diff options
| author | realtradam <[email protected]> | 2021-06-16 07:09:43 -0400 |
|---|---|---|
| committer | realtradam <[email protected]> | 2021-06-16 07:09:43 -0400 |
| commit | ba707eebb995eb46141d3c5e1701cd7252ba81c8 (patch) | |
| tree | dfddbfd069825f55ace5ab25a4a3c09540744476 /component_manager.rb | |
| parent | f88af5840b9d6af0f78090c894818c5ee138979c (diff) | |
| download | FelECS-ba707eebb995eb46141d3c5e1701cd7252ba81c8.tar.gz FelECS-ba707eebb995eb46141d3c5e1701cd7252ba81c8.zip | |
entities, components, and systems improved
Diffstat (limited to 'component_manager.rb')
| -rw-r--r-- | component_manager.rb | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/component_manager.rb b/component_manager.rb index f4402b3..a29aac8 100644 --- a/component_manager.rb +++ b/component_manager.rb @@ -56,6 +56,18 @@ class FelFlame # @return [Integer] attr_accessor :id + attr_writer :addition_triggers + + def addition_triggers + @addition_triggers ||= [] + end + + attr_writer :removal_triggers + + def removal_triggers + @removal_triggers ||= [] + end + # Creates a new component and sets the values of the attributes given to it. If an attritbute is not passed then it will remain as the default. # @param attrs [Keyword: Value] You can pass any number of Keyword-Value pairs # @return [Component] @@ -80,6 +92,18 @@ class FelFlame end class <<self + attr_writer :addition_triggers + + def addition_triggers + @addition_triggers ||= [] + end + + attr_writer :removal_triggers + + def removal_triggers + @removal_triggers ||= [] + end + # @return [Array<Component>] Array of all Components that belong to a given component manager # @!visibility private def data @@ -128,11 +152,17 @@ class FelFlame # Removes this component from the list and purges all references to this Component from other Entities, as well as its {id ID} and data. # @return [Boolean] true. def delete - entities.each do |entity_id| - FelFlame::Entities[entity_id].remove self + addition_triggers.each do |system| + system.clear_triggers component_or_manager: self + end + # This needs to be cloned because indices get deleted as + # the remove command is called, breaking the loop if it + # wasn't referencing a clone(will get Nil errors) + iter = entities.map(&:clone) + iter.each do |entity_id| + FelFlame::Entities[entity_id].remove self #unless FelFlame::Entities[entity_id].nil? end self.class.data[id] = nil - @entities = nil instance_variables.each do |var| instance_variable_set(var, nil) end |
