diff options
| author | realtradam <[email protected]> | 2021-05-27 05:29:50 -0400 |
|---|---|---|
| committer | realtradam <[email protected]> | 2021-05-27 05:29:50 -0400 |
| commit | ecbf3f77aefb9045197e6aec89369494f878dffb (patch) | |
| tree | 2ab1ce542a572a71980078adbb374866cb6bd819 /entity_manager.rb | |
| parent | 58470d70add715bd4ea4fd75c14eb56b9e649c41 (diff) | |
| download | FelECS-ecbf3f77aefb9045197e6aec89369494f878dffb.tar.gz FelECS-ecbf3f77aefb9045197e6aec89369494f878dffb.zip | |
set up to write unit tests
Diffstat (limited to 'entity_manager.rb')
| -rw-r--r-- | entity_manager.rb | 98 |
1 files changed, 50 insertions, 48 deletions
diff --git a/entity_manager.rb b/entity_manager.rb index 7d0d1ff..177ce1a 100644 --- a/entity_manager.rb +++ b/entity_manager.rb @@ -1,62 +1,64 @@ -class Entity - attr_accessor :id +class FelFlame + class Entities + attr_accessor :id - def initialize(*signature) - final_signature = 0 - signature.each do |sig| - final_signature += sig + def initialize(*signature) + final_signature = 0 + signature.each do |sig| + final_signature += sig + end + @id = Entities.generate_new_id + self.class.all.push self + self.class.signatures.push final_signature + Components.entity_created(@id) end - @id = Entity.generate_new_id - self.class.all.push self - self.class.signatures.push final_signature - Components.entity_created(@id) - end - class <<self - # All entities that exist - def all - @all ||= [] - end + class <<self + # All entities that exist + def all + @all ||= [] + end - def id_queue - @id_queue ||= [] - end + def id_queue + @id_queue ||= [] + end - def generate_new_id - if id_queue.empty? - all.size - else - id_queue.shift + def generate_new_id + if id_queue.empty? + all.size + else + id_queue.shift + end end - end - # What components a given entity uses - def signatures - @signatures ||= [] - end + # What components a given entity uses + def signatures + @signatures ||= [] + end - def destroy_entity(entity_id) - if all[entity_id].nil? - puts 'Entity can not be destroyed, id out of bounds' - elsif entity_id < all.size - 1 - Components.constants.each do |constant| - unless (signatures[entity_id] & Components::const_get(constant).id).zero? - Components::const_get(constant).delete(entity_id) + def destroy_entity(entity_id) + if all[entity_id].nil? + puts 'Entity can not be destroyed, id out of bounds' + elsif entity_id < all.size - 1 + Components.constants.each do |constant| + unless (signatures[entity_id] & Components::const_get(constant).id).zero? + Components::const_get(constant).delete(entity_id) + end end - end - all[entity_id] = nil - signatures[entity_id] = nil - id_queue.push entity_id - elsif entity_id == all.size - 1 - Components.constants.each do |constant| - unless (signatures[entity_id] & Components::const_get(constant).id).zero? - Components::const_get(constant).delete(entity_id) + all[entity_id] = nil + signatures[entity_id] = nil + id_queue.push entity_id + elsif entity_id == all.size - 1 + Components.constants.each do |constant| + unless (signatures[entity_id] & Components::const_get(constant).id).zero? + Components::const_get(constant).delete(entity_id) + end end + all.pop + signatures.pop + else + puts 'Unknown error with destroy_entity, entity not destroyed' end - all.pop - signatures.pop - else - puts 'Unknown error with destroy_entity, entity not destroyed' end end end |
