diff options
| author | _Tradam <[email protected]> | 2021-05-26 02:12:54 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-05-26 02:12:54 -0400 |
| commit | 41f574c04c70e6327cb1861fac01664bd3f3f7ba (patch) | |
| tree | 34a184ff4fd182a8823f416fd87b4d546e1e250f /app/lib/entity_manager.rb | |
| parent | f97a9ca95e464e728bba9337b579bc380c33bc7d (diff) | |
| parent | a5bbcbf5d78005746fb64c51a779f830d7667a57 (diff) | |
| download | typemon-code-master.tar.gz typemon-code-master.zip | |
split off FelFlame
Diffstat (limited to 'app/lib/entity_manager.rb')
| -rw-r--r-- | app/lib/entity_manager.rb | 63 |
1 files changed, 0 insertions, 63 deletions
diff --git a/app/lib/entity_manager.rb b/app/lib/entity_manager.rb deleted file mode 100644 index 7d0d1ff..0000000 --- a/app/lib/entity_manager.rb +++ /dev/null @@ -1,63 +0,0 @@ -class Entity - attr_accessor :id - - def initialize(*signature) - final_signature = 0 - signature.each do |sig| - final_signature += sig - 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 - - def id_queue - @id_queue ||= [] - end - - def generate_new_id - if id_queue.empty? - all.size - else - id_queue.shift - end - 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) - 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) - end - end - all.pop - signatures.pop - else - puts 'Unknown error with destroy_entity, entity not destroyed' - end - end - end -end |
