From a96733c75ce7caff16a1d79a9caa1894ed95d2ca Mon Sep 17 00:00:00 2001 From: realtradam Date: Sat, 3 Jul 2021 00:36:00 -0400 Subject: completed systems functionality --- component_manager.rb | 40 +- docs/FelFlame.html | 2 +- docs/FelFlame/Components.html | 24 +- docs/FelFlame/Entities.html | 2 +- docs/FelFlame/Helper.html | 2 +- docs/FelFlame/Helper/ComponentManager.html | 363 +++++-- docs/FelFlame/Helper/ComponentManagerTemplate.html | 1042 -------------------- docs/FelFlame/Systems.html | 403 ++++++-- docs/_index.html | 2 +- docs/file.README.html | 2 +- docs/index.html | 2 +- docs/method_list.html | 42 +- docs/top-level-namespace.html | 2 +- spec/system_manager_spec.rb | 317 +++++- system_manager.rb | 110 ++- 15 files changed, 1090 insertions(+), 1265 deletions(-) delete mode 100644 docs/FelFlame/Helper/ComponentManagerTemplate.html diff --git a/component_manager.rb b/component_manager.rb index a29aac8..14975e9 100644 --- a/component_manager.rb +++ b/component_manager.rb @@ -30,7 +30,12 @@ class FelFlame FelFlame::Components.const_get(component_name).attr_accessor attr end attrs_with_defaults.each do |attr, _default| - FelFlame::Components.const_get(component_name).attr_accessor attr + #FelFlame::Components.const_get(component_name).attr_accessor attr + FelFlame::Components.const_get(component_name).attr_reader attr + FelFlame::Components.const_get(component_name).define_method("#{attr}=") do |value| + attr_changed_trigger_systems(attr) unless value.equal? send(attr) + instance_variable_set("@#{attr}", value) + end end FelFlame::Components.const_get(component_name).define_method(:set_defaults) do attrs_with_defaults.each do |attr, default| @@ -56,18 +61,20 @@ class FelFlame # @return [Integer] attr_accessor :id - attr_writer :addition_triggers + attr_writer :addition_triggers, :removal_triggers, :attr_triggers def addition_triggers @addition_triggers ||= [] end - attr_writer :removal_triggers - def removal_triggers @removal_triggers ||= [] end + def attr_triggers + @attr_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] @@ -92,18 +99,20 @@ class FelFlame end class <] Array of all Components that belong to a given component manager # @!visibility private def data @@ -149,6 +158,19 @@ class FelFlame end end + # Execute systems that have been added to execute on variable change + def attr_changed_trigger_systems(attr) + systems_to_execute = self.class.attr_triggers[attr] + systems_to_execute = [] if systems_to_execute.nil? + + systems_to_execute |= attr_triggers[attr] unless attr_triggers[attr].nil? + + systems_to_execute.sort_by(&:priority).reverse.each(&:call) + #self.attr_triggers.each do |system| + # systems_to_execute |= [system] + #end + end + # 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 @@ -171,9 +193,11 @@ class FelFlame # @return [Hash] A hash, where all the keys are attributes linked to their respective values. def attrs - instance_variables.each_with_object({}) do |key, final| + return_hash = instance_variables.each_with_object({}) do |key, final| final[key.to_s.delete_prefix('@').to_sym] = instance_variable_get(key) end + return_hash.delete(:attr_triggers) + return_hash end # Export all data into a JSON String, which could then later be loaded or saved to a file diff --git a/docs/FelFlame.html b/docs/FelFlame.html index 13eb3f1..27527e4 100644 --- a/docs/FelFlame.html +++ b/docs/FelFlame.html @@ -193,7 +193,7 @@ diff --git a/docs/FelFlame/Components.html b/docs/FelFlame/Components.html index 3472ea0..5dbc160 100644 --- a/docs/FelFlame/Components.html +++ b/docs/FelFlame/Components.html @@ -233,12 +233,12 @@
 
 
-45
-46
-47
+50 +51 +52 -
# File 'component_manager.rb', line 45
+      
# File 'component_manager.rb', line 50
 
 def each(&block)
   constants.each(&block)
@@ -369,7 +369,12 @@
 38
 39
 40
-41
+41 +42 +43 +44 +45 +46
# File 'component_manager.rb', line 23
@@ -384,7 +389,12 @@
     FelFlame::Components.const_get(component_name).attr_accessor attr
   end
   attrs_with_defaults.each do |attr, _default|
-    FelFlame::Components.const_get(component_name).attr_accessor attr
+    #FelFlame::Components.const_get(component_name).attr_accessor attr
+    FelFlame::Components.const_get(component_name).attr_reader attr
+    FelFlame::Components.const_get(component_name).define_method("#{attr}=") do |value|
+      attr_changed_trigger_systems(attr) unless value.equal? send(attr)
+      instance_variable_set("@#{attr}", value)
+    end
   end
   FelFlame::Components.const_get(component_name).define_method(:set_defaults) do
     attrs_with_defaults.each do |attr, default|
@@ -403,7 +413,7 @@
 
 
       
diff --git a/docs/FelFlame/Entities.html b/docs/FelFlame/Entities.html
index e91c2c0..bf716c0 100644
--- a/docs/FelFlame/Entities.html
+++ b/docs/FelFlame/Entities.html
@@ -1224,7 +1224,7 @@
 
 
       
diff --git a/docs/FelFlame/Helper.html b/docs/FelFlame/Helper.html
index 19f40b6..e924d44 100644
--- a/docs/FelFlame/Helper.html
+++ b/docs/FelFlame/Helper.html
@@ -132,7 +132,7 @@
 
 
       
diff --git a/docs/FelFlame/Helper/ComponentManager.html b/docs/FelFlame/Helper/ComponentManager.html
index 425d91b..cce8c36 100644
--- a/docs/FelFlame/Helper/ComponentManager.html
+++ b/docs/FelFlame/Helper/ComponentManager.html
@@ -137,6 +137,31 @@
   
 
   
