From ba707eebb995eb46141d3c5e1701cd7252ba81c8 Mon Sep 17 00:00:00 2001 From: realtradam Date: Wed, 16 Jun 2021 07:09:43 -0400 Subject: entities, components, and systems improved --- docs/FelFlame/Systems.html | 1174 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 1172 insertions(+), 2 deletions(-) (limited to 'docs/FelFlame/Systems.html') diff --git a/docs/FelFlame/Systems.html b/docs/FelFlame/Systems.html index cfb3a95..65d463b 100644 --- a/docs/FelFlame/Systems.html +++ b/docs/FelFlame/Systems.html @@ -85,6 +85,11 @@ +
+
Extended by:
+
Enumerable
+
+ @@ -94,7 +99,9 @@
Defined in:
-
felflame.rb
+
felflame.rb,
+ system_manager.rb
+
@@ -116,15 +123,1178 @@ +

Instance Attribute Summary collapse

+ + + + + + +

+ Class Method Summary + collapse +

+ + + +

+ Instance Method Summary + collapse +

+ + + + + +
+

Constructor Details

+ +
+

+ + #initialize(name, priority: 0, &block) ⇒ Systems + + + +

+
+ +

Creates a new System which can be accessed as a constant under the namespace FelFlame::Systems. The name given is what constant the system is assigned to

+
+
+
+ +
+

Examples:

+ + +
FelFlame::Systems.new('PassiveHeal', priority: -2, frame: 2) do
+  FelFlame::Components::Health.each do |component|
+    component.hp += 5
+  end
+end
+# Only heal all characters with health every other frame.
+# Give it a low priority so other systems such as a
+#   Poison system would kill the player first
+ +
+

Parameters:

+
    + +
  • + + name + + + (String) + + + + — +
    +

    The name this system will use. Needs to to be in the Ruby Constant format.

    +
    + +
  • + +
  • + + priority + + + (Integer) + + + (defaults to: 0) + + + — +
    +

    Which priority order this system should be executed in relative to other systems. Higher means executed earlier.

    +
    + +
  • + +
  • + + block + + + (Proc) + + + + — +
    +

    The code you wish to be executed when the system is triggered. Can be defined by using a do end block or using { } braces.

    +
    + +
  • + +
+ + +
+ + + + +
+
+
+
+50
+51
+52
+53
+54
+55
+
+
# File 'system_manager.rb', line 50
+
+def initialize(name, priority: 0, &block)
+  FelFlame::Systems.const_set(name, self)
+  @const_name = name
+  @priority = priority
+  @block = block
+end
+
+
+ +
+ +
+

Instance Attribute Details

+ + + +
+

+ + #addition_triggersObject + + + + + +

+ + + + +
+
+
+
+14
+15
+16
+
+
# File 'system_manager.rb', line 14
+
+def addition_triggers
+  @addition_triggers ||= []
+end
+
+
+ + + +
+

+ + #const_nameObject + + + + + +

+
+ +

The Constant name assigned to this System

+ + +
+
+
+ + +
+ + + + +
+
+
+
+7
+8
+9
+
+
# File 'system_manager.rb', line 7
+
+def const_name
+  @const_name
+end
+
+
+ + + +
+

+ + #frameObject + + + + + +

+
+ +

How many frames need to pass before this System is executed when controlled by FelFlame::Stage

+ + +
+
+
+ + +
+ + + + +
+
+
+
+10
+11
+12
+
+
# File 'system_manager.rb', line 10
+
+def frame
+  @frame
+end
+
+
+ + + +
+

+ + #priorityObject + + + + + +

+
+ +

How early this System should be executed in a list of Systems

+ + +
+
+
+ + +
+ + + + +
+
+
+
+4
+5
+6
+
+
# File 'system_manager.rb', line 4
+
+def priority
+  @priority
+end
+
+
+ + + +
+

+ + #removal_triggersObject + + + + + +

+ + + + +
+
+
+
+20
+21
+22
+
+
# File 'system_manager.rb', line 20
+
+def removal_triggers
+  @removal_triggers ||= []
+end
+
+
+ +
+ + +
+

Class Method Details

+ + +
+

+ + .each(&block) ⇒ Enumerator + + + + + +

+
+ +

