From a96733c75ce7caff16a1d79a9caa1894ed95d2ca Mon Sep 17 00:00:00 2001 From: realtradam Date: Sat, 3 Jul 2021 00:36:00 -0400 Subject: completed systems functionality --- docs/FelFlame/Systems.html | 403 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 344 insertions(+), 59 deletions(-) (limited to 'docs/FelFlame/Systems.html') 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 @@
     
     
           
    -- 
    cgit v1.2.3