+    
+ + + + +
  • + + + .attr_triggers ⇒ Object + + + + + + + + + + + + + + + +
  • @@ -192,6 +217,31 @@ +
    + + + + +
  • + + + #attr_triggers ⇒ Object + + + + + + + + + + + + + + + +
  • @@ -322,6 +372,30 @@
  • + #attr_changed_trigger_systems(attr) ⇒ Object + + + + + + + + + + + + + +
    +

    Execute systems that have been added to execute on variable change.

    +
    + +
  • + + +
  • + + #attrs ⇒ Hash @@ -541,13 +615,6 @@
     
     
    -74
    -75
    -76
    -77
    -78
    -79
    -80
     81
     82
     83
    @@ -559,10 +626,17 @@
     89
     90
     91
    -92
    +92 +93 +94 +95 +96 +97 +98 +99
  • -
    # File 'component_manager.rb', line 74
    +      
    # File 'component_manager.rb', line 81
     
     def initialize(**attrs)
       # Prepare the object
    @@ -610,12 +684,12 @@
           
     
     
    -97
    -98
    -99
    +104 +105 +106
    -
    # File 'component_manager.rb', line 97
    +      
    # File 'component_manager.rb', line 104
     
     def addition_triggers
       @addition_triggers ||= []
    @@ -626,6 +700,38 @@
     
         
           
    +      
    +      
    +

    + + .attr_triggersObject + + + + + +

    + + + + +
    +
    +
    +
    +112
    +113
    +114
    +
    +
    # File 'component_manager.rb', line 112
    +
    +def attr_triggers
    +  @attr_triggers ||= {}
    +end
    +
    +
    + +

    @@ -642,12 +748,12 @@
     
     
    -103
    -104
    -105
    +108 +109 +110

    -
    # File 'component_manager.rb', line 103
    +      
    # File 'component_manager.rb', line 108
     
     def removal_triggers
       @removal_triggers ||= []
    @@ -679,12 +785,12 @@
           
     
     
    -61
    -62
    -63
    +66 +67 +68
    -
    # File 'component_manager.rb', line 61
    +      
    # File 'component_manager.rb', line 66
     
     def addition_triggers
       @addition_triggers ||= []
    @@ -695,6 +801,38 @@
     
         
           
    +      
    +      
    +

    + + #attr_triggersObject + + + + + +

    + + + + +
    +
    +
    +
    +74
    +75
    +76
    +
    +
    # File 'component_manager.rb', line 74
    +
    +def attr_triggers
    +  @attr_triggers ||= {}
    +end
    +
    +
    + +

    @@ -735,12 +873,12 @@
     
     
    -57
    -58
    -59
    +62 +63 +64

    -
    # File 'component_manager.rb', line 57
    +      
    # File 'component_manager.rb', line 62
     
     def id
       @id
    @@ -767,12 +905,12 @@
           
     
     
    -67
    -68
    -69
    +70 +71 +72
    -
    # File 'component_manager.rb', line 67
    +      
    # File 'component_manager.rb', line 70
     
     def removal_triggers
       @removal_triggers ||= []
    @@ -857,12 +995,12 @@
           
     
     
    -120
    -121
    -122
    +129 +130 +131
    -
    # File 'component_manager.rb', line 120
    +      
    # File 'component_manager.rb', line 129
     
     def [](component_id)
       data[component_id]
    @@ -911,12 +1049,12 @@
           
     
     
    -127
    -128
    -129
    +136 +137 +138
    -
    # File 'component_manager.rb', line 127
    +      
    # File 'component_manager.rb', line 136
     
     def each(&block)
       data.compact.each(&block)
    @@ -933,7 +1071,64 @@
     
         
           
    -

    +

    + + #attr_changed_trigger_systems(attr) ⇒ Object + + + + + +

    +
    + +

    Execute systems that have been added to execute on variable change

    + + +
    +
    +
    + + +
    + + + + +
    +
    +
    +
    +162
    +163
    +164
    +165
    +166
    +167
    +168
    +169
    +170
    +171
    +172
    +
    +
    # File 'component_manager.rb', line 162
    +
    +def attr_changed_trigger_systems(attr)
    +  systems_to_execute = self.class.attr_triggers[attr]
    +  systems_to_execute = [] if systems_to_execute.nil?
    +
    +  systems_to_execute |= attr_triggers[attr] unless attr_triggers[attr].nil?
    +
    +  systems_to_execute.sort_by(&:priority).reverse.each(&:call)
    +  #self.attr_triggers.each do |system|
    +  #  systems_to_execute |= [system]
    +  #end
    +end
    +
    +
    + +
    +

    #attrsHash @@ -976,19 +1171,23 @@
     
     
    -173
    -174
    -175
    -176
    -177
    +195 +196 +197 +198 +199 +200 +201

    -
    # File 'component_manager.rb', line 173
    +      
    # File 'component_manager.rb', line 195
     
     def attrs
    -  instance_variables.each_with_object({}) do |key, final|
    +  return_hash = instance_variables.each_with_object({}) do |key, final|
         final[key.to_s.delete_prefix('@').to_sym] = instance_variable_get(key)
       end
    +  return_hash.delete(:attr_triggers)
    +  return_hash
     end
    @@ -1039,26 +1238,26 @@
     
     
    -154
    -155
    -156
    -157
    -158
    -159
    -160
    -161
    -162
    -163
    -164
    -165
    -166
    -167
    -168
    -169
    -170
    +176 +177 +178 +179 +180 +181 +182 +183 +184 +185 +186 +187 +188 +189 +190 +191 +192
    -
    # File 'component_manager.rb', line 154
    +      
    # File 'component_manager.rb', line 176
     
     def delete
       addition_triggers.each do |system|
    @@ -1121,12 +1320,12 @@
           
     
     
    -140
    -141
    -142
    +149 +150 +151
    -
    # File 'component_manager.rb', line 140
    +      
    # File 'component_manager.rb', line 149
     
     def entities
       @entities ||= []
    @@ -1175,12 +1374,12 @@
           
     
     
    -134
    -135
    -136
    +143 +144 +145
    -
    # File 'component_manager.rb', line 134
    +      
    # File 'component_manager.rb', line 143
     
     def to_i
       id
    @@ -1234,12 +1433,12 @@
           
     
     
    -182
    -183
    -184
    +206 +207 +208
    -
    # File 'component_manager.rb', line 182
    +      
    # File 'component_manager.rb', line 206
     
     def to_json
       # should return a json or hash of all data in this component
    @@ -1293,14 +1492,14 @@
           
     
     
    -146
    -147
    -148
    -149
    -150
    +155 +156 +157 +158 +159
    -
    # File 'component_manager.rb', line 146
    +      
    # File 'component_manager.rb', line 155
     
     def update_attrs(**opts)
       opts.each do |key, value|
    @@ -1317,7 +1516,7 @@
     
     
           
    diff --git a/docs/FelFlame/Helper/ComponentManagerTemplate.html b/docs/FelFlame/Helper/ComponentManagerTemplate.html
    deleted file mode 100644
    index b97dff0..0000000
    --- a/docs/FelFlame/Helper/ComponentManagerTemplate.html
    +++ /dev/null
    @@ -1,1042 +0,0 @@
    -
    -
    -  
    -    
    -
    -
    -  Class: FelFlame::Helper::ComponentManagerTemplate
    -  
    -    — Documentation by YARD 0.9.26
    -  
    -
    -
    -  
    -
    -  
    -
    -
    -
    -
    -  
    -
    -  
    -
    -
    -  
    -  
    -    
    -
    -    
    - - -

    Class: FelFlame::Helper::ComponentManagerTemplate - - - -

    -
    - -
    -
    Inherits:
    -
    - Object - -
      -
    • Object
    • - - - -
    - show all - -
    -
    - - - - - - - - - - - -
    -
    Defined in:
    -
    component_manager.rb
    -
    - -
    - -

    Overview

    -
    - -

    Component Managers are what is used to create individual components which can be attached to entities. When a Component is created from a Component Manager that has accessors given to it, you can set or get the values of those accessors using standard ruby message sending (e.g `@component.var = 5`), or by using the #attrs and #update_attrs methods instead.

    - - -
    -
    -
    - - -
    - - - -

    Instance Attribute Summary collapse

    - - - - - - -

    - Class Method Summary - collapse -

    - - - -

    - Instance Method Summary - collapse -

    - -
      - -
    • - - - #attrs ⇒ Hash - - - - - - - - - - - - - -
      -

      Returns a hash, where all the keys are attributes linked to their respective values.

      -
      - -
    • - - -
    • - - - #delete ⇒ Boolean - - - - - - - - - - - - - -
      -

      Removes this component from the list and purges all references to this Component from other Entities, as well as its ID and data.

      -
      - -
    • - - -
    • - - - #linked_entities ⇒ Array - - - - - - - - - - - - - -
      -

      A list of components that are linked to the component.

      -
      - -
    • - - -
    • - - - #to_i ⇒ Integer - - - - - - - - - - - - - -
      -

      An alias for the ID reader.

      -
      - -
    • - - -
    • - - - #to_json ⇒ String - - - - - - - - - - - - - -
      -

      Export all data into a JSON String, which could then later be loaded or saved to a file TODO: This function is not yet complete.

      -
      - -
    • - - -
    • - - - #update_attrs(**opts) ⇒ Object - - - - - - - - - - - - - -
      -

      Update attribute values using a hash or keywords.

      -
      - -
    • - - -
    - - - -
    -

    Instance Attribute Details

    - - - -
    -

    - - #idObject - - - - - -

    -
    - -

    Holds the unique ID of a component. The ID is only unique within the scope of the component manager it was created from.

    - - -
    -
    -
    - - -
    - - - - -
    -
    -
    -
    -43
    -44
    -45
    -
    -
    # File 'component_manager.rb', line 43
    -
    -def id
    -  @id
    -end
    -
    -
    - -
    - - -
    -

    Class Method Details

    - - -
    -

    - - .[](component_id) ⇒ Component - - - - - -

    -
    - -

    Gets a Component from the given unique ID. Usage is simular to how an Array lookup works.

    - - -
    -
    -
    -

    Parameters:

    -
      - -
    • - - component_id - - - (Integer) - - - -
    • - -
    - -

    Returns:

    -
      - -
    • - - - (Component) - - - - — -
      -

      Returns the Component that uses the given unique ID, nil if there is no Component associated with the given ID

      -
      - -
    • - -
    - -
    - - - - -
    -
    -
    -
    -55
    -56
    -57
    -
    -
    # File 'component_manager.rb', line 55
    -
    -def [](component_id)
    -  data[component_id]
    -end
    -
    -
    - -
    -

    - - .eachEnumerator - - - - - -

    -
    - -

    Iterates over all components within the component manager

    - - -
    -
    -
    - -

    Returns:

    -
      - -
    • - - - (Enumerator) - - - -
    • - -
    - -
    - - - - -
    -
    -
    -
    -80
    -81
    -82
    -83
    -84
    -
    -
    # File 'component_manager.rb', line 80
    -
    -def each
    -  data.each do |component|
    -    yield component
    -  end
    -end
    -
    -
    - -
    -

    - - .new(**attrs) ⇒ Object - - - - - -

    -
    - -

    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.

    - - -
    -
    -
    -

    Parameters:

    -
      - -
    • - - attrs - - - (Keywords) - - - -
    • - -
    - - -
    - - - - -
    -
    -
    -
    -61
    -62
    -63
    -64
    -65
    -66
    -67
    -68
    -69
    -70
    -71
    -72
    -73
    -74
    -75
    -76
    -
    -
    # File 'component_manager.rb', line 61
    -
    -def new(**attrs)
    -  new_component = super
    -
    -  # Generate ID
    -  new_id = self.data.find_index { |i| i.nil? }
    -  new_id = self.data.size if new_id.nil?
    -  new_component.id = new_id
    -
    -  # Fill params
    -  attrs.each do |key, value|
    -    new_component.send "#{key}=", value
    -  end
    -
    -  # Save Component
    -  data[new_id] = new_component
    -end
    -
    -
    - -
    - -
    -

    Instance Method Details

    - - -
    -

    - - #attrsHash - - - - - -

    -
    - -

    Returns a hash, where all the keys are attributes linked to their respective values.

    - - -
    -
    -
    - -

    Returns:

    -
      - -
    • - - - (Hash) - - - - — -
      -

      Returns a hash, where all the keys are attributes linked to their respective values.

      -
      - -
    • - -
    - -
    - - - - -
    -
    -
    -
    -122
    -123
    -124
    -125
    -126
    -
    -
    # File 'component_manager.rb', line 122
    -
    -def attrs
    -  instance_variables.each_with_object({}) do |key, final|
    -    final[key.to_s.delete_prefix('@').to_sym] = instance_variable_get(key)
    -  end
    -end
    -
    -
    - -
    -

    - - #deleteBoolean - - - - - -

    -
    - -

    Removes this component from the list and purges all references to this Component from other Entities, as well as its ID and data.

    - - -
    -
    -
    - -

    Returns:

    -
      - -
    • - - - (Boolean) - - - - — -
      -

      true.

      -
      - -
    • - -
    - -
    - - - - -
    -
    -
    -
    -109
    -110
    -111
    -112
    -113
    -114
    -115
    -116
    -117
    -118
    -119
    -
    -
    # File 'component_manager.rb', line 109
    -
    -def delete
    -  linked_entities.each do |entity_id|
    -    FelFlame::Entities[entity_id].remove self
    -  end
    -  self.class.data[id] = nil
    -  @linked_entities = nil
    -  instance_variables.each do |var|
    -    instance_variable_set(var, nil)
    -  end
    -  true
    -end
    -
    -
    - -
    -

    - - #linked_entitiesArray - - - - - -

    -
    - -

    A list of components that are linked to the component

    - - -
    -
    -
    - -

    Returns:

    -
      - -
    • - - - (Array) - - - -
    • - -
    - -
    - - - - -
    -
    -
    -
    -95
    -96
    -97
    -
    -
    # File 'component_manager.rb', line 95
    -
    -def linked_entities
    -  @linked_entities ||= []
    -end
    -
    -
    - -
    -

    - - #to_iInteger - - - - - -

    -
    - -

    An alias for the ID reader

    - - -
    -
    -
    - -

    Returns:

    -
      - -
    • - - - (Integer) - - - -
    • - -
    - -
    - - - - -
    -
    -
    -
    -89
    -90
    -91
    -
    -
    # File 'component_manager.rb', line 89
    -
    -def to_i
    -  id
    -end
    -
    -
    - -
    -

    - - #to_jsonString - - - - - -

    -
    - -

    Export all data into a JSON String, which could then later be loaded or saved to a file TODO: This function is not yet complete

    - - -
    -
    -
    - -

    Returns:

    -
      - -
    • - - - (String) - - - - — -
      -

      a JSON formatted String

      -
      - -
    • - -
    - -
    - - - - -
    -
    -
    -
    -131
    -132
    -133
    -
    -
    # File 'component_manager.rb', line 131
    -
    -def to_json
    -  # should return a json or hash of all data in this component
    -end
    -
    -
    - -
    -

    - - #update_attrs(**opts) ⇒ Object - - - - - -

    -
    - -

    Update attribute values using a hash or keywords.

    - - -
    -
    -
    - -

    Returns:

    -
      - -
    • - - - - - - - -
      -

      Hash of updated attributes

      -
      - -
    • - -
    - -
    - - - - -
    -
    -
    -
    -101
    -102
    -103
    -104
    -105
    -
    -
    # File 'component_manager.rb', line 101
    -
    -def update_attrs(**opts)
    -  opts.each do |key, value|
    -    send "#{key}=", value
    -  end
    -end
    -
    -
    - -
    - -
    - - - -
    - - \ No newline at end of file diff --git a/docs/FelFlame/Systems.html b/docs/FelFlame/Systems.html index 65d463b..8961bf1 100644 --- a/docs/FelFlame/Systems.html +++ b/docs/FelFlame/Systems.html @@ -146,6 +146,31 @@ +
    + + + + +
  • + + + #attr_triggers ⇒ Object + + + + + + + + + + + + + + + +
  • @@ -446,6 +471,30 @@

    Add a component or component manager so that it triggers this system when the component or a component from the component manager is added to an entity.

    + + + +
  • + + + #trigger_when_is_changed(component_or_manager, attr) ⇒ Object + + + + + + + + + + + + + +
    +

    Add a component or component manager so that it triggers this system when a component's attribute is changed.

    +
    +
  • @@ -503,7 +552,7 @@

    Examples:

    -
    FelFlame::Systems.new('PassiveHeal', priority: -2, frame: 2) do
    +      
    FelFlame::Systems.new('PassiveHeal', priority: -2) do
       FelFlame::Components::Health.each do |component|
         component.hp += 5
       end
    @@ -575,15 +624,15 @@
           
     
     
    -50
    -51
    -52
    -53
    -54
    -55
    +56 +57 +58 +59 +60 +61
    -
    # File 'system_manager.rb', line 50
    +      
    # File 'system_manager.rb', line 56
     
     def initialize(name, priority: 0, &block)
       FelFlame::Systems.const_set(name, self)
    @@ -634,6 +683,38 @@
     
         
           
    +      
    +      
    +

    + + #attr_triggersObject + + + + + +

    + + + + +
    +
    +
    +
    +26
    +27
    +28
    +
    +
    # File 'system_manager.rb', line 26
    +
    +def attr_triggers
    +  @attr_triggers ||= {}
    +end
    +
    +
    + +

    @@ -840,12 +921,12 @@
     
     
    -29
    -30
    -31
    +35 +36 +37

    -
    # File 'system_manager.rb', line 29
    +      
    # File 'system_manager.rb', line 35
     
     def each(&block)
       constants.map { |sym| const_get(sym) }.sort_by(&:priority).reverse.each(&block)
    @@ -887,12 +968,12 @@
           
     
     
    -58
    -59
    -60
    +64 +65 +66
    -
    # File 'system_manager.rb', line 58
    +      
    # File 'system_manager.rb', line 64
     
     def call
       @block.call
    @@ -914,15 +995,52 @@
     
    -

    Removes triggers from this system

    +

    Removes triggers from this system. This function is fairly flexible so it can accept a few different inputs For addition and removal triggers, you can optionally pass in a component, or a manager to clear specifically the relevant triggers for that one component or manager. If you do not pass a component or manager then it will clear triggers for all components and managers. For attr_triggers

    -

    Parameters:

    + +
    +

    Examples:

    + + +
    # To clear all triggers that execute this system when a component is added:
    +FelFlame::Systems::ExampleSystem.clear_triggers :addition_triggers
    +# Same as above but for when a component is removed instead
    +FelFlame::Systems::ExampleSystem.clear_triggers :removal_triggers
    +# Same as above but for when a component has a certain attribute changed
    +FelFlame::Systems::ExampleSystem.clear_triggers :attr_triggers
    +
    +# Clear a trigger from a specific component
    +FelFlame::Systems::ExampleSystem.clear_triggers :addition_triggers, FelFlame::Component::ExampleComponent[0]
    +# Clear a trigger from a specific component manager
    +FelFlame::Systems::ExampleSystem.clear_triggers :addition_triggers, FelFlame::Component::ExampleComponent
    +
    +# Clear the trigger that executes a system when the ':example_attr' is changes
    +FelFlame::Systems::ExampleSystem.clear_triggers :attr_triggers, :example_attr
    + +
    +

    Parameters:

      +
    • + + trigger_types + + + (:Symbols) + + + + — +
      +

      One or more of the following trigger types: :addition_triggers, :removal_triggers, or :attr_triggers. If attr_triggers is used then you may pass attributes you wish to be cleared as symbols in this parameter as well

      +
      + +
    • +
    • component_or_manager @@ -968,39 +1086,147 @@
       
       
      -77
      -78
      -79
      -80
      -81
      -82
      -83
      -84
      -85
      -86
      -87
      -88
      -89
      -90
      -91
      +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171
    -
    # File 'system_manager.rb', line 77
    +      
    # File 'system_manager.rb', line 103
     
     def clear_triggers(*trigger_types, component_or_manager: nil)
    -  trigger_types = [:addition_triggers, :removal_triggers] if trigger_types.empty?
    -  trigger_types.each do |trigger_type|
    +  trigger_types = [:addition_triggers, :removal_triggers, :attr_triggers] if trigger_types.empty?
    +
    +  if trigger_types.include? :attr_triggers
    +    if (trigger_types - [:addition_triggers,
    +        :removal_triggers,
    +        :attr_triggers]).empty?
    +
    +      if component_or_manager.nil?
    +        #remove all attrs
    +        self.attr_triggers.each do |cmp_or_mgr, attrs|
    +          attrs.each do |attr|
    +            next if cmp_or_mgr.attr_triggers[attr].nil?
    +
    +            cmp_or_mgr.attr_triggers[attr].delete self
    +          end
    +          self.attr_triggers = {}
    +        end
    +      else
    +        #remove attrs relevant to comp_or_man
    +        unless self.attr_triggers[component_or_manager].nil?
    +          self.attr_triggers[component_or_manager].each do |attr|
    +            component_or_manager.attr_triggers[attr].delete self
    +          end
    +          self.attr_triggers[component_or_manager] = []
    +        end
    +      end
    +
    +    else
    +
    +      if component_or_manager.nil?
    +        (trigger_types - [:addition_triggers, :removal_triggers, :attr_triggers]).each do |attr|
    +          #remove attr
    +          self.attr_triggers.each do |cmp_or_mgr, attrs|
    +            cmp_or_mgr.attr_triggers[attr].delete self
    +          end
    +        end
    +        self.attr_triggers.delete (trigger_types - [:addition_triggers,
    +                                                    :removal_triggers,
    +                                                    :attr_triggers])
    +      else
    +        #remove attr from component_or_manager
    +        (trigger_types - [:addition_triggers, :removal_triggers, :attr_triggers]).each do |attr|
    +          next if component_or_manager.attr_triggers[attr].nil?
    +          component_or_manager.attr_triggers[attr].delete self
    +          #self.attr_triggers[component_or_manager].each do |attr|
    +          #  component_or_manager.attr_triggers[attr].delete self
    +          #end
    +        end
    +        self.attr_triggers[component_or_manager] -= trigger_types unless self.attr_triggers[component_or_manager].nil?
    +      end
    +
    +    end
    +  end
    +
    +  (trigger_types & [:removal_triggers, :addition_triggers] - [:attr_triggers]).each do |trigger_type|
         if component_or_manager.nil?
    -      send(trigger_type).each do |trigger|
    +      #remove all removal triggers
    +      self.send(trigger_type).each do |trigger|
             trigger.send(trigger_type).delete self
           end
    -      self.addition_triggers = []
    +      self.send("#{trigger_type.to_s}=", [])
         else
    -      send(trigger_type).delete component_or_manager
    +      #remove removal trigger relevant to comp/man
    +      self.send(trigger_type).delete component_or_manager
           component_or_manager.send(trigger_type).delete self
         end
       end
    -  true
     end
    @@ -1053,12 +1279,12 @@
     
     
    -70
    -71
    -72
    +76 +77 +78
    -
    # File 'system_manager.rb', line 70
    +      
    # File 'system_manager.rb', line 76
     
     def redefine(&block)
       @block = block
    @@ -1112,10 +1338,10 @@
           
     
     
    -66
    +72
    -
    # File 'system_manager.rb', line 66
    +      
    # File 'system_manager.rb', line 72
     
     def step; end
    @@ -1187,14 +1413,14 @@
     
     
    -96
    -97
    -98
    -99
    -100
    +176 +177 +178 +179 +180
    -
    # File 'system_manager.rb', line 96
    +      
    # File 'system_manager.rb', line 176
     
     def trigger_when_added(component_or_manager)
       self.addition_triggers |= [component_or_manager]
    @@ -1204,6 +1430,65 @@
         
       
     
    +
    +    
    +      
    +

    + + #trigger_when_is_changed(component_or_manager, attr) ⇒ Object + + + + + +

    +
    + +

    Add a component or component manager so that it triggers this system when a component's attribute is changed.

    + + +
    +
    +
    + + +
    + + + + +
    +
    +
    +
    +192
    +193
    +194
    +195
    +196
    +197
    +198
    +199
    +200
    +201
    +202
    +203
    +
    +
    # File 'system_manager.rb', line 192
    +
    +def trigger_when_is_changed(component_or_manager, attr)
    +  if component_or_manager.attr_triggers[attr].nil?
    +    component_or_manager.attr_triggers[attr] = [self]
    +  else
    +    component_or_manager.attr_triggers[attr] |= [self]
    +  end
    +  if self.attr_triggers[component_or_manager].nil?
    +    self.attr_triggers[component_or_manager] = [attr]
    +  else
    +    self.attr_triggers[component_or_manager] |= [attr]
    +  end
    +end
    +
    @@ -1270,14 +1555,14 @@
     
     
    -105
    -106
    -107
    -108
    -109
    +185 +186 +187 +188 +189
    -
    # File 'system_manager.rb', line 105
    +      
    # File 'system_manager.rb', line 185
     
     def trigger_when_removed(component_or_manager)
       self.removal_triggers |= [component_or_manager]
    @@ -1294,7 +1579,7 @@
     
     
           
    diff --git a/docs/_index.html b/docs/_index.html
    index cc26e86..1ce8693 100644
    --- a/docs/_index.html
    +++ b/docs/_index.html
    @@ -164,7 +164,7 @@
     
     
           
    diff --git a/docs/file.README.html b/docs/file.README.html
    index 2de097c..ac4599e 100644
    --- a/docs/file.README.html
    +++ b/docs/file.README.html
    @@ -373,7 +373,7 @@ complete I will use a more verbose explanation as below to help users of the fra
     
     
           
    diff --git a/docs/index.html b/docs/index.html
    index ce3390b..460ae00 100644
    --- a/docs/index.html
    +++ b/docs/index.html
    @@ -373,7 +373,7 @@ complete I will use a more verbose explanation as below to help users of the fra
     
     
           
    diff --git a/docs/method_list.html b/docs/method_list.html
    index 6d634b1..609abe6 100644
    --- a/docs/method_list.html
    +++ b/docs/method_list.html
    @@ -92,6 +92,38 @@
       
       
     
    +  
  • +
    + #attr_changed_trigger_systems + FelFlame::Helper::ComponentManager +
    +
  • + + +
  • +
    + #attr_triggers + FelFlame::Systems +
    +
  • + + +
  • +
    + #attr_triggers + FelFlame::Helper::ComponentManager +
    +
  • + + +
  • +
    + attr_triggers + FelFlame::Helper::ComponentManager +
    +
  • + +
  • #attrs @@ -350,13 +382,21 @@
  • +
    + #trigger_when_removed + FelFlame::Systems +
    +
  • + + +
  • #update_attrs FelFlame::Helper::ComponentManager diff --git a/docs/top-level-namespace.html b/docs/top-level-namespace.html index d08d816..00751f9 100644 --- a/docs/top-level-namespace.html +++ b/docs/top-level-namespace.html @@ -127,7 +127,7 @@
    diff --git a/spec/system_manager_spec.rb b/spec/system_manager_spec.rb index c2b8cf6..783b1a7 100644 --- a/spec/system_manager_spec.rb +++ b/spec/system_manager_spec.rb @@ -3,41 +3,44 @@ require_relative '../felflame.rb' describe 'Components' do before :all do - @component_manager ||= FelFlame::Components.new('TestSystems', health: 10, name: 'imp') + @component_manager ||= FelFlame::Components.new('TestSystems', health: 10, name: 'imp', mana: 10) + @@testitr = 999 end before :each do + @@testitr += 1 + @system = FelFlame::Systems.new "Test#{@@testitr}" do + @component_manager.each do |component| + component.health += 5 + end + end end after :each do - #TODO: order breaks it @component_manager.each(&:delete) FelFlame::Entities.each(&:delete) FelFlame::Systems.each(&:clear_triggers) end it 'can create a system' do - FelFlame::Systems.new('Test100') do + FelFlame::Systems.new('Test99') do 'Works' end - expect(FelFlame::Systems::Test100.call).to eq('Works') + expect(FelFlame::Systems::Test99.call).to eq('Works') end it 'can be redefined' do - FelFlame::Systems.new('Test101') do - 'neat' - end - FelFlame::Systems::Test101.redefine do + @system.redefine do 'very neat' end - expect(FelFlame::Systems::Test101.call).to eq('very neat') + expect(@system.call).to eq('very neat') end it 'can iterate over the sorted systems by priority' do - FelFlame::Systems.new('Test102', priority: 1) {} - FelFlame::Systems.new('Test103', priority: 50) {} - FelFlame::Systems.new('Test104', priority: 7) {} - answer_key = ['Test103', 'Test104', 'Test102'] + FelFlame::Systems.new('Test2', priority: 1) {} + FelFlame::Systems.new('Test3', priority: 50) {} + FelFlame::Systems.new('Test4', priority: 7) {} + answer_key = ['Test3', 'Test4', 'Test2'] test = FelFlame::Systems.each.to_a # converts the system name to the constant, compares their positions making sure they are sorted # higher priority should be placed first @@ -55,29 +58,25 @@ describe 'Components' do multiple = 3 first = @component_manager.new(health: init1) second = @component_manager.new(health: init2) - FelFlame::Systems.new('Test105') do + @system.redefine do @component_manager.each do |component| component.health -= multiple end end - FelFlame::Systems::Test105.call + @system.call expect(first.health).to eq(init1 -= multiple) expect(second.health).to eq(init2 -= multiple) 10.times do - FelFlame::Systems::Test105.call + @system.call end expect(first.health).to eq(init1 - (multiple * 10)) expect(second.health).to eq(init2 - (multiple * 10)) end + it 'can trigger when a single Component is added' do - FelFlame::Systems.new 'Test107' do - @component_manager.each do |component| - component.health += 5 - end - end @cmp0 = @component_manager.new @cmp1 = @component_manager.new health: 20 - FelFlame::Systems::Test107.trigger_when_added @cmp0 + @system.trigger_when_added @cmp0 expect(@cmp0.health).to eq(10) expect(@cmp1.health).to eq(20) @entity0 = FelFlame::Entities.new @@ -90,35 +89,25 @@ describe 'Components' do end it 'can trigger when a Component from a manager is added' do - FelFlame::Systems.new 'Test106' do - @component_manager.each do |component| - component.health += 5 - end - end @cmp1 = @component_manager.new @cmp2 = @component_manager.new health: 20 - FelFlame::Systems::Test106.trigger_when_added @component_manager + @system.trigger_when_added @component_manager expect(@cmp1.health).to eq(10) expect(@cmp2.health).to eq(20) @entity1 = FelFlame::Entities.new @entity2 = FelFlame::Entities.new @cmp2 expect(@cmp1.health).to eq(15) expect(@cmp2.health).to eq(25) - FelFlame::Systems::Test106.trigger_when_added @cmp1 + @system.trigger_when_added @cmp1 @entity1.add @cmp1 expect(@cmp1.health).to eq(20) expect(@cmp2.health).to eq(30) end it 'can trigger when a single Component is removed' do - FelFlame::Systems.new 'Test108' do - @component_manager.each do |component| - component.health += 5 - end - end @cmp0 = @component_manager.new @cmp1 = @component_manager.new health: 20 - FelFlame::Systems::Test108.trigger_when_removed @cmp0 + @system.trigger_when_removed @cmp0 expect(@cmp0.health).to eq(10) expect(@cmp1.health).to eq(20) @entity0 = FelFlame::Entities.new @@ -132,17 +121,17 @@ describe 'Components' do @entity0.remove @cmp1 expect(@cmp0.health).to eq(15) expect(@cmp1.health).to eq(25) + @system.clear_triggers(:removal_triggers, component_or_manager: @cmp0) + @entity1.add @cmp0 + @entity1.remove @cmp0 + expect(@cmp0.health).to eq(15) + expect(@cmp1.health).to eq(25) end it 'can trigger when a Component from a manager is removed' do - FelFlame::Systems.new 'Test109' do - @component_manager.each do |component| - component.health += 5 - end - end @cmp0 = @component_manager.new @cmp1 = @component_manager.new health: 20 - FelFlame::Systems::Test109.trigger_when_removed @component_manager + @system.trigger_when_removed @component_manager expect(@cmp0.health).to eq(10) expect(@cmp1.health).to eq(20) @entity0 = FelFlame::Entities.new @@ -152,22 +141,22 @@ describe 'Components' do @entity1.remove @cmp0 expect(@cmp0.health).to eq(15) expect(@cmp1.health).to eq(25) - FelFlame::Systems::Test109.trigger_when_removed @cmp1 + @system.trigger_when_removed @cmp1 @entity0.add @cmp1, @cmp0 @entity0.remove @cmp1 expect(@cmp0.health).to eq(20) expect(@cmp1.health).to eq(30) + @system.clear_triggers(:removal_triggers) + @entity1.add @cmp0, @cmp1 + @entity1.remove @cmp0, @cmp1 + expect(@cmp0.health).to eq(20) + expect(@cmp1.health).to eq(30) end -=begin - it 'can trigger when a single Component is added' do - FelFlame::Systems.new 'Test110' do - @component_manager.each do |component| - component.health += 5 - end - end + + it 'can trigger when a single Component\'s attribute is changed' do @cmp0 = @component_manager.new @cmp1 = @component_manager.new health: 20 - FelFlame::Systems::Test110.trigger_when_is_changed @cmp0, :name + @system.trigger_when_is_changed @cmp0, :name expect(@cmp0.health).to eq(10) expect(@cmp1.health).to eq(20) @entity0 = FelFlame::Entities.new @@ -181,5 +170,231 @@ describe 'Components' do expect(@cmp0.health).to eq(15) expect(@cmp1.health).to eq(25) end -=end + + it 'can clear all triggers' do + @cmp0 = @component_manager.new health: 10 + @cmp1 = @component_manager.new health: 20 + @entity1 = FelFlame::Entities.new + @system.trigger_when_added @cmp0 + @system.trigger_when_added @component_manager + @system.trigger_when_removed @cmp0 + @system.trigger_when_removed @component_manager + @system.trigger_when_is_changed @cmp0, :name + @system.trigger_when_is_changed @component_manager, :name + @system.clear_triggers + expect(@cmp0.health).to eq(10) + expect(@cmp1.health).to eq(20) + @entity1.add @cmp0, @cmp1 + @entity1.remove @cmp0, @cmp1 + @cmp0.name = 'something' + @cmp1.name = 'different' + expect(@cmp0.health).to eq(10) + expect(@cmp1.health).to eq(20) + end + + it 'can clear individual attr_triggers, without component or manager' do + @cmp0 = @component_manager.new health: 10, mana: 10 + @cmp1 = @component_manager.new health: 20, mana: 20 + @entity1 = FelFlame::Entities.new + @system.trigger_when_is_changed @cmp0, :name + @system.trigger_when_is_changed @component_manager, :name + @system.trigger_when_is_changed @cmp0, :mana + @system.trigger_when_is_changed @component_manager, :mana + @system.clear_triggers :attr_triggers, :name + expect(@cmp0.health).to eq(10) + expect(@cmp1.health).to eq(20) + @cmp0.name = 'something' + @cmp1.name = 'different' + expect(@cmp0.health).to eq(10) + expect(@cmp1.health).to eq(20) + @cmp0.mana = 15 + @cmp1.mana = 15 + expect(@cmp0.health).to eq(20) + expect(@cmp1.health).to eq(30) + end + + it 'can clear individual attr_triggers, with component' do + @cmp0 = @component_manager.new health: 10, mana: 10 + @cmp1 = @component_manager.new health: 20, mana: 20 + @entity1 = FelFlame::Entities.new + @system.trigger_when_is_changed @cmp0, :name + @system.trigger_when_is_changed @cmp0, :mana + #expect(@system.attr_triggers).to eq({@cmp0 => [:name, :mana]}) + #expect(@cmp0.attr_triggers).to eq({:name => [@system], :mana => [@system]}) + @system.clear_triggers :attr_triggers, :name, component_or_manager: @cmp0 + #expect(@system.attr_triggers).to eq({@cmp0 => [:mana]}) + #expect(@cmp0.attr_triggers).to eq({:name => [], :mana => [@system]}) + expect(@cmp0.health).to eq(10) + expect(@cmp1.health).to eq(20) + @cmp0.name = 'something' + @cmp1.name = 'different' + expect(@cmp0.health).to eq(10) + expect(@cmp1.health).to eq(20) + @cmp0.mana = 15 + @cmp1.mana = 15 + expect(@cmp0.health).to eq(15) + expect(@cmp1.health).to eq(25) + end + + it 'can clear individual attr_triggers, with manager' do + @cmp0 = @component_manager.new health: 10, mana: 10 + @cmp1 = @component_manager.new health: 20, mana: 20 + @entity1 = FelFlame::Entities.new + @system.trigger_when_is_changed @component_manager, :name + @system.trigger_when_is_changed @component_manager, :mana + @system.clear_triggers :attr_triggers, :name, component_or_manager: @component_manager + expect(@cmp0.health).to eq(10) + expect(@cmp1.health).to eq(20) + @cmp0.name = 'something' + @cmp1.name = 'different' + expect(@cmp0.health).to eq(10) + expect(@cmp1.health).to eq(20) + @cmp0.mana = 15 + @cmp1.mana = 15 + expect(@cmp0.health).to eq(20) + expect(@cmp1.health).to eq(30) + end + + it 'can clear all attr_triggers, without component or manager' do + @cmp0 = @component_manager.new health: 10, mana: 10 + @cmp1 = @component_manager.new health: 20, mana: 20 + @entity1 = FelFlame::Entities.new + @system.trigger_when_is_changed @component_manager, :name + @system.trigger_when_is_changed @cmp1, :mana + @system.clear_triggers :attr_triggers + expect(@cmp0.health).to eq(10) + expect(@cmp1.health).to eq(20) + @cmp0.name = 'something' + @cmp1.name = 'different' + expect(@cmp0.health).to eq(10) + expect(@cmp1.health).to eq(20) + @cmp0.mana = 15 + @cmp1.mana = 15 + expect(@cmp0.health).to eq(10) + expect(@cmp1.health).to eq(20) + end + + it 'can clear all attr_triggers, with component' do + @cmp0 = @component_manager.new health: 10, mana: 10 + @cmp1 = @component_manager.new health: 20, mana: 20 + @entity1 = FelFlame::Entities.new + @system.trigger_when_is_changed @component_manager, :name + @system.trigger_when_is_changed @cmp1, :mana + @system.clear_triggers :attr_triggers, component_or_manager: @cmp1 + expect(@cmp0.health).to eq(10) + expect(@cmp1.health).to eq(20) + @cmp0.name = 'something' + @cmp1.name = 'different' + expect(@cmp0.health).to eq(20) + expect(@cmp1.health).to eq(30) + @cmp0.mana = 15 + @cmp1.mana = 15 + expect(@cmp0.health).to eq(20) + expect(@cmp1.health).to eq(30) + end + + it 'can clear all attr_triggers, with manager' do + @cmp0 = @component_manager.new health: 10, mana: 10 + @cmp1 = @component_manager.new health: 20, mana: 20 + @entity1 = FelFlame::Entities.new + @system.trigger_when_is_changed @component_manager, :name + @system.trigger_when_is_changed @cmp1, :mana + @system.clear_triggers :attr_triggers, component_or_manager: @component_manager + expect(@cmp0.health).to eq(10) + expect(@cmp1.health).to eq(20) + @cmp0.name = 'something' + @cmp1.name = 'different' + expect(@cmp0.health).to eq(10) + expect(@cmp1.health).to eq(20) + @cmp0.mana = 15 + @cmp1.mana = 15 + expect(@cmp0.health).to eq(15) + expect(@cmp1.health).to eq(25) + end + + it 'can clear addition_trigger, without component or manager' do + @cmp0 = @component_manager.new health: 10 + @cmp1 = @component_manager.new health: 20 + @entity1 = FelFlame::Entities.new + @system.trigger_when_added @cmp0 + @system.trigger_when_added @component_manager + @system.clear_triggers(:addition_triggers) + expect(@cmp0.health).to eq(10) + expect(@cmp1.health).to eq(20) + @entity1.add @cmp0, @cmp1 + @entity1.remove @cmp0, @cmp1 + expect(@cmp0.health).to eq(10) + expect(@cmp1.health).to eq(20) + end + + it 'can clear addition_trigger, with component' do + @cmp0 = @component_manager.new health: 10 + @cmp1 = @component_manager.new health: 20 + @entity1 = FelFlame::Entities.new + @system.trigger_when_added @cmp0 + @system.clear_triggers :addition_triggers, component_or_manager: @cmp0 + expect(@cmp0.health).to eq(10) + expect(@cmp1.health).to eq(20) + @entity1.add @cmp0, @cmp1 + @entity1.remove @cmp0, @cmp1 + expect(@cmp0.health).to eq(10) + expect(@cmp1.health).to eq(20) + end + + it 'can clear addition_trigger, with manager' do + @cmp0 = @component_manager.new health: 10 + @cmp1 = @component_manager.new health: 20 + @entity1 = FelFlame::Entities.new + @system.trigger_when_added @component_manager + @system.clear_triggers :addition_triggers, component_or_manager: @component_manager + expect(@cmp0.health).to eq(10) + expect(@cmp1.health).to eq(20) + @entity1.add @cmp0, @cmp1 + @entity1.remove @cmp0, @cmp1 + expect(@cmp0.health).to eq(10) + expect(@cmp1.health).to eq(20) + end + + it 'can clear removal_trigger, without component or manager' do + @cmp0 = @component_manager.new health: 10 + @cmp1 = @component_manager.new health: 20 + @entity1 = FelFlame::Entities.new + @system.trigger_when_removed @cmp0 + @system.trigger_when_removed @component_manager + @system.clear_triggers(:removal_triggers) + expect(@cmp0.health).to eq(10) + expect(@cmp1.health).to eq(20) + @entity1.add @cmp0, @cmp1 + @entity1.remove @cmp0, @cmp1 + expect(@cmp0.health).to eq(10) + expect(@cmp1.health).to eq(20) + end + + it 'can clear removal_trigger, with component' do + @cmp0 = @component_manager.new health: 10 + @cmp1 = @component_manager.new health: 20 + @entity1 = FelFlame::Entities.new + @system.trigger_when_removed @cmp0 + @system.clear_triggers :removal_triggers, component_or_manager: @cmp0 + expect(@cmp0.health).to eq(10) + expect(@cmp1.health).to eq(20) + @entity1.add @cmp0, @cmp1 + @entity1.remove @cmp0, @cmp1 + expect(@cmp0.health).to eq(10) + expect(@cmp1.health).to eq(20) + end + + it 'can clear removal_trigger, with manager' do + @cmp0 = @component_manager.new health: 10 + @cmp1 = @component_manager.new health: 20 + @entity1 = FelFlame::Entities.new + @system.trigger_when_removed @component_manager + @system.clear_triggers :removal_triggers, component_or_manager: @component_manager + expect(@cmp0.health).to eq(10) + expect(@cmp1.health).to eq(20) + @entity1.add @cmp0, @cmp1 + @entity1.remove @cmp0, @cmp1 + expect(@cmp0.health).to eq(10) + expect(@cmp1.health).to eq(20) + end end diff --git a/system_manager.rb b/system_manager.rb index 4bd37b2..2e1bd25 100644 --- a/system_manager.rb +++ b/system_manager.rb @@ -21,6 +21,12 @@ class FelFlame @removal_triggers ||= [] end + attr_writer :attr_triggers + + def attr_triggers + @attr_triggers ||= {} + end + class <