draco 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +28 -0
- data/lib/draco.rb +16 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1057daf5d6bb88b4877d001fe21d123557cb720df446d9ff2c0111a58baceb0f
|
4
|
+
data.tar.gz: a96296838c903442df84482a8eb57346fc8225a34a6842f352d8d3ec1cc955cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/draco.rb
CHANGED
@@ -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.
|
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
|
-
#
|
515
|
+
# components_or_ids - The Component Classes to filter by
|
515
516
|
#
|
516
517
|
# Returns a Set list of Entities
|
517
|
-
def [](*
|
518
|
-
|
518
|
+
def [](*components_or_ids)
|
519
|
+
components_or_ids
|
519
520
|
.flatten
|
520
|
-
.map
|
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|
|