Iterate over all Systems, sorted by their priority. You also call other enumerable methods instead of each, such as each_with_index or select

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Enumerator) + + + +
  • + +
+ +
+ + + + +
+
+
+
+29
+30
+31
+
+
# File 'system_manager.rb', line 29
+
+def each(&block)
+  constants.map { |sym| const_get(sym) }.sort_by(&:priority).reverse.each(&block)
+end
+
+
+ +
+ +
+

Instance Method Details

+ + +
+

+ + #callObject + + + + + +

+
+ +

Manually execute the system a single time

+ + +
+
+
+ + +
+ + + + +
+
+
+
+58
+59
+60
+
+
# File 'system_manager.rb', line 58
+
+def call
+  @block.call
+end
+
+
+ +
+

+ + #clear_triggers(*trigger_types, component_or_manager: nil) ⇒ Boolean + + + + + +

+
+ +

Removes triggers from this system

+ + +
+
+
+

Parameters:

+
    + +
  • + + component_or_manager + + + (Component or ComponentManager) + + + (defaults to: nil) + + + — +
    +

    The object to clear triggers from. Use Nil to clear triggers from all components associated with this system.

    +
    + +
  • + +
+ +

Returns:

+
    + +
  • + + + (Boolean) + + + + — +
    +

    true

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+77
+78
+79
+80
+81
+82
+83
+84
+85
+86
+87
+88
+89
+90
+91
+
+
# File 'system_manager.rb', line 77
+
+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|
+    if component_or_manager.nil?
+      send(trigger_type).each do |trigger|
+        trigger.send(trigger_type).delete self
+      end
+      self.addition_triggers = []
+    else
+      send(trigger_type).delete component_or_manager
+      component_or_manager.send(trigger_type).delete self
+    end
+  end
+  true
+end
+
+
+ +
+

+ + #redefine(&block) ⇒ Object + + + + + +

+
+ +

Redefine what code is executed by this System when it is called upon.

+ + +
+
+
+

Parameters:

+
    + +
  • + + block + + + (Proc) + + + + — +
    +

    The code you wish to be executed when the system is triggered. Can be defined by using a do end block or using { } braces.

    +
    + +
  • + +
+ + +
+ + + + +
+
+
+
+70
+71
+72
+
+
# File 'system_manager.rb', line 70
+
+def redefine(&block)
+  @block = block
+end
+
+
+ +
+

+ + #stepBoolean + + + + + +

+
+ +

Attempt to execute the system following the frame parameter set on this system. For example if a System has its frame set to 3, it will only execute once every third frame that is called in FelFlame::Stage

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Boolean) + + + + — +
    +

    true if the frame of the FelFlame::Stage is a multiple of this System's frame setting and this system has executed, false otherwise where the system has not executed.

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+66
+
+
# File 'system_manager.rb', line 66
+
+def step; end
+
+
+ +
+

+ + #trigger_when_added(component_or_manager) ⇒ Boolean + + + + + +

+
+ +

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

+ + +
+
+
+

Parameters:

+
    + +
  • + + component_or_manager + + + (Component or ComponentManager) + + + + — +
    +

    The component or component manager to trigger this system when added

    +
    + +
  • + +
+ +

Returns:

+
    + +
  • + + + (Boolean) + + + + — +
    +

    true

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+96
+97
+98
+99
+100
+
+
# File 'system_manager.rb', line 96
+
+def trigger_when_added(component_or_manager)
+  self.addition_triggers |= [component_or_manager]
+  component_or_manager.addition_triggers |= [self]
+  true
+end
+
+
+ +
+

+ + #trigger_when_removed(component_or_manager) ⇒ Boolean + + + + + +

+
+ +

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

+ + +
+
+
+

Parameters:

+
    + +
  • + + component_or_manager + + + (Component or ComponentManager) + + + + — +
    +

    The component or component manager to trigger this system when removed

    +
    + +
  • + +
+ +

Returns:

+
    + +
  • + + + (Boolean) + + + + — +
    +

    true

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+105
+106
+107
+108
+109
+
+
# File 'system_manager.rb', line 105
+
+def trigger_when_removed(component_or_manager)
+  self.removal_triggers |= [component_or_manager]
+  component_or_manager.removal_triggers |= [self]
+  true
+end
+
+
+ +
-- cgit v1.2.3