Class: BeltsEngine::Ecs::Collection
- Inherits:
-
Hash
- Object
- Hash
- BeltsEngine::Ecs::Collection
- Defined in:
- lib/belts_engine/ecs/collection.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #add_entity(entity) ⇒ Object
- #each_with_components ⇒ Object
-
#initialize(with: [], without: []) ⇒ Collection
constructor
A new instance of Collection.
- #remove_entity(entity_id) ⇒ Object
Constructor Details
#initialize(with: [], without: []) ⇒ Collection
Returns a new instance of Collection.
5 6 7 8 9 |
# File 'lib/belts_engine/ecs/collection.rb', line 5 def initialize(with: [], without: []) @with = with.sort @without = without.sort @key = {with: with, without: without} end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
3 4 5 |
# File 'lib/belts_engine/ecs/collection.rb', line 3 def key @key end |
Instance Method Details
#add_entity(entity) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/belts_engine/ecs/collection.rb', line 11 def add_entity(entity) return if (@with - entity.keys).any? return if (@without & entity.keys).any? self[entity[:id]] = entity.slice(:id, *@with) end |
#each_with_components ⇒ Object
22 23 24 25 26 |
# File 'lib/belts_engine/ecs/collection.rb', line 22 def each_with_components each do |k, v| yield **v end end |
#remove_entity(entity_id) ⇒ Object
18 19 20 |
# File 'lib/belts_engine/ecs/collection.rb', line 18 def remove_entity(entity_id) self.delete(entity_id) end |