draco 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +28 -0
  3. data/lib/draco.rb +16 -6
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c3c9cbbaf38c7b5b07e5bc31dc43cd3f046f37290b165e3133c4617e10cdb54
4
- data.tar.gz: f7ec6ce41ca9d9a9d7c6de52cb3c89f4d1b1a4998d7ebb8467c6bf511d41e78d
3
+ metadata.gz: 1057daf5d6bb88b4877d001fe21d123557cb720df446d9ff2c0111a58baceb0f
4
+ data.tar.gz: a96296838c903442df84482a8eb57346fc8225a34a6842f352d8d3ec1cc955cb
5
5
  SHA512:
6
- metadata.gz: 595424485c3bde045b8679fe8efc00a3c77109f381902f71b47abcec17a6c729529f902e0c32d194308088d9e9ce1ac80e4343a19d01a6aa6f25ce8c3437ca78
7
- data.tar.gz: c4e6ad8b15416fc9646b1c1540c34bc8752d55fe01662c7c49f84f7496794b7d1a7993abc959b97e65dd03d44fb9a6521461a30eebc2d54db97fb79b07236b53
6
+ metadata.gz: 502d00bc7c2d3e099548c8c2211182ae95bbb0d35de8dba9e20f232046803740bfa3331a8bf94a414b4c5ecaad7c86a570fdcb53fec8325e07191eec4342a3ec
7
+ data.tar.gz: f19a25eca8d942dea85a8835f8e239d3a81613a9667c788dba4eadb021876b90938e533bb049bf50155f316a16fe43065dd730b9578a927ea3691a2775b8538f
data/README.md CHANGED
@@ -23,6 +23,19 @@ This repository includes a sample application in `samples/teeny-tiny`.
23
23
  2. Copy `lib/draco.rb` into your new `lib` directory.
24
24
  3. In your `main.rb` file, require `app/lib/draco.rb`.
25
25
 
26
+ ## Support
27
+
28
+ - Find a bug? [Open an issue](https://github.com/guitsaru/draco/issues).
29
+ - Need help? [Start a Discussion](https://github.com/guitsaru/draco/discussions) or [Join us in Discord: Channel #oss-draco](https://discord.gg/vPUNtwfm).
30
+
31
+ ## Versioning
32
+
33
+ Draco uses [https://semver.org/].
34
+
35
+ * Major (X.y.z) - Incremented for any backwards incompatible public API changes.
36
+ * Minor (x.Y.z) - Incremented for new, backwards compatible, public API enhancements/fixes.
37
+ * Patch (x.y.Z) - Incremented for small, backwards compatible, bug fixes.
38
+
26
39
  ## Usage
27
40
 
28
41
  ### Components
@@ -161,6 +174,19 @@ player entity has been given the name `player`. We can now access this directly
161
174
  world.player
162
175
  ```
163
176
 
177
+ ### Fetching entities by id
178
+
179
+ In some cases you'll want to keep track of entities by their id, such as when you want to keep track of another entity in a component.
180
+
181
+ ```ruby
182
+ entity = Player.new
183
+ entity.id
184
+ # => 12
185
+
186
+ world.entities[12] == entity
187
+ # => true
188
+ ```
189
+
164
190
  ## Learn More
165
191
 
166
192
  Here are some good resources to learn about Entity Component Systems
@@ -172,6 +198,8 @@ Here are some good resources to learn about Entity Component Systems
172
198
 
173
199
  Draco is licensed under AGPL. You can purchase the right to use Draco under the [commercial license](https://github.com/guitsaru/draco/blob/master/COMM-LICENSE).
174
200
 
201
+ Each purchase comes with free upgrades for the current major version of Draco.
202
+
175
203
  <a class="gumroad-button" href="https://guitsaru.itch.io/draco" target="_blank">Purchase Commercial License</a>
176
204
 
177
205
  ## Development
@@ -5,7 +5,7 @@
5
5
  # An Entity Component System is an architectural pattern used in game development to decouple behavior from objects.
6
6
  module Draco
7
7
  # Public: The version of the library. Draco uses semver to version releases.
8
- VERSION = "0.3.3"
8
+ VERSION = "0.4.0"
9
9
 
10
10
  # Public: A general purpose game object that consists of a unique id and a collection of Components.
11
11
  class Entity
@@ -505,19 +505,26 @@ module Draco
505
505
  def initialize(*entities)
506
506
  @entity_to_components = Hash.new { |hash, key| hash[key] = Set.new }
507
507
  @component_to_entities = Hash.new { |hash, key| hash[key] = Set.new }
508
+ @entity_ids = {}
508
509
 
509
510
  self << entities
510
511
  end
511
512
 
512
- # Internal: Gets all Entities that implement all of the given Components
513
+ # Internal: Gets all Entities that implement all of the given Components or that match the given entity ids.
513
514
  #
514
- # components - The Component Classes to filter by
515
+ # components_or_ids - The Component Classes to filter by
515
516
  #
516
517
  # Returns a Set list of Entities
517
- def [](*components)
518
- components
518
+ def [](*components_or_ids)
519
+ components_or_ids
519
520
  .flatten
520
- .map { |component| @component_to_entities[component] }
521
+ .map do |component_or_id|
522
+ if component_or_id.is_a?(Numeric)
523
+ Array(@entity_ids[component_or_id])
524
+ else
525
+ @component_to_entities[component_or_id]
526
+ end
527
+ end
521
528
  .reduce { |acc, i| i & acc }
522
529
  end
523
530
 
@@ -539,6 +546,8 @@ module Draco
539
546
  def add(entity)
540
547
  entity.subscribe(self)
541
548
 
549
+ @entity_ids[entity.id] = entity
550
+
542
551
  components = entity.components.map(&:class)
543
552
  @entity_to_components[entity].merge(components)
544
553
 
@@ -555,6 +564,7 @@ module Draco
555
564
  #
556
565
  # Returns the EntityStore
557
566
  def delete(entity)
567
+ @entity_ids.delete(entity.id)
558
568
  components = Array(@entity_to_components.delete(entity))
559
569
 
560
570
  components.each do |component|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: draco
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Pruitt