From bf6769c6b1658c5f6a7b02fc8fc0400fc4f61dec Mon Sep 17 00:00:00 2001 From: realtradam Date: Fri, 28 Jan 2022 16:41:23 -0500 Subject: fix order of attr triggers --- docs/FelECS.html | 335 +++++++++ docs/FelECS/ComponentManager.html | 1239 ++++++++++++++++++++++++++++++ docs/FelECS/Components.html | 337 +++++++++ docs/FelECS/Entities.html | 792 +++++++++++++++++++ docs/FelECS/Order.html | 251 +++++++ docs/FelECS/Scenes.html | 765 +++++++++++++++++++ docs/FelECS/Stage.html | 572 ++++++++++++++ docs/FelECS/Systems.html | 1505 +++++++++++++++++++++++++++++++++++++ docs/_index.html | 96 ++- docs/class_list.html | 2 +- docs/file.README.html | 532 +++++-------- docs/index.html | 532 +++++-------- docs/method_list.html | 368 +++++++++ docs/top-level-namespace.html | 39 +- lib/felecs/component_manager.rb | 6 +- mrbgem/mrblib/felecs.rb | 6 +- 16 files changed, 6704 insertions(+), 673 deletions(-) create mode 100644 docs/FelECS.html create mode 100644 docs/FelECS/ComponentManager.html create mode 100644 docs/FelECS/Components.html create mode 100644 docs/FelECS/Entities.html create mode 100644 docs/FelECS/Order.html create mode 100644 docs/FelECS/Scenes.html create mode 100644 docs/FelECS/Stage.html create mode 100644 docs/FelECS/Systems.html diff --git a/docs/FelECS.html b/docs/FelECS.html new file mode 100644 index 0000000..d2d03b4 --- /dev/null +++ b/docs/FelECS.html @@ -0,0 +1,335 @@ + + + + + + + Module: FelECS + + — Documentation by YARD 0.9.26 + + + + + + + + + + + + + + + + + + + +
+ + +

Module: FelECS + + + +

+
+ + + + + + + + + + + +
+
Defined in:
+
lib/felecs.rb,
+ lib/felecs/order.rb,
lib/felecs/version.rb,
lib/felecs/scene_manager.rb,
lib/felecs/stage_manager.rb,
lib/felecs/entity_manager.rb,
lib/felecs/system_manager.rb,
lib/felecs/component_manager.rb
+
+
+ +
+ +

Overview

+
+ +

:nocov: Keeps the version of the Gem

+ + +
+
+
+ + +

Defined Under Namespace

+

+ + + Modules: Components, Order, Stage + + + + Classes: ComponentManager, Entities, Scenes, Systems + + +

+ + +

+ Constant Summary + collapse +

+ +
+ +
Ent = +
+
+ +

An alias for Entities

+ + +
+
+
+ + +
+
+
FelECS::Entities
+ +
Cmp = +
+
+ +

An alias for Components

+ + +
+
+
+ + +
+
+
FelECS::Components
+ +
Sys = +
+
+ +

An alias for Systems

+ + +
+
+
+ + +
+
+
FelECS::Systems
+ +
Scn = +
+
+ +

An alias for Scenes

+ + +
+
+
+ + +
+
+
FelECS::Scenes
+ +
Stg = +
+
+ +

An alias for Stage

+ + +
+
+
+ + +
+
+
FelECS::Stage
+ +
Odr = +
+
+
An alias for {FelECS +
+ + +
+
+
+ + +
+
+
FelECS::Order
+ +
VERSION = +
+
+ +

The version of the Gem

+ + +
+
+
+ + +
+
+
'5.0.0'
+ +
+ + + + + + + + + +

+ Class Method Summary + collapse +

+ + + + + + +
+

Class Method Details

+ + +
+

+ + .callObject + + + + + +

+
+ +

An alias for FelECS::Stage.call. It executes a single frame in the game.

+ + +
+
+
+ + +
+ + + + +
+
+
+
+18
+19
+20
+
+
# File 'lib/felecs.rb', line 18
+
+def call
+  FelECS::Stage.call
+end
+
+
+ +
+ +
+ + + +
+ + \ No newline at end of file diff --git a/docs/FelECS/ComponentManager.html b/docs/FelECS/ComponentManager.html new file mode 100644 index 0000000..de5d5c3 --- /dev/null +++ b/docs/FelECS/ComponentManager.html @@ -0,0 +1,1239 @@ + + + + + + + Class: FelECS::ComponentManager + + — Documentation by YARD 0.9.26 + + + + + + + + + + + + + + + + + + + +
+ + +

Class: FelECS::ComponentManager + + + +

+
+ +
+
Inherits:
+
+ Object + +
    +
  • Object
  • + + + +
+ show all + +
+
+ + + + + + + + + + + +
+
Defined in:
+
lib/felecs/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 #to_h and #update_attrs methods instead.

+ + +
+
+
+ + +
+ + + +

Class Attribute Summary collapse

+
    + +
  • + + + .addition_triggers ⇒ Array<System> + + + + + + + + + readonly + + + + + + + + + +
    +

    Stores references to systems that should be triggered when this component is added to an enitity.

    +
    + +
  • + + +
  • + + + .attr_triggers ⇒ Hash<Symbol, System> + + + + + + + + + readonly + + + + + + + + + +
    +

    Stores references to systems that should be triggered when an attribute from this component changed.

    +
    + +
  • + + +
  • + + + .removal_triggers ⇒ Array<System> + + + + + + + + + readonly + + + + + + + + + +
    +

    Stores references to systems that should be triggered when this component is removed from an enitity.

    +
    + +
  • + + +
+ +

Instance Attribute Summary collapse

+
    + +
  • + + + #addition_triggers ⇒ Array<System> + + + + + + + + + readonly + + + + + + + + + +
    +

    Stores references to systems that should be triggered when a component from this manager is added.

    +
    + +
  • + + +
  • + + + #attr_triggers ⇒ Hash<Symbol, Array<System>> + + + + + + + + + readonly + + + + + + + + + +
    +

    Stores references to systems that should be triggered when an attribute from this manager is changed.

    +
    + +
  • + + +
  • + + + #removal_triggers ⇒ Array<System> + + + + + + + + + readonly + + + + + + + + + +
    +

    Stores references to systems that should be triggered when a component from this manager is removed.

    +
    + +
  • + + +
+ + + + + +

+ Instance Method Summary + collapse +

+ + + + +
+

Constructor Details

+ +
+

+ + #initialize(**attrs) ⇒ Component + + + + + +

+
+ +

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 + + + (Keyword: Value) + + + + — +
    +

    You can pass any number of Keyword-Value pairs

    +
    + +
  • + +
+ + +
+ + + + +
+
+
+
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+
+
# File 'lib/felecs/component_manager.rb', line 134
+
+def initialize(**attrs)
+  # Prepare the object
+  # (this is a function created with metaprogramming
+  # in FelECS::Components)
+  set_defaults
+
+  # Fill params
+  attrs.each do |key, value|
+    send "#{key}=", value
+  end
+
+  # Save Component
+  self.class.push self
+end
+
+
+ +
+ +
+

Class Attribute Details

+ + + +
+

+ + .addition_triggersArray<System> + + + + + +

+
+ +

Stores references to systems that should be triggered when this component is added to an enitity. Do not edit this array as it is managed by FelECS automatically.

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Array<System>) + + + +
  • + +
+ +
+ + + + +
+
+
+
+182
+183
+184
+
+
# File 'lib/felecs/component_manager.rb', line 182
+
+def addition_triggers
+  @addition_triggers ||= []
+end
+
+
+ + + +
+

+ + .attr_triggersHash<Symbol, System> + + + + + +

+
+ +

Stores references to systems that should be triggered when an attribute from this component changed. Do not edit this hash as it is managed by FelECS automatically.

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Hash<Symbol, System>) + + + +
  • + +
+ +
+ + + + +
+
+
+
+198
+199
+200
+
+
# File 'lib/felecs/component_manager.rb', line 198
+
+def attr_triggers
+  @attr_triggers ||= {}
+end
+
+
+ + + +
+

+ + .removal_triggersArray<System> + + + + + +

+
+ +

Stores references to systems that should be triggered when this component is removed from an enitity. Do not edit this array as it is managed by FelECS automatically.

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Array<System>) + + + +
  • + +
+ +
+ + + + +
+
+
+
+190
+191
+192
+
+
# File 'lib/felecs/component_manager.rb', line 190
+
+def removal_triggers
+  @removal_triggers ||= []
+end
+
+
+ +
+ +
+

Instance Attribute Details

+ + + +
+

+ + #addition_triggersArray<System> + + + + + +

+
+ +

Stores references to systems that should be triggered when a component from this manager is added. Do not edit this array as it is managed by FelECS automatically.

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Array<System>) + + + +
  • + +
+ +
+ + + + +
+
+
+
+111
+112
+113
+
+
# File 'lib/felecs/component_manager.rb', line 111
+
+def addition_triggers
+  @addition_triggers ||= []
+end
+
+
+ + + +
+

+ + #attr_triggersHash<Symbol, Array<System>> + + + + + +

+
+ +

Stores references to systems that should be triggered when an attribute from this manager is changed. Do not edit this hash as it is managed by FelECS automatically.

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Hash<Symbol, Array<System>>) + + + +
  • + +
+ +
+ + + + +
+
+
+
+127
+128
+129
+
+
# File 'lib/felecs/component_manager.rb', line 127
+
+def attr_triggers
+  @attr_triggers ||= {}
+end
+
+
+ + + +
+

+ + #removal_triggersArray<System> + + + + + +

+
+ +

Stores references to systems that should be triggered when a component from this manager is removed. Do not edit this array as it is managed by FelECS automatically.

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Array<System>) + + + +
  • + +
+ +
+ + + + +
+
+
+
+119
+120
+121
+
+
# File 'lib/felecs/component_manager.rb', line 119
+
+def removal_triggers
+  @removal_triggers ||= []
+end
+
+
+ +
+ + +
+

Instance Method Details

+ + +
+

+ + #deleteBoolean + + + + + +

+
+ +

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

+ + +
+
+
+ +

Returns:

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

    true.

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+
+
# File 'lib/felecs/component_manager.rb', line 249
+
+def delete
+  addition_triggers.each do |system|
+    system.clear_triggers component_or_manager: self
+  end
+  entities.reverse_each do |entity|
+    entity.remove self
+  end
+  self.class._data.delete self
+  instance_variables.each do |var|
+    instance_variable_set(var, nil)
+  end
+  true
+end
+
+
+ +
+

+ + #entitiesArray<Component> + + + + + +

+
+ +

Entities that have this component

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Array<Component>) + + + +
  • + +
+ +
+ + + + +
+
+
+
+211
+212
+213
+
+
# File 'lib/felecs/component_manager.rb', line 211
+
+def entities
+  @entities ||= []
+end
+
+
+ +
+

+ + #entityComponent + + + + + +

+
+ +

A single entity. Use this if you expect the component to only belong to one entity and you want to access it.

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Component) + + + +
  • + +
+ +
+ + + + +
+
+
+
+217
+218
+219
+220
+221
+222
+223
+224
+
+
# File 'lib/felecs/component_manager.rb', line 217
+
+def entity
+  if entities.empty?
+    Warning.warn("This component belongs to NO entities but you called the method that is intended for components belonging to a single entity.\nYou may have a bug in your logic.")
+  elsif entities.length > 1
+    Warning.warn("This component belongs to MANY entities but you called the method that is intended for components belonging to a single entity.\nYou may have a bug in your logic.")
+  end
+  entities.first
+end
+
+
+ +
+

+ + #to_hHash<Symbol, Value> + + + + + +

+
+ +

Returns A hash, where all the keys are attributes storing their respective values.

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Hash<Symbol, Value>) + + + + — +
    +

    A hash, where all the keys are attributes storing their respective values.

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+264
+265
+266
+267
+268
+269
+270
+
+
# File 'lib/felecs/component_manager.rb', line 264
+
+def to_h
+  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
+
+
+ +
+

+ + #update_attrs(**opts) ⇒ Hash<Symbol, Value> + + + + + +

+
+ +

Update attribute values using a hash or keywords.

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Hash<Symbol, Value>) + + + + — +
    +

    Hash of updated attributes

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+228
+229
+230
+231
+232
+
+
# File 'lib/felecs/component_manager.rb', line 228
+
+def update_attrs(**opts)
+  opts.each do |key, value|
+    send "#{key}=", value
+  end
+end
+
+
+ +
+ +
+ + + +
+ + \ No newline at end of file diff --git a/docs/FelECS/Components.html b/docs/FelECS/Components.html new file mode 100644 index 0000000..a1b7abc --- /dev/null +++ b/docs/FelECS/Components.html @@ -0,0 +1,337 @@ + + + + + + + Module: FelECS::Components + + — Documentation by YARD 0.9.26 + + + + + + + + + + + + + + + + + + + +
+ + +

Module: FelECS::Components + + + +

+
+ + + + + + + + + + + +
+
Defined in:
+
lib/felecs.rb,
+ lib/felecs/component_manager.rb
+
+
+ +
+ +

Overview

+
+ +

Creates component managers and allows accessing them them under the Components namespace as Constants. You can use array methods directly on this class to access Component Managers.

+ +

To see how component managers are used please look at the ComponentManager documentation.

+ + +
+
+
+ + +
+ + + + + + + +

+ Class Method Summary + collapse +

+ + + + + + +
+

Class Method Details

+ + +
+

+ + .new(component_name, *attrs, **attrs_with_defaults) ⇒ ComponentManager + + + + + +

+
+ +

Creates a new component manager.

+ + +
+
+
+ +
+

Examples:

+ + +
# Here color is set to default to red
+# while max and current are nil until set.
+# When you make a new component using this component manager
+# these are the values and accessors it will have.
+FelECS::Component.new('Health', :max, :current, color: 'red')
+ +
+

Parameters:

+
    + +
  • + + component_name + + + (String) + + + + — +
    +

    Name of your new component manager. Must be stylized in the format of constants in Ruby

    +
    + +
  • + +
  • + + attrs + + + (:Symbols) + + + + — +
    +

    New components made with this manager will include these symbols as accessors, the values of these accessors will default to nil

    +
    + +
  • + +
  • + + attrs_with_defaults + + + (Keyword: DefaultValue) + + + + — +
    +

    New components made with this manager will include these keywords as accessors, their defaults set to the values given to the keywords

    +
    + +
  • + +
+ +

Returns:

+ + +
+ + + + +
+
+
+
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+40
+41
+42
+43
+44
+45
+46
+47
+48
+49
+50
+51
+
+
# File 'lib/felecs/component_manager.rb', line 20
+
+def new(component_name, *attrs, **attrs_with_defaults)
+  if FelECS::Components.const_defined?(component_name)
+    raise(NameError.new, "Component Manager '#{component_name}' is already defined")
+  end
+
+  const_set(component_name, Class.new(FelECS::ComponentManager) {})
+  update_const_cache
+
+  attrs.each do |attr|
+    if FelECS::Components.const_get(component_name).method_defined?(attr.to_s) || FelECS::Components.const_get(component_name).method_defined?("#{attr}=")
+      raise NameError, "The attribute name \"#{attr}\" is already a method"
+    end
+
+    FelECS::Components.const_get(component_name).attr_accessor attr
+  end
+  attrs_with_defaults.each do |attr, _default|
+    attrs_with_defaults[attr] = _default.dup
+    FelECS::Components.const_get(component_name).attr_reader attr
+    FelECS::Components.const_get(component_name).define_method("#{attr}=") do |value|
+      unless value.equal? send(attr)
+        instance_variable_set("@#{attr}", value)
+        attr_changed_trigger_systems(attr)
+      end
+    end
+  end
+  FelECS::Components.const_get(component_name).define_method(:set_defaults) do
+    attrs_with_defaults.each do |attr, default|
+      instance_variable_set("@#{attr}", default.dup)
+    end
+  end
+  FelECS::Components.const_get(component_name)
+end
+
+
+ +
+ +
+ + + +
+ + \ No newline at end of file diff --git a/docs/FelECS/Entities.html b/docs/FelECS/Entities.html new file mode 100644 index 0000000..1d2bda6 --- /dev/null +++ b/docs/FelECS/Entities.html @@ -0,0 +1,792 @@ + + + + + + + Class: FelECS::Entities + + — Documentation by YARD 0.9.26 + + + + + + + + + + + + + + + + + + + +
+ + +

Class: FelECS::Entities + + + +

+
+ +
+
Inherits:
+
+ Object + +
    +
  • Object
  • + + + +
+ show all + +
+
+ + + + + + + + + + + +
+
Defined in:
+
lib/felecs.rb,
+ lib/felecs/entity_manager.rb
+
+
+ +
+ +

Overview

+
+ +

Creates and manages Entities. Entities are just collections of Components. You can use array methods directly on this class to access Entities.

+ + +
+
+
+ + +
+ + + + + + + +

+ Instance Method Summary + collapse +

+ + + + +
+

Constructor Details

+ +
+

+ + #initialize(*components) ⇒ Entity + + + + + +

+
+ +

Creating a new Entity

+ + +
+
+
+

Parameters:

+
    + +
  • + + components + + + (Components) + + + + — +
    +

    Can be any number of components, identical duplicates will be automatically purged however different components from the same component manager are allowed.

    +
    + +
  • + +
+ + +
+ + + + +
+
+
+
+8
+9
+10
+11
+12
+
+
# File 'lib/felecs/entity_manager.rb', line 8
+
+def initialize(*components)
+  # Add each component
+  add(*components)
+  self.class._data.push self
+end
+
+
+ +
+ + +
+

Instance Method Details

+ + +
+

+ + #add(*components_to_add) ⇒ Boolean + + + + + +

+
+ +

Add any number components to the Entity.

+ + +
+
+
+

Parameters:

+
    + +
  • + + components_to_add + + + (Component) + + + + — +
    +

    Any number of components created from any component manager

    +
    + +
  • + +
+ +

Returns:

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

    true

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+57
+58
+59
+60
+61
+62
+63
+64
+65
+66
+67
+68
+69
+70
+
+
# File 'lib/felecs/entity_manager.rb', line 57
+
+def add(*components_to_add)
+  components_to_add.each do |component|
+    if components[component.class].nil?
+      components[component.class] = [component]
+      component.entities.push self
+      check_systems component, :addition_triggers
+    elsif !components[component.class].include? component
+      components[component.class].push component
+      component.entities.push self
+      check_systems component, :addition_triggers
+    end
+  end
+  true
+end
+
+
+ +
+

+ + #component(manager = nil) ⇒ Component + + + + + +

+
+ +

A single component from a component manager. Use this if you expect the component to only belong to one entity and you want to access it. Access the component using either parameter notation or array notation. Array notation is conventional for better readablility.

+ + +
+
+
+ +
+

Examples:

+ + +
@entity.component[@component_manager] # array notation(the standard)
+@entity.component(@component_manager) # method notation
+ +
+

Parameters:

+
    + +
  • + + manager + + + (ComponentManager) + + + (defaults to: nil) + + + — +
    +

    If you pass nil you can then use array notation to access the same value.

    +
    + +
  • + +
+ +

Returns:

+
    + +
  • + + + (Component) + + + +
  • + +
+ +
+ + + + +
+
+
+
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+
+
# File 'lib/felecs/entity_manager.rb', line 26
+
+def component(manager = nil)
+  if manager.nil?
+    FelECS::Entities.component_redirect.entity = self
+    FelECS::Entities.component_redirect
+  else
+    if components[manager].nil?
+      raise "This entity(#{self}) doesnt have any components of this type: #{manager}"
+    elsif components[manager].length > 1
+      Warning.warn("This entity has MANY of this component but you called the method that is intended for having a single of this component type.\nYou may have a bug in your logic.")
+    end
+
+    components[manager].first
+  end
+end
+
+
+ +
+

+ + #componentsHash<Component_Manager, Array<Integer>> + + + + + +

+
+ +

A hash that uses component manager constant names as keys, and where the values of those keys are arrays that contain the the components attached to this entity.

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Hash<Component_Manager, Array<Integer>>) + + + +
  • + +
+ +
+ + + + +
+
+
+
+16
+17
+18
+
+
# File 'lib/felecs/entity_manager.rb', line 16
+
+def components
+  @components ||= {}
+end
+
+
+ +
+

+ + #deleteBoolean + + + + + +

+
+ +

Removes this Entity from the list and purges all references to this Entity from other Components, as well as its data.

+ + +
+
+
+ +

Returns:

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

    true

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+43
+44
+45
+46
+47
+48
+49
+50
+51
+52
+
+
# File 'lib/felecs/entity_manager.rb', line 43
+
+def delete
+  components.each do |_component_manager, component_array|
+    component_array.reverse_each do |component|
+      component.entities.delete(self)
+    end
+  end
+  FelECS::Entities._data.delete self
+  @components = {}
+  true
+end
+
+
+ +
+

+ + #remove(*components_to_remove) ⇒ Boolean + + + + + +

+
+ +

Remove a component from the Entity

+ + +
+
+
+

Parameters:

+
    + +
  • + + components_to_remove + + + (Component) + + + + — +
    +

    A component created from any component manager

    +
    + +
  • + +
+ +

Returns:

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

    true

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+87
+88
+89
+90
+91
+92
+93
+94
+95
+
+
# File 'lib/felecs/entity_manager.rb', line 87
+
+def remove(*components_to_remove)
+  components_to_remove.each do |component|
+    check_systems component, :removal_triggers if component.entities.include? self
+    component.entities.delete self
+    components[component.class].delete component
+    components.delete component.class if components[component.class].empty?
+  end
+  true
+end
+
+
+ +
+ +
+ + + +
+ + \ No newline at end of file diff --git a/docs/FelECS/Order.html b/docs/FelECS/Order.html new file mode 100644 index 0000000..8ea39da --- /dev/null +++ b/docs/FelECS/Order.html @@ -0,0 +1,251 @@ + + + + + + + Module: FelECS::Order + + — Documentation by YARD 0.9.26 + + + + + + + + + + + + + + + + + + + +
+ + +

Module: FelECS::Order + + + +

+
+ + + + + + + + + + + +
+
Defined in:
+
lib/felecs.rb,
+ lib/felecs/order.rb
+
+
+ +
+ +

Overview

+
+ +

Sets the priority of a list of Systems or Scenes for you in the order you pass them to this class.

+ + +
+
+
+ + +
+ + + + + + + +

+ Class Method Summary + collapse +

+ +
    + +
  • + + + .sort(*sortables) ⇒ Boolean + + + + + + + + + + + + + +
    +

    Sets the priority of all items passed into this method according to the order they were passed.

    +
    + +
  • + + +
+ + + + +
+

Class Method Details

+ + +
+

+ + .sort(*sortables) ⇒ Boolean + + + + + +

+
+ +

Sets the priority of all items passed into this method according to the order they were passed. If an array is one of the elements then it will give all of those elements in the array the same priority.

+ + +
+
+
+

Parameters:

+ + +

Returns:

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

    true.

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+
+
# File 'lib/felecs/order.rb', line 11
+
+def self.sort(*sortables)
+  sortables.each_with_index do |sorted, index|
+    if sorted.respond_to? :priority
+      sorted.priority = index
+    else
+      sorted.each do |item|
+        item.priority = index
+      end
+    end
+  end
+  true
+end
+
+
+ +
+ +
+ + + +
+ + \ No newline at end of file diff --git a/docs/FelECS/Scenes.html b/docs/FelECS/Scenes.html new file mode 100644 index 0000000..e548278 --- /dev/null +++ b/docs/FelECS/Scenes.html @@ -0,0 +1,765 @@ + + + + + + + Class: FelECS::Scenes + + — Documentation by YARD 0.9.26 + + + + + + + + + + + + + + + + + + + +
+ + +

Class: FelECS::Scenes + + + +

+
+ +
+
Inherits:
+
+ Object + +
    +
  • Object
  • + + + +
+ show all + +
+
+ + + + + + + + + + + +
+
Defined in:
+
lib/felecs.rb,
+ lib/felecs/scene_manager.rb
+
+
+ +
+ +

Overview

+
+ +

Creates and manages Scenes. Scenes are collections of Systems, and execute all the Systems when called upon. Any scenes you create are accessable under the Scenes namespace as Constants.

+ + +
+
+
+ + +
+ + + +

Instance Attribute Summary collapse

+
    + +
  • + + + #priority ⇒ Object + + + + + + + + + + + + + + + + +
    +

    How early this Scene should be executed in a list of Scenes.

    +
    + +
  • + + +
  • + + + #systems ⇒ Array<System> + + + + + + + + + readonly + + + + + + + + + +
    +

    The list of Systems this Scene contains.

    +
    + +
  • + + +
+ + + + + +

+ Instance Method Summary + collapse +

+ + + + +
+

Constructor Details

+ +
+

+ + #initialize(name, priority: 0) ⇒ Scenes + + + + + +

+
+ +

Create a new Scene using the name given

+ + +
+
+
+

Parameters:

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

    String format must follow requirements of a constant

    +
    + +
  • + +
+ + +
+ + + + +
+
+
+
+22
+23
+24
+25
+
+
# File 'lib/felecs/scene_manager.rb', line 22
+
+def initialize(name, priority: 0)
+  self.priority = priority
+  FelECS::Scenes.const_set(name, self)
+end
+
+
+ +
+ +
+

Instance Attribute Details

+ + + +
+

+ + #priorityObject + + + + + +

+
+ +

How early this Scene should be executed in a list of Scenes

+ + +
+
+
+ + +
+ + + + +
+
+
+
+12
+13
+14
+
+
# File 'lib/felecs/scene_manager.rb', line 12
+
+def priority
+  @priority
+end
+
+
+ + + +
+

+ + #systemsArray<System> + + + + + +

+
+ +

The list of Systems this Scene contains

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Array<System>) + + + +
  • + +
+ +
+ + + + +
+
+
+
+29
+30
+31
+
+
# File 'lib/felecs/scene_manager.rb', line 29
+
+def systems
+  @systems ||= []
+end
+
+
+ +
+ + +
+

Instance Method Details

+ + +
+

+ + #add(*systems_to_add) ⇒ Boolean + + + + + +

+
+ +

Adds any number of Systems to this Scene

+ + +
+
+
+ +

Returns:

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

    true

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+42
+43
+44
+45
+46
+47
+48
+49
+
+
# File 'lib/felecs/scene_manager.rb', line 42
+
+def add(*systems_to_add)
+  self.systems |= systems_to_add
+  self.systems = systems.sort_by(&:priority)
+  systems_to_add.each do |system|
+    system.scenes |= [self]
+  end
+  true
+end
+
+
+ +
+

+ + #callBoolean + + + + + +

+
+ +

Execute all systems in this Scene, in the order of their priority

+ + +
+
+
+ +

Returns:

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

    true

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+35
+36
+37
+38
+
+
# File 'lib/felecs/scene_manager.rb', line 35
+
+def call
+  systems.each(&:call)
+  true
+end
+
+
+ +
+

+ + #clearBoolean + + + + + +

+
+ +

Removes all Systems from this Scene

+ + +
+
+
+ +

Returns:

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

    true

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+60
+61
+62
+63
+64
+65
+66
+67
+
+
# File 'lib/felecs/scene_manager.rb', line 60
+
+def clear
+  systems.each do |system|
+    system.scenes.delete self
+  end
+  systems.clear
+  # FelECS::Stage.update_systems_list if FelECS::Stage.scenes.include? self
+  true
+end
+
+
+ +
+

+ + #remove(*systems_to_remove) ⇒ Boolean + + + + + +

+
+ +

Removes any number of Systems from this Scene

+ + +
+
+
+ +

Returns:

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

    true

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+53
+54
+55
+56
+
+
# File 'lib/felecs/scene_manager.rb', line 53
+
+def remove(*systems_to_remove)
+  self.systems -= systems_to_remove
+  true
+end
+
+
+ +
+ +
+ + + +
+ + \ No newline at end of file diff --git a/docs/FelECS/Stage.html b/docs/FelECS/Stage.html new file mode 100644 index 0000000..ec24ccf --- /dev/null +++ b/docs/FelECS/Stage.html @@ -0,0 +1,572 @@ + + + + + + + Module: FelECS::Stage + + — Documentation by YARD 0.9.26 + + + + + + + + + + + + + + + + + + + +
+ + +

Module: FelECS::Stage + + + +

+
+ + + + + + + + + + + +
+
Defined in:
+
lib/felecs.rb,
+ lib/felecs/stage_manager.rb
+
+
+ +
+ +

Overview

+
+ +

Stores Scenes you add to it which you want to execute on each frame. When called upon will execute all Systems in the Scenes in the Stage and will execute them according to their priority order.

+ + +
+
+
+ + +
+ + + +

Class Attribute Summary collapse

+
    + +
  • + + + .scenes ⇒ Array<Scene> + + + + + + + + + readonly + + + + + + + + + +
    +

    Contains all the Scenes added to the Stage.

    +
    + +
  • + + +
+ + + + + +

+ Class Method Summary + collapse +

+ + + + + +
+

Class Attribute Details

+ + + +
+

+ + .scenesArray<Scene> + + + + + +

+
+ +

Contains all the Scenes added to the Stage

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Array<Scene>) + + + +
  • + +
+ +
+ + + + +
+
+
+
+42
+43
+44
+
+
# File 'lib/felecs/stage_manager.rb', line 42
+
+def scenes
+  @scenes ||= []
+end
+
+
+ +
+ + +
+

Class Method Details

+ + +
+

+ + .add(*scenes_to_add) ⇒ Boolean + + + + + +

+
+ +

Add any number of Scenes to the Stage

+ + +
+
+
+ +

Returns:

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

    true

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+13
+14
+15
+16
+17
+
+
# File 'lib/felecs/stage_manager.rb', line 13
+
+def add(*scenes_to_add)
+  self.scenes |= scenes_to_add
+  self.scenes = scenes.sort_by(&:priority)
+  true
+end
+
+
+ +
+

+ + .callBoolean + + + + + +

+
+ +

Executes one frame of the game. This executes all the Scenes added to the Stage in order of their priority.

+ + +
+
+
+ +

Returns:

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

    true

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+35
+36
+37
+38
+
+
# File 'lib/felecs/stage_manager.rb', line 35
+
+def call
+  self.scenes.each(&:call)
+  true
+end
+
+
+ +
+

+ + .clearBoolean + + + + + +

+
+ +

Clears all Scenes that were added to the Stage

+ + +
+
+
+ +

Returns:

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

    true

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+28
+29
+30
+31
+
+
# File 'lib/felecs/stage_manager.rb', line 28
+
+def clear
+  self.scenes.clear
+  true
+end
+
+
+ +
+

+ + .remove(*scenes_to_remove) ⇒ Boolean + + + + + +

+
+ +

Remove any number of Scenes from the Stage

+ + +
+
+
+ +

Returns:

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

    true

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+21
+22
+23
+24
+
+
# File 'lib/felecs/stage_manager.rb', line 21
+
+def remove(*scenes_to_remove)
+  self.scenes -= scenes_to_remove
+  true
+end
+
+
+ +
+ +
+ + + +
+ + \ No newline at end of file diff --git a/docs/FelECS/Systems.html b/docs/FelECS/Systems.html new file mode 100644 index 0000000..867d3a2 --- /dev/null +++ b/docs/FelECS/Systems.html @@ -0,0 +1,1505 @@ + + + + + + + Class: FelECS::Systems + + — Documentation by YARD 0.9.26 + + + + + + + + + + + + + + + + + + + +
+ + +

Class: FelECS::Systems + + + +

+
+ +
+
Inherits:
+
+ Object + +
    +
  • Object
  • + + + +
+ show all + +
+
+ + + + + + + + + + + +
+
Defined in:
+
lib/felecs.rb,
+ lib/felecs/system_manager.rb
+
+
+ +
+ +

Overview

+
+ +

Creates and manages Systems. Systems are the logic of the game and do not contain any data within them. Any systems you create are accessable under the Systems namespace as Constants. You can use array methods directly on this class to access Systems.

+ + +
+
+
+ + +
+ + + +

Instance Attribute Summary collapse

+
    + +
  • + + + #addition_triggers ⇒ Array<Component> + + + + + + + + + readonly + + + + + + + + + +
    +

    Stores references to components or their managers that trigger this component when a component or component from that manager is added to an entity.

    +
    + +
  • + + +
  • + + + #attr_triggers ⇒ Hash<Symbol, Array<Symbol>> + + + + + + + + + readonly + + + + + + + + + +
    +

    Stores references to systems that should be triggered when an attribute from this manager is changed Do not edit this hash as it is managed by FelECS automatically.

    +
    + +
  • + + +
  • + + + #priority ⇒ Object + + + + + + + + + + + + + + + + +
    +

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

    +
    + +
  • + + +
  • + + + #removal_triggers ⇒ Array<Component> + + + + + + + + + readonly + + + + + + + + + +
    +

    Stores references to components or their managers that trigger this component when a component or component from that manager is removed from an entity.

    +
    + +
  • + + +
  • + + + #scenes ⇒ Object + + + + + + + + + + + + + + + + +
    + +
  • + + +
+ + + + + +

+ 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 FelECS::Systems. The name given is what constant the system is assigned to

+ + +
+
+
+ +
+

Examples:

+ + +
FelECS::Systems.new('PassiveHeal', priority: -2) do
+  FelECS::Components::Health.each do |component|
+    component.hp += 5
+  end
+end
+# 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.

    +
    + +
  • + +
+ + +
+ + + + +
+
+
+
+115
+116
+117
+118
+119
+120
+121
+
+
# File 'lib/felecs/system_manager.rb', line 115
+
+def initialize(name, priority: 0, &block)
+  FelECS::Systems.const_set(name, self)
+  FelECS::Systems.update_const_cache
+  @priority = priority
+  @block = block
+  @scenes = []
+end
+
+
+ +
+ +
+

Instance Attribute Details

+ + + +
+

+ + #addition_triggersArray<Component> + + + + + +

+
+ +

Stores references to components or their managers that trigger this component when a component or component from that manager is added to an entity. Do not edit this hash as it is managed by FelECS automatically.

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Array<Component>) + + + +
  • + +
+ +
+ + + + +
+
+
+
+35
+36
+37
+
+
# File 'lib/felecs/system_manager.rb', line 35
+
+def addition_triggers
+  @addition_triggers ||= []
+end
+
+
+ + + +
+

+ + #attr_triggersHash<Symbol, Array<Symbol>> + + + + + +

+
+ +

Stores references to systems that should be triggered when an attribute from this manager is changed Do not edit this hash as it is managed by FelECS automatically.

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Hash<Symbol, Array<Symbol>>) + + + +
  • + +
+ +
+ + + + +
+
+
+
+52
+53
+54
+
+
# File 'lib/felecs/system_manager.rb', line 52
+
+def attr_triggers
+  @attr_triggers ||= {}
+end
+
+
+ + + +
+

+ + #priorityObject + + + + + +

+
+ +

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

+ + +
+
+
+ + +
+ + + + +
+
+
+
+6
+7
+8
+
+
# File 'lib/felecs/system_manager.rb', line 6
+
+def priority
+  @priority
+end
+
+
+ + + +
+

+ + #removal_triggersArray<Component> + + + + + +

+
+ +

Stores references to components or their managers that trigger this component when a component or component from that manager is removed from an entity. Do not edit this hash as it is managed by FelECS automatically.

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Array<Component>) + + + +
  • + +
+ +
+ + + + +
+
+
+
+44
+45
+46
+
+
# File 'lib/felecs/system_manager.rb', line 44
+
+def removal_triggers
+  @removal_triggers ||= []
+end
+
+
+ + + +
+

+ + #scenesObject + + + + + +

+ + + + +
+
+
+
+19
+20
+21
+
+
# File 'lib/felecs/system_manager.rb', line 19
+
+def scenes
+  @scenes ||= []
+end
+
+
+ +
+ + +
+

Class Method Details

+ + +
+

+ + .const_cacheObject + + + + + +

+
+ +

Stores the systems in Components. This is needed because calling `FelECS::Components.constants` will not let you iterate over the value of the constants but will instead give you an array of symbols. This caches the convertion of those symbols to the actual value of the constants

+ + +
+
+
+ + +
+ + + + +
+
+
+
+63
+64
+65
+
+
# File 'lib/felecs/system_manager.rb', line 63
+
+def const_cache
+  @const_cache || update_const_cache
+end
+
+
+ +
+ +
+

Instance Method Details

+ + +
+

+ + #callObject + + + + + +

+
+ +

Manually execute the system a single time

+ + +
+
+
+ + +
+ + + + +
+
+
+
+124
+125
+126
+
+
# File 'lib/felecs/system_manager.rb', line 124
+
+def call
+  @block.call
+end
+
+
+ +
+

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

+
+ +

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

+ + +
+
+
+ +
+

Examples:

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

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+
+
# File 'lib/felecs/system_manager.rb', line 157
+
+def clear_triggers(*trigger_types, component_or_manager: nil)
+  trigger_types = %i[addition_triggers removal_triggers attr_triggers] if trigger_types.empty?
+
+  if trigger_types.include? :attr_triggers
+    if (trigger_types - %i[addition_triggers
+        removal_triggers
+        attr_triggers]).empty?
+
+        if component_or_manager.nil?
+          # remove all attrs
+          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 attr_triggers[component_or_manager].nil?
+            attr_triggers[component_or_manager].each do |attr|
+              component_or_manager.attr_triggers[attr].delete self
+            end
+            attr_triggers[component_or_manager] = []
+          end
+        end
+
+    elsif component_or_manager.nil?
+
+      (trigger_types - %i[addition_triggers removal_triggers attr_triggers]).each do |attr|
+        # remove attr
+        attr_triggers.each do |cmp_or_mgr, _attrs|
+          cmp_or_mgr.attr_triggers[attr].delete self
+        end
+      end
+      attr_triggers.delete(trigger_types - %i[addition_triggers
+                           removal_triggers
+                           attr_triggers])
+    else
+      # remove attr from component_or_manager
+      (trigger_types - %i[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
+      end
+      attr_triggers[component_or_manager] -= trigger_types unless attr_triggers[component_or_manager].nil?
+
+    end
+  end
+
+  (trigger_types & %i[removal_triggers addition_triggers] - [:attr_triggers]).each do |trigger_type|
+    if component_or_manager.nil?
+      # remove all removal triggers
+      send(trigger_type).each do |trigger|
+        trigger.send(trigger_type).delete self
+      end
+      send("#{trigger_type}=", [])
+    else
+      # remove removal trigger relevant to comp/man
+      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.

    +
    + +
  • + +
+ + +
+ + + + +
+
+
+
+130
+131
+132
+
+
# File 'lib/felecs/system_manager.rb', line 130
+
+def redefine(&block)
+  @block = block
+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

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+227
+228
+229
+230
+231
+
+
# File 'lib/felecs/system_manager.rb', line 227
+
+def trigger_when_added(component_or_manager)
+  self.addition_triggers |= [component_or_manager]
+  component_or_manager.addition_triggers |= [self]
+  true
+end
+
+
+ +
+

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

+
+ +

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

+ + +
+
+
+ +

Returns:

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

    true

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+
+
# File 'lib/felecs/system_manager.rb', line 244
+
+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 attr_triggers[component_or_manager].nil?
+    attr_triggers[component_or_manager] = [attr]
+  else
+    attr_triggers[component_or_manager] |= [attr]
+  end
+  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

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+236
+237
+238
+239
+240
+
+
# File 'lib/felecs/system_manager.rb', line 236
+
+def trigger_when_removed(component_or_manager)
+  self.removal_triggers |= [component_or_manager]
+  component_or_manager.removal_triggers |= [self]
+  true
+end
+
+
+ +
+ +
+ + + +
+ + \ No newline at end of file diff --git a/docs/_index.html b/docs/_index.html index f850b17..13029f8 100644 --- a/docs/_index.html +++ b/docs/_index.html @@ -75,6 +75,100 @@ + + + + + + + + + + + + + + + @@ -84,7 +178,7 @@ diff --git a/docs/class_list.html b/docs/class_list.html index 3f4c240..924f66a 100644 --- a/docs/class_list.html +++ b/docs/class_list.html @@ -43,7 +43,7 @@ diff --git a/docs/file.README.html b/docs/file.README.html index fbe3543..cae63f4 100644 --- a/docs/file.README.html +++ b/docs/file.README.html @@ -59,12 +59,12 @@

FelECS

- + -

Maintainability -Test Coverage +

Maintainability +Test Coverage Inline docs -MIT License +MIT License Ko-Fi

Check out the comprehensive documentation here!

@@ -104,42 +104,15 @@
  • Deleting Components
  • Accessing Components' attached Entities
  • - -
  • get the first entity attached.
  • -
  • this will throw a warning if there is more or less then
  • -
  • exactly one entity - -
  • -
  • Code and Logic
  • -
  • do something with these components - * Execution - * Alternative Execution
  • -
  • When this Component is added to an Entity, this System will be called
  • -
  • When this Component is removed from an Entity, this System will be called
  • -
  • When this Component's health attribute is changed, this System will be called
  • -
  • When a Component from this Component Manager is added to an Entity, this System will be called
  • -
  • When a Component from this Component Manager is removed from an Entity, this System will be called
  • -
  • When this Component's health attribute from this Component Manager is changed, this System will be called - * Clearing Alternative Executions
  • -
  • clears ALL triggers with this system
  • -
  • clears ALL triggers with this Component Manager
  • -
  • clear the 'trigger_when_added' for this Component
  • -
  • clear the 'trigger_when_removed' for this Component
  • -
  • clear the 'trigger_when_is_set' for this Component specifically for the health attribute
  • -
  • clears ALL triggers with this Component
  • -
  • clear the 'trigger_when_added' for this Component Manager
  • -
  • clear the 'trigger_when_removed' for this Component Manager
  • -
  • clear the 'trigger_when_is_set' for this Component Manager specifically for the health attribute - * Redefinition
  • -
  • Some new logic or code - -
    • Scenes
        @@ -171,520 +144,413 @@

        What is FelECS?

        -
        FelECS is an ECS framework for developing games in the Ruby language. FelECS has been designed from the ground up with these three ideas in mind:
        +

        FelECS is an ECS framework for developing games in the Ruby language. FelECS has been designed from the ground up with these three ideas in mind:

        -1. **Engine Agnostic:** FelECS has been designed to be rendering engine agnostic as long as the target rendering engine is written in Ruby. This means that this framework can be dropped into existing rendering engines such as [Ruby2D](http://www.ruby2d.com) or [DRGTK](https://dragonruby.org/toolkit/game) with little modifications. -2. **Easily Extensible:** FelECS has been designed such that extensions to its capabilities can be easily added. Extensions such as rendering engine wrappers, premade systems, premade components, etcetera can be easily coded and then distributed as gems. -3. **Principle of (My) Least Astonishment:** I want to develop games using a language and framework I love and makes sense to me, inspired by the [Philosophy of the creator of Ruby](https://en.wikipedia.org/wiki/Ruby_(programming_language)#Philosophy). -
        +
          +
        1. Engine Agnostic: FelECS has been designed to be rendering engine agnostic as long as the target rendering engine is written in Ruby. This means that this framework can be dropped into existing rendering engines such as Ruby2D or DRGTK with little modifications.
        2. +
        3. Easily Extensible: FelECS has been designed such that extensions to its capabilities can be easily added. Extensions such as rendering engine wrappers, premade systems, premade components, etcetera can be easily coded and then distributed as gems.
        4. +
        5. Principle of (My) Least Astonishment: I want to develop games using a language and framework I love and makes sense to me, inspired by the Philosophy of the creator of Ruby.
        6. +

        What is ECS?

        -
        ECS is a software architectural pattern that is used in video game development. Traditionally games were programmed using an object oriented method, while ECS instead attempts to program games using a data oriented method instead.  
        -ECS stands for Entity, Component, and System.
        +

        ECS is a software architectural pattern that is used in video game development. Traditionally games were programmed using an object oriented method, while ECS instead attempts to program games using a data oriented method instead.
        +ECS stands for Entity, Component, and System.

        ---- -
        +

        Components

        -
        This is where the data or information of a given "object" is stored. There is no logic or code here. 
        -
        +

        This is where the data or information of a given "object" is stored. There is no logic or code here.

        Entities

        -
        Entities will contain one or more Components, but contains no logic or data otherwise
        -
        +

        Entities will contain one or more Components, but contains no logic or data otherwise

        Systems

        -
        Systems are where all the logic or code is kept. There is no data stored in here.
        +

        Systems are where all the logic or code is kept. There is no data stored in here.

        ---- +
        -By using this pattern it allows programmers to easily control what an "object" or entity can do and how much data it needs to have. It avoids the issue of inhertance as no inhertance is ever required in this system. If you need a certain entity to have a certain functionality you just add the relevant component to it, and the systems that automatically go over specific components will give your entitiy the desired functionality. +

        By using this pattern it allows programmers to easily control what an "object" or entity can do and how much data it needs to have. It avoids the issue of inhertance as no inhertance is ever required in this system. If you need a certain entity to have a certain functionality you just add the relevant component to it, and the systems that automatically go over specific components will give your entitiy the desired functionality.

        -**"But your framework also has `Scenes`, `Stage`, and `Order`, what is that about?"** +

        "But your framework also has Scenes, Stage, and Order, what is that about?"

        ---- -
        +

        Scenes

        -
        Scenes are simply a collection or subset of Systems. This allows for an easy way to activate and deactivate Systems.
        -
        +

        Scenes are simply a collection or subset of Systems. This allows for an easy way to activate and deactivate Systems.

        Stage

        -
        The Stage is Scenes which are activated. This means any Scenes on the Stage are executed each frame, while the rest of the Systems are not.
        -
        +

        The Stage is Scenes which are activated. This means any Scenes on the Stage are executed each frame, while the rest of the Systems are not.

        Order

        -
        Order is a helper class which can set the priority of Scenes and Systems.
        +

        Order is a helper class which can set the priority of Scenes and Systems.

        ---- -
        +

        Usage

        -
        There are 2 ways of using FelECS. You can either `include` it as a gem in your project if your game engine supports this. The other option is to download the single file export of FelECS and then `require_relative` this file in your project. The single file export takes all the ruby code in the various files and concatenates them into a single file so it is more portable and easy to add.
        +

        There are 2 ways of using FelECS. You can either include it as a gem in your project if your game engine supports this. The other option is to download the single file export of FelECS and then require_relative this file in your project. The single file export takes all the ruby code in the various files and concatenates them into a single file so it is more portable and easy to add.

        -To use the gem method you can do the following: install the gem using `gem install felflame` or using bundler `bundle add felflame` and then require it in your project like so: `require 'felflame'`. +

        To use the gem method you can do the following: install the gem using gem install felecs or using bundler bundle add felecs and then require it in your project like so: require 'felecs'.

        -To use the single file export method you simply download the felflame.rb file from the [releases page on Github](https://github.com/realtradam/FelECS/releases) and add it to your source folder and add a `require relative 'felflame.rb'` line or wherever you have placed the file to use it. -
        +

        To use the single file export method you simply download the felecs.rb file from the releases page on Github and add it to your source folder and add a require relative 'felecs.rb' line or wherever you have placed the file to use it.

        Entities

        Creation

        -
        Entities are essentially "objects" in the game world. To create a new Entity we do the following:
        -
        -```ruby
        -@entity = FelECS::Entities.new
        -```
        -or if we want to add (any number of)components to it when creating it:
        +

        Entities are essentially "objects" in the game world. To create a new Entity we do the following:

        -```ruby +
        @entity = FelECS::Entities.new
         
        -

        @entity = FelECS::Entites.new( - FelECS::Components::Health.new, - @component, - FelECS::Components::EnemyTeam.first - ) - ```

        +

        or if we want to add (any number of)components to it when creating it:

        + +
        @entity = FelECS::Entites.new(
        +  FelECS::Components::Health.new,
        +  @component,
        +  FelECS::Components::EnemyTeam.first
        +)
        +

        Accessing

        -
        Oftentimes you will not be accessing an Entity this way. Later we will shows you a more common way of accessing entities.
        -If you need to you can access Entities using the `Entities` module:
        +

        Oftentimes you will not be accessing an Entity this way. Later we will shows you a more common way of accessing entities. +If you need to you can access Entities using the Entities module:

        -```ruby -@entity = FelECS::Entities[2] -@entity = FelECS::Entities.first -@entity = FelECS::Entities.each # you can iterate over all entities this way. Any valid array method can be used -``` -
        +
        @entity = FelECS::Entities[2]
        +@entity = FelECS::Entities.first
        +@entity = FelECS::Entities.each # you can iterate over all entities this way. Any valid array method can be used
        +

        Adding and Removing Components

        -
        We can still add or remove Components from an Entity after it has been created. Here is how:
        +

        We can still add or remove Components from an Entity after it has been created. Here is how:

        -```ruby -@entity.add @component -@entity.remove @component -``` +
        @entity.add @component
        +@entity.remove @component
         

        Accessing Entities' Attached Components

        -
        This is the most common way of accessing an Entity
        +

        This is the most common way of accessing an Entity

        -When Components are added to Entities, they can be accessed from the Entity. By using a Component Manager as a key we can access an array of all components created from that Component Manager that are attached to an entity: +

        When Components are added to Entities, they can be accessed from the Entity. By using a Component Manager as a key we can access an array of all components created from that Component Manager that are attached to an entity:

        -```ruby -@entity.components[@component_manager] # => [@component1, @component2, @component3] -``` -
        +
        @entity.components[@component_manager] # => [@component1, @component2, @component3]
        +

        Deletion

        -
        To have all Components from an Entity **removed** and the Entity deleted we do the following:
        +

        To have all Components from an Entity removed and the Entity deleted we do the following:

        -NOTE: The components will **not be deleted**. They are simply **removed** from the entity and then the entity is destroyed. You must handle component deletion yourself as for example singleton components need to removed instead of deleted. +

        NOTE: The components will not be deleted. They are simply removed from the entity and then the entity is destroyed. You must handle component deletion yourself as for example singleton components need to removed instead of deleted.

        -```ruby -@entity.delete -``` +
        @entity.delete
         

        Components

        Creating a Component Manager

        -
        Components are where all the data is stored. The data is stored in variables or accessors in each component.
        -These accessors and their defaults are configured when a component manager is created, like so:
        +

        Components are where all the data is stored. The data is stored in variables or accessors in each component. +These accessors and their defaults are configured when a component manager is created, like so:

        -```ruby -@component_manager = FelECS::Components.new('Stats', :armour, hp: 100) -``` +
        @component_manager = FelECS::Components.new('Stats', :armour, hp: 100)
        +
        -In this example we created a component manager called "Stats". +

        In this example we created a component manager called "Stats". The name given to component managers must follow the same rules for naming constants in ruby for a reason you will shortly see. The parameters following are all creating the attributes we can set. We can set any number of parameters we wish, in this example we define two. -The `:armour` parameter is being created without a default, it will equal to `nil` when a new component is created, while `hp` will be equal to 100 when a component is created. -When defining attributes symbols should be used. -

        +The :armour parameter is being created without a default, it will equal to nil when a new component is created, while hp will be equal to 100 when a component is created. +When defining attributes symbols should be used.

        Creating a Component from a Component Manager

        -
        Now that we have a component manager we can make components from it like so:
        +

        Now that we have a component manager we can make components from it like so:

        -```ruby -@component = FelECS::Components::Stats.new -``` +
        @component = FelECS::Components::Stats.new
        +
        -Or we can even override the defaults when creating the component: +

        Or we can even override the defaults when creating the component:

        -```ruby -@component = FelECS::Components::Stats.new(armour: 'steel') -``` +
        @component = FelECS::Components::Stats.new(armour: 'steel')
         

        Accessing

        -
        You can access components using any array method.
        +

        You can access components using any array method.

        -```ruby -@component = FelECS::Components::Stats[2] -@component = FelECS::Components::Stats.first -@component = FelECS::Components::Stats.each # you can use iterators this way -``` -
        +
        @component = FelECS::Components::Stats[2]
        +@component = FelECS::Components::Stats.first
        +@component = FelECS::Components::Stats.each # you can use iterators this way
        +

        Accessing Attributes and Changing Them

        -
        There are a few different ways we can read or change the attributes of a component depending on what our needs are.
        -Here are the ways to edit attrubutes, followed by the ways to read them.
        -```ruby
        -@component.armour = 'Mythril'
        -@component.update_attrs(armour: 'Leather', hp: 95)
        -```
        -```ruby
        -@component.hp # => 95
        -@component.to_h # => {armour: 'Leather', hp: 95}
        -```
        +

        There are a few different ways we can read or change the attributes of a component depending on what our needs are. +Here are the ways to edit attrubutes, followed by the ways to read them.

        + +
        @component.armour = 'Mythril'
        +@component.update_attrs(armour: 'Leather', hp: 95)
         
        +
        @component.hp # => 95
        +@component.to_h # => {armour: 'Leather', hp: 95}
        +
        +

        Deleting Components

        -
        Deleting a Component is the same convention as deleting an Entity. When a Component is deleted referenced to it such as to entities are automatically cleared.
        +

        Deleting a Component is the same convention as deleting an Entity. When a Component is deleted referenced to it such as to entities are automatically cleared.

        -```ruby -@component.delete -``` +
        @component.delete
         

        Accessing Components' attached Entities

        -
        Components also keep track of what Entities are using it. To access this list we do the following:
        +

        Components also keep track of what Entities are using it. To access this list we do the following:

        -```ruby -@component.entities # => [@entity1, @entity2, @entity3] -
        - -

        get the first entity attached.

        - -

        this will throw a warning if there is more or less then

        - -

        exactly one entity

        - -
        @component.entity # => @entity
        -```
        -
        +
        @component.entities # => [@entity1, @entity2, @entity3]
        +
        +# get the first entity attached.
        +# this will throw a warning if there is more or less then
        +# exactly one entity
        +@component.entity # => @entity
        +

        Systems

        Creation

        -
        We can create Systems like so:
        +

        We can create Systems like so:

        -```ruby -FelECS::Systems.new('Render', priority: 2) do +
        FelECS::Systems.new('Render', priority: 2) do
        +  # Code and Logic
        +end
         
        -

        Code and Logic

        - -
        end
        -```
        +

        The name we assign is how we can access the System, like so:

        -The name we assign is how we can access the System, like so: +
        FelECS::Systems::Render
        +
        -```ruby -FelECS::Systems::Render -``` -Priority determines the order Systems should be executed, this is used for `Scenes` and the `Stage`. +

        Priority determines the order Systems should be executed, this is used for Scenes and the Stage. The lower the number, the earlier a given System will be executed. -E.g priority 1 will go first, priority 2 will go second, etcetera. +E.g priority 1 will go first, priority 2 will go second, etcetera.

        -Both Scenes and Systems have a priority. System priority will decide the order it will be called inside of a Scene, which the Scene priority will decide the order it will be called inside of the Stage. +

        Both Scenes and Systems have a priority. System priority will decide the order it will be called inside of a Scene, which the Scene priority will decide the order it will be called inside of the Stage.

        -Often we will want to execute some logic on each Component in a given Component Manager so our code might look like this: +

        Often we will want to execute some logic on each Component in a given Component Manager so our code might look like this:

        -```ruby -FelECS::Systems.new('Render', priority: 2) do -FelECS::Components::Sprites.each do |component| -
        - -

        do something with these components

        - -
        end
        -end
        -```
        +
        FelECS::Systems.new('Render', priority: 2) do
        +  FelECS::Components::Sprites.each do |component|
        +    # do something with these components
        +  end
        +end
         

        Execution

        -
        After we create a System, it won't do anything on its own until we tell it to. Here is how:
        -
        -```ruby
        -FelECS::Systems::Render.call
        -```
        -
        -Sometimes you might want to manually activate a System, but the more common way to have Systems be triggered is to use Scenes and the Stage or the alternative ways of execution.
        -
        - -

        Alternative Execution

        - -
        Sometimes you want a System to automatically trigger when a special even happens. FelECS can keep track of when a Component is added, removed, or when an attribute is changed and then execute Systems linked to these events. Here is how to create these links:
        +

        After we create a System, it won't do anything on its own until we tell it to. Here is how:

        -```ruby +
        FelECS::Systems::Render.call
         
        -

        When this Component is added to an Entity, this System will be called

        - -

        FelECS::Systems::PassiveRegen.trigger_when_added(@component)

        +

        Sometimes you might want to manually activate a System, but the more common way to have Systems be triggered is to use Scenes and the Stage or the alternative ways of execution.

        -

        When this Component is removed from an Entity, this System will be called

        - -

        FelECS::Systems::PassiveRegen.trigger_when_removed(@component)

        +

        Alternative Execution

        -

        When this Component's health attribute is changed, this System will be called

        +

        Sometimes you want a System to automatically trigger when a special even happens. FelECS can keep track of when a Component is added, removed, or when an attribute is changed and then execute Systems linked to these events. Here is how to create these links:

        -

        FelECS::Systems::PassiveRegen.trigger_when_is_set(@component, :health) - ```

        +
        # When this Component is added to an Entity, this System will be called
        +FelECS::Systems::PassiveRegen.trigger_when_added(@component)
         
        -
        If we want these triggers to happen for all Components that belong to specific Component Manager then we can do that instead:
        +# When this Component is removed from an Entity, this System will be called
        +FelECS::Systems::PassiveRegen.trigger_when_removed(@component)
         
        -```ruby
        +# When this Component's health attribute is changed, this System will be called
        +FelECS::Systems::PassiveRegen.trigger_when_is_changed(@component, :health)
         
        -

        When a Component from this Component Manager is added to an Entity, this System will be called

        +

        If we want these triggers to happen for all Components that belong to specific Component Manager then we can do that instead:

        -

        FelECS::Systems::PassiveRegen.trigger_when_added(@component_manager)

        +
        # When a Component from this Component Manager is added to an Entity, this System will be called
        +FelECS::Systems::PassiveRegen.trigger_when_added(@component_manager)
         
        -

        When a Component from this Component Manager is removed from an Entity, this System will be called

        +# When a Component from this Component Manager is removed from an Entity, this System will be called +FelECS::Systems::PassiveRegen.trigger_when_removed(@component_manager) -

        FelECS::Systems::PassiveRegen.trigger_when_removed(@component_manager)

        - -

        When this Component's health attribute from this Component Manager is changed, this System will be called

        - -

        FelECS::Systems::PassiveRegen.trigger_when_is_set(@component_manager, :health) - ```

        - -
        We can create any number of these links between Systems, Components, and Component Manangers as we like, simply call the method again with our other Components and Component Managers
        -
        - -

        Clearing Alternative Executions

        - -
        If we wish to remove these links that we created, we can do that using the follwing function in any of the following ways:
        -
        -```ruby
        +# When this Component's health attribute from this Component Manager is changed, this System will be called
        +FelECS::Systems::PassiveRegen.trigger_when_is_changed(@component_manager, :health)
         
        -

        clears ALL triggers with this system

        - -
        FelECS::Systems::PassiveRegen.clear_triggers
        -
        +

        We can create any number of these links between Systems, Components, and Component Manangers as we like, simply call the method again with our other Components and Component Managers

        -

        clears ALL triggers with this Component Manager

        - -

        FelECS::Systems::PassiveRegen.clear_triggers(@component)

        - -

        clear the 'trigger_when_added' for this Component

        - -

        FelECS::Systems::PassiveRegen.clear_triggers(@component, :added)

        +

        Clearing Alternative Executions

        -

        clear the 'trigger_when_removed' for this Component

        +

        If we wish to remove these links that we created, we can do that using the follwing function in any of the following ways:

        -

        FelECS::Systems::PassiveRegen.clear_triggers(@component, :removed)

        +
        # clears ALL triggers with this system
        +FelECS::Systems::PassiveRegen.clear_triggers
         
        -

        clear the 'trigger_when_is_set' for this Component specifically for the health attribute

        +# clears ALL triggers with this Component Manager +FelECS::Systems::PassiveRegen.clear_triggers(@component) -

        FelECS::Systems::PassiveRegen.clear_triggers(@component, :is_set, :health) - ```

        +# clear the 'trigger_when_added' for this Component +FelECS::Systems::PassiveRegen.clear_triggers(@component, :added) -
        Likewise we can do the same with Component Managers:
        +# clear the 'trigger_when_removed' for this Component
        +FelECS::Systems::PassiveRegen.clear_triggers(@component, :removed)
         
        -```ruby
        +# clear the 'trigger_when_is_changed' for this Component specifically for the health attribute
        +FelECS::Systems::PassiveRegen.clear_triggers(@component, :is_set, :health)
         
        -

        clears ALL triggers with this Component

        - -

        FelECS::Systems::PassiveRegen.clear_triggers(@component_manager)

        +

        Likewise we can do the same with Component Managers:

        -

        clear the 'trigger_when_added' for this Component Manager

        +
        # clears ALL triggers with this Component
        +FelECS::Systems::PassiveRegen.clear_triggers(@component_manager) 
         
        -

        FelECS::Systems::PassiveRegen.clear_triggers(@component_manager, :added)

        +# clear the 'trigger_when_added' for this Component Manager +FelECS::Systems::PassiveRegen.clear_triggers(@component_manager, :added) -

        clear the 'trigger_when_removed' for this Component Manager

        +# clear the 'trigger_when_removed' for this Component Manager +FelECS::Systems::PassiveRegen.clear_triggers(@component_manager, :removed) -

        FelECS::Systems::PassiveRegen.clear_triggers(@component_manager, :removed)

        - -

        clear the 'trigger_when_is_set' for this Component Manager specifically for the health attribute

        - -

        FelECS::Systems::PassiveRegen.clear_triggers(@component_manager, :is_set, :health) - ```

        +# clear the 'trigger_when_is_changed' for this Component Manager specifically for the health attribute +FelECS::Systems::PassiveRegen.clear_triggers(@component_manager, :is_set, :health) +

        Redefinition

        -
        If we wanted to change what code or logic a given System executes, we could do that with:
        +

        If we wanted to change what code or logic a given System executes, we could do that with:

        -```ruby -FelECS::Systems::PassiveRegen.redefine do -
        - -

        Some new logic or code

        - -
        end
        -```
        +
        FelECS::Systems::PassiveRegen.redefine do
        +  # Some new logic or code
        +end
         

        Scenes

        Creation

        -
        Once we have all the core parts of ECS, we will want to organize our Systems. To do this we will use Scenes to group up Systems so they can quickly be enabled or disabled. Note that [Alternative Executions](#alternative-execution) will occur even if they are not part of a Scene. Here is how we make a new Scene:
        +

        Once we have all the core parts of ECS, we will want to organize our Systems. To do this we will use Scenes to group up Systems so they can quickly be enabled or disabled. Note that Alternative Executions will occur even if they are not part of a Scene. Here is how we make a new Scene:

        -```ruby -@scene = FelECS::Scenes.new('ExampleScene', priority: 5) -``` +
        @scene = FelECS::Scenes.new('ExampleScene', priority: 5)
         

        Accessing

        -
        Just like other classes in FelECS, the name we gave the Scene is how we access it:
        +

        Just like other classes in FelECS, the name we gave the Scene is how we access it:

        -```ruby -@scene = FelECS::Scenes::ExampleScene -``` +
        @scene = FelECS::Scenes::ExampleScene
         

        Adding Systems

        -
        Adding Systems is simple. We can add as many as we want. In this example we add 3 different systems:
        +

        Adding Systems is simple. We can add as many as we want. In this example we add 3 different systems:

        -```ruby +
        FelECS::Scenes::ExampleScene.add(
        +  FelECS::Systems::Render,
        +  @system2,
        +  @system3
        +)
         
        -

        FelECS::Scenes::ExampleScene.add( - FelECS::Systems::Render, - @system2, - @system3 - ) - ```

        -

        Removing Systems

        -
        Removing Systems works similarly:
        +

        Removing Systems works similarly:

        -```ruby +
        FelECS::Scenes::ExampleScene.remove(
        +  FelECS::Systems::Render,
        +  @system2,
        +  @system3
        +)
         
        -

        FelECS::Scenes::ExampleScene.remove( - FelECS::Systems::Render, - @system2, - @system3 - ) - ```

        -

        Clearing

        -
        If you want to remove all Systems from a Scene here is how we do it:
        +

        If you want to remove all Systems from a Scene here is how we do it:

        -```ruby -@scene.clear -``` +
        @scene.clear
         

        Execution

        -
        To execute all Systems within a scene once we can just do:
        +

        To execute all Systems within a scene once we can just do:

        -```ruby -@scene.call -``` - -The Scene will make sure that the systems are executed in the correct order based on their given priorities +
        @scene.call
         
        +

        The Scene will make sure that the systems are executed in the correct order based on their given priorities

        +

        Stage

        Adding Scenes

        -
        Finally we have the Stage. There is only a single Stage and we do not have to create it as it exists by default. By adding a Scene to the Stage we are saying that the Scene is 'active'. To add a Scene we do the following:
        +

        Finally we have the Stage. There is only a single Stage and we do not have to create it as it exists by default. By adding a Scene to the Stage we are saying that the Scene is 'active'. To add a Scene we do the following:

        -```ruby -FelECS::Stage.add FelECS::Scene::ExampleScene -``` +
        FelECS::Stage.add FelECS::Scene::ExampleScene
         

        Removing Scenes

        -
        Likewise we can remove Scenes:
        +

        Likewise we can remove Scenes:

        -```ruby -FelECS::Stage.remove FelECS::Scene::ExampleScene -``` +
        FelECS::Stage.remove FelECS::Scene::ExampleScene
         

        Executing

        -
        On each frame of the game generally we will want to execute the Stage once. When the Stage is executed it is progressing your game 1 frame forward. The Stage will call all Scenes you added to it in the order of their priority. Here is how we do it:
        +

        On each frame of the game generally we will want to execute the Stage once. When the Stage is executed it is progressing your game 1 frame forward. The Stage will call all Scenes you added to it in the order of their priority. Here is how we do it:

        -```ruby -FelECS::Stage.call -``` +
        FelECS::Stage.call
         

        Order

        Setting the order

        -
        To set the order you just need to call `FelECS::Order.sort` and pass Scenes or Systems in the parameters in the order you wish for them to execute
        +

        To set the order you just need to call FelECS::Order.sort and pass Scenes or Systems in the parameters in the order you wish for them to execute

        -```ruby +
        FelECS::Order.sort(
        +  @system1,
        +  @system2,
        +  @system3
        +)
         
        -

        FelECS::Order.sort( - @system1, - @system2, - @system3 - ) - ```

        +

        If you want some Scenes or Systems to have the same priority then just pass them as an array:

        -
        If you want some Scenes or Systems to have the same priority then just pass them as an array:
        -
        -```ruby
        +
        FelECS::Order.sort(
        +  @scene1,
        +  [@scene2_1, @scene2_2],
        +  @scene3
        +) 
         
        -

        FelECS::Order.sort( - @scene1, - [@scene2_1, @scene2_2], - @scene3 - ) - ```

        -

        Closing Notes

        -
        There are some methods I haven't gone over in the overview. If you want to see everything and read in more detail check out the [Documentation](https://felflame.tradam.fyi)!
        -
        +

        There are some methods I haven't gone over in the overview. If you want to see everything and read in more detail check out the Documentation!

        Contribution

        -
        Contributors are welcome! I am always looking to impove the capabilities of game development in Ruby. Feel free to open an issue to discuss a proposed changed or fix. To code a change or fix first fork the project. Next write your changes or fixes. Make sure all your changes and fixes are properly documented using Yard(I will not merge if it is not 100% documented) and make sure everything has tests written for it with Rspec(I will also not merge if it does not have 100% test coverage). Once you have your changes made then simply make a pull request.  
        +

        Contributors are welcome! I am always looking to impove the capabilities of game development in Ruby. Feel free to open an issue to discuss a proposed changed or fix. To code a change or fix first fork the project. Next write your changes or fixes. Make sure all your changes and fixes are properly documented using Yard(I will not merge if it is not 100% documented) and make sure everything has tests written for it with Rspec(I will also not merge if it does not have 100% test coverage). Once you have your changes made then simply make a pull request.

        -If you need help writing documentation or tests feel free to ask! +

        If you need help writing documentation or tests feel free to ask!

        -If you want to contribute to development with a thanks you can always [buy me a coffee ;^)](https://ko-fi.com/tradam) -
        +

        If you want to contribute to development with a thanks you can always buy me a coffee ;^)

  • diff --git a/docs/index.html b/docs/index.html index e81dd9d..fedf740 100644 --- a/docs/index.html +++ b/docs/index.html @@ -59,12 +59,12 @@

    FelECS

    - + -

    Maintainability -Test Coverage +

    Maintainability +Test Coverage Inline docs -MIT License +MIT License Ko-Fi

    Check out the comprehensive documentation here!

    @@ -104,42 +104,15 @@
  • Deleting Components
  • Accessing Components' attached Entities
  • - -
  • get the first entity attached.
  • -
  • this will throw a warning if there is more or less then
  • -
  • exactly one entity - -
  • -
  • Code and Logic
  • -
  • do something with these components - * Execution - * Alternative Execution
  • -
  • When this Component is added to an Entity, this System will be called
  • -
  • When this Component is removed from an Entity, this System will be called
  • -
  • When this Component's health attribute is changed, this System will be called
  • -
  • When a Component from this Component Manager is added to an Entity, this System will be called
  • -
  • When a Component from this Component Manager is removed from an Entity, this System will be called
  • -
  • When this Component's health attribute from this Component Manager is changed, this System will be called - * Clearing Alternative Executions
  • -
  • clears ALL triggers with this system
  • -
  • clears ALL triggers with this Component Manager
  • -
  • clear the 'trigger_when_added' for this Component
  • -
  • clear the 'trigger_when_removed' for this Component
  • -
  • clear the 'trigger_when_is_set' for this Component specifically for the health attribute
  • -
  • clears ALL triggers with this Component
  • -
  • clear the 'trigger_when_added' for this Component Manager
  • -
  • clear the 'trigger_when_removed' for this Component Manager
  • -
  • clear the 'trigger_when_is_set' for this Component Manager specifically for the health attribute - * Redefinition
  • -
  • Some new logic or code - -
    • Scenes
        @@ -171,520 +144,413 @@

        What is FelECS?

        -
        FelECS is an ECS framework for developing games in the Ruby language. FelECS has been designed from the ground up with these three ideas in mind:
        +

        FelECS is an ECS framework for developing games in the Ruby language. FelECS has been designed from the ground up with these three ideas in mind:

        -1. **Engine Agnostic:** FelECS has been designed to be rendering engine agnostic as long as the target rendering engine is written in Ruby. This means that this framework can be dropped into existing rendering engines such as [Ruby2D](http://www.ruby2d.com) or [DRGTK](https://dragonruby.org/toolkit/game) with little modifications. -2. **Easily Extensible:** FelECS has been designed such that extensions to its capabilities can be easily added. Extensions such as rendering engine wrappers, premade systems, premade components, etcetera can be easily coded and then distributed as gems. -3. **Principle of (My) Least Astonishment:** I want to develop games using a language and framework I love and makes sense to me, inspired by the [Philosophy of the creator of Ruby](https://en.wikipedia.org/wiki/Ruby_(programming_language)#Philosophy). -
        +
          +
        1. Engine Agnostic: FelECS has been designed to be rendering engine agnostic as long as the target rendering engine is written in Ruby. This means that this framework can be dropped into existing rendering engines such as Ruby2D or DRGTK with little modifications.
        2. +
        3. Easily Extensible: FelECS has been designed such that extensions to its capabilities can be easily added. Extensions such as rendering engine wrappers, premade systems, premade components, etcetera can be easily coded and then distributed as gems.
        4. +
        5. Principle of (My) Least Astonishment: I want to develop games using a language and framework I love and makes sense to me, inspired by the Philosophy of the creator of Ruby.
        6. +

        What is ECS?

        -
        ECS is a software architectural pattern that is used in video game development. Traditionally games were programmed using an object oriented method, while ECS instead attempts to program games using a data oriented method instead.  
        -ECS stands for Entity, Component, and System.
        +

        ECS is a software architectural pattern that is used in video game development. Traditionally games were programmed using an object oriented method, while ECS instead attempts to program games using a data oriented method instead.
        +ECS stands for Entity, Component, and System.

        ---- -
        +

        Components

        -
        This is where the data or information of a given "object" is stored. There is no logic or code here. 
        -
        +

        This is where the data or information of a given "object" is stored. There is no logic or code here.

        Entities

        -
        Entities will contain one or more Components, but contains no logic or data otherwise
        -
        +

        Entities will contain one or more Components, but contains no logic or data otherwise

        Systems

        -
        Systems are where all the logic or code is kept. There is no data stored in here.
        +

        Systems are where all the logic or code is kept. There is no data stored in here.

        ---- +
        -By using this pattern it allows programmers to easily control what an "object" or entity can do and how much data it needs to have. It avoids the issue of inhertance as no inhertance is ever required in this system. If you need a certain entity to have a certain functionality you just add the relevant component to it, and the systems that automatically go over specific components will give your entitiy the desired functionality. +

        By using this pattern it allows programmers to easily control what an "object" or entity can do and how much data it needs to have. It avoids the issue of inhertance as no inhertance is ever required in this system. If you need a certain entity to have a certain functionality you just add the relevant component to it, and the systems that automatically go over specific components will give your entitiy the desired functionality.

        -**"But your framework also has `Scenes`, `Stage`, and `Order`, what is that about?"** +

        "But your framework also has Scenes, Stage, and Order, what is that about?"

        ---- -
        +

        Scenes

        -
        Scenes are simply a collection or subset of Systems. This allows for an easy way to activate and deactivate Systems.
        -
        +

        Scenes are simply a collection or subset of Systems. This allows for an easy way to activate and deactivate Systems.

        Stage

        -
        The Stage is Scenes which are activated. This means any Scenes on the Stage are executed each frame, while the rest of the Systems are not.
        -
        +

        The Stage is Scenes which are activated. This means any Scenes on the Stage are executed each frame, while the rest of the Systems are not.

        Order

        -
        Order is a helper class which can set the priority of Scenes and Systems.
        +

        Order is a helper class which can set the priority of Scenes and Systems.

        ---- -
        +

        Usage

        -
        There are 2 ways of using FelECS. You can either `include` it as a gem in your project if your game engine supports this. The other option is to download the single file export of FelECS and then `require_relative` this file in your project. The single file export takes all the ruby code in the various files and concatenates them into a single file so it is more portable and easy to add.
        +

        There are 2 ways of using FelECS. You can either include it as a gem in your project if your game engine supports this. The other option is to download the single file export of FelECS and then require_relative this file in your project. The single file export takes all the ruby code in the various files and concatenates them into a single file so it is more portable and easy to add.

        -To use the gem method you can do the following: install the gem using `gem install felflame` or using bundler `bundle add felflame` and then require it in your project like so: `require 'felflame'`. +

        To use the gem method you can do the following: install the gem using gem install felecs or using bundler bundle add felecs and then require it in your project like so: require 'felecs'.

        -To use the single file export method you simply download the felflame.rb file from the [releases page on Github](https://github.com/realtradam/FelECS/releases) and add it to your source folder and add a `require relative 'felflame.rb'` line or wherever you have placed the file to use it. -
        +

        To use the single file export method you simply download the felecs.rb file from the releases page on Github and add it to your source folder and add a require relative 'felecs.rb' line or wherever you have placed the file to use it.

        Entities

        Creation

        -
        Entities are essentially "objects" in the game world. To create a new Entity we do the following:
        -
        -```ruby
        -@entity = FelECS::Entities.new
        -```
        -or if we want to add (any number of)components to it when creating it:
        +

        Entities are essentially "objects" in the game world. To create a new Entity we do the following:

        -```ruby +
        @entity = FelECS::Entities.new
         
        -

        @entity = FelECS::Entites.new( - FelECS::Components::Health.new, - @component, - FelECS::Components::EnemyTeam.first - ) - ```

        +

        or if we want to add (any number of)components to it when creating it:

        + +
        @entity = FelECS::Entites.new(
        +  FelECS::Components::Health.new,
        +  @component,
        +  FelECS::Components::EnemyTeam.first
        +)
        +

        Accessing

        -
        Oftentimes you will not be accessing an Entity this way. Later we will shows you a more common way of accessing entities.
        -If you need to you can access Entities using the `Entities` module:
        +

        Oftentimes you will not be accessing an Entity this way. Later we will shows you a more common way of accessing entities. +If you need to you can access Entities using the Entities module:

        -```ruby -@entity = FelECS::Entities[2] -@entity = FelECS::Entities.first -@entity = FelECS::Entities.each # you can iterate over all entities this way. Any valid array method can be used -``` -
        +
        @entity = FelECS::Entities[2]
        +@entity = FelECS::Entities.first
        +@entity = FelECS::Entities.each # you can iterate over all entities this way. Any valid array method can be used
        +

        Adding and Removing Components

        -
        We can still add or remove Components from an Entity after it has been created. Here is how:
        +

        We can still add or remove Components from an Entity after it has been created. Here is how:

        -```ruby -@entity.add @component -@entity.remove @component -``` +
        @entity.add @component
        +@entity.remove @component
         

        Accessing Entities' Attached Components

        -
        This is the most common way of accessing an Entity
        +

        This is the most common way of accessing an Entity

        -When Components are added to Entities, they can be accessed from the Entity. By using a Component Manager as a key we can access an array of all components created from that Component Manager that are attached to an entity: +

        When Components are added to Entities, they can be accessed from the Entity. By using a Component Manager as a key we can access an array of all components created from that Component Manager that are attached to an entity:

        -```ruby -@entity.components[@component_manager] # => [@component1, @component2, @component3] -``` -
        +
        @entity.components[@component_manager] # => [@component1, @component2, @component3]
        +

        Deletion

        -
        To have all Components from an Entity **removed** and the Entity deleted we do the following:
        +

        To have all Components from an Entity removed and the Entity deleted we do the following:

        -NOTE: The components will **not be deleted**. They are simply **removed** from the entity and then the entity is destroyed. You must handle component deletion yourself as for example singleton components need to removed instead of deleted. +

        NOTE: The components will not be deleted. They are simply removed from the entity and then the entity is destroyed. You must handle component deletion yourself as for example singleton components need to removed instead of deleted.

        -```ruby -@entity.delete -``` +
        @entity.delete
         

        Components

        Creating a Component Manager

        -
        Components are where all the data is stored. The data is stored in variables or accessors in each component.
        -These accessors and their defaults are configured when a component manager is created, like so:
        +

        Components are where all the data is stored. The data is stored in variables or accessors in each component. +These accessors and their defaults are configured when a component manager is created, like so:

        -```ruby -@component_manager = FelECS::Components.new('Stats', :armour, hp: 100) -``` +
        @component_manager = FelECS::Components.new('Stats', :armour, hp: 100)
        +
        -In this example we created a component manager called "Stats". +

        In this example we created a component manager called "Stats". The name given to component managers must follow the same rules for naming constants in ruby for a reason you will shortly see. The parameters following are all creating the attributes we can set. We can set any number of parameters we wish, in this example we define two. -The `:armour` parameter is being created without a default, it will equal to `nil` when a new component is created, while `hp` will be equal to 100 when a component is created. -When defining attributes symbols should be used. -

        +The :armour parameter is being created without a default, it will equal to nil when a new component is created, while hp will be equal to 100 when a component is created. +When defining attributes symbols should be used.

        Creating a Component from a Component Manager

        -
        Now that we have a component manager we can make components from it like so:
        +

        Now that we have a component manager we can make components from it like so:

        -```ruby -@component = FelECS::Components::Stats.new -``` +
        @component = FelECS::Components::Stats.new
        +
        -Or we can even override the defaults when creating the component: +

        Or we can even override the defaults when creating the component:

        -```ruby -@component = FelECS::Components::Stats.new(armour: 'steel') -``` +
        @component = FelECS::Components::Stats.new(armour: 'steel')
         

        Accessing

        -
        You can access components using any array method.
        +

        You can access components using any array method.

        -```ruby -@component = FelECS::Components::Stats[2] -@component = FelECS::Components::Stats.first -@component = FelECS::Components::Stats.each # you can use iterators this way -``` -
        +
        @component = FelECS::Components::Stats[2]
        +@component = FelECS::Components::Stats.first
        +@component = FelECS::Components::Stats.each # you can use iterators this way
        +

        Accessing Attributes and Changing Them

        -
        There are a few different ways we can read or change the attributes of a component depending on what our needs are.
        -Here are the ways to edit attrubutes, followed by the ways to read them.
        -```ruby
        -@component.armour = 'Mythril'
        -@component.update_attrs(armour: 'Leather', hp: 95)
        -```
        -```ruby
        -@component.hp # => 95
        -@component.to_h # => {armour: 'Leather', hp: 95}
        -```
        +

        There are a few different ways we can read or change the attributes of a component depending on what our needs are. +Here are the ways to edit attrubutes, followed by the ways to read them.

        + +
        @component.armour = 'Mythril'
        +@component.update_attrs(armour: 'Leather', hp: 95)
         
        +
        @component.hp # => 95
        +@component.to_h # => {armour: 'Leather', hp: 95}
        +
        +

        Deleting Components

        -
        Deleting a Component is the same convention as deleting an Entity. When a Component is deleted referenced to it such as to entities are automatically cleared.
        +

        Deleting a Component is the same convention as deleting an Entity. When a Component is deleted referenced to it such as to entities are automatically cleared.

        -```ruby -@component.delete -``` +
        @component.delete
         

        Accessing Components' attached Entities

        -
        Components also keep track of what Entities are using it. To access this list we do the following:
        +

        Components also keep track of what Entities are using it. To access this list we do the following:

        -```ruby -@component.entities # => [@entity1, @entity2, @entity3] -
        - -

        get the first entity attached.

        - -

        this will throw a warning if there is more or less then

        - -

        exactly one entity

        - -
        @component.entity # => @entity
        -```
        -
        +
        @component.entities # => [@entity1, @entity2, @entity3]
        +
        +# get the first entity attached.
        +# this will throw a warning if there is more or less then
        +# exactly one entity
        +@component.entity # => @entity
        +

        Systems

        Creation

        -
        We can create Systems like so:
        +

        We can create Systems like so:

        -```ruby -FelECS::Systems.new('Render', priority: 2) do +
        FelECS::Systems.new('Render', priority: 2) do
        +  # Code and Logic
        +end
         
        -

        Code and Logic

        - -
        end
        -```
        +

        The name we assign is how we can access the System, like so:

        -The name we assign is how we can access the System, like so: +
        FelECS::Systems::Render
        +
        -```ruby -FelECS::Systems::Render -``` -Priority determines the order Systems should be executed, this is used for `Scenes` and the `Stage`. +

        Priority determines the order Systems should be executed, this is used for Scenes and the Stage. The lower the number, the earlier a given System will be executed. -E.g priority 1 will go first, priority 2 will go second, etcetera. +E.g priority 1 will go first, priority 2 will go second, etcetera.

        -Both Scenes and Systems have a priority. System priority will decide the order it will be called inside of a Scene, which the Scene priority will decide the order it will be called inside of the Stage. +

        Both Scenes and Systems have a priority. System priority will decide the order it will be called inside of a Scene, which the Scene priority will decide the order it will be called inside of the Stage.

        -Often we will want to execute some logic on each Component in a given Component Manager so our code might look like this: +

        Often we will want to execute some logic on each Component in a given Component Manager so our code might look like this:

        -```ruby -FelECS::Systems.new('Render', priority: 2) do -FelECS::Components::Sprites.each do |component| -
        - -

        do something with these components

        - -
        end
        -end
        -```
        +
        FelECS::Systems.new('Render', priority: 2) do
        +  FelECS::Components::Sprites.each do |component|
        +    # do something with these components
        +  end
        +end
         

        Execution

        -
        After we create a System, it won't do anything on its own until we tell it to. Here is how:
        -
        -```ruby
        -FelECS::Systems::Render.call
        -```
        -
        -Sometimes you might want to manually activate a System, but the more common way to have Systems be triggered is to use Scenes and the Stage or the alternative ways of execution.
        -
        - -

        Alternative Execution

        - -
        Sometimes you want a System to automatically trigger when a special even happens. FelECS can keep track of when a Component is added, removed, or when an attribute is changed and then execute Systems linked to these events. Here is how to create these links:
        +

        After we create a System, it won't do anything on its own until we tell it to. Here is how:

        -```ruby +
        FelECS::Systems::Render.call
         
        -

        When this Component is added to an Entity, this System will be called

        - -

        FelECS::Systems::PassiveRegen.trigger_when_added(@component)

        +

        Sometimes you might want to manually activate a System, but the more common way to have Systems be triggered is to use Scenes and the Stage or the alternative ways of execution.

        -

        When this Component is removed from an Entity, this System will be called

        - -

        FelECS::Systems::PassiveRegen.trigger_when_removed(@component)

        +

        Alternative Execution

        -

        When this Component's health attribute is changed, this System will be called

        +

        Sometimes you want a System to automatically trigger when a special even happens. FelECS can keep track of when a Component is added, removed, or when an attribute is changed and then execute Systems linked to these events. Here is how to create these links:

        -

        FelECS::Systems::PassiveRegen.trigger_when_is_set(@component, :health) - ```

        +
        # When this Component is added to an Entity, this System will be called
        +FelECS::Systems::PassiveRegen.trigger_when_added(@component)
         
        -
        If we want these triggers to happen for all Components that belong to specific Component Manager then we can do that instead:
        +# When this Component is removed from an Entity, this System will be called
        +FelECS::Systems::PassiveRegen.trigger_when_removed(@component)
         
        -```ruby
        +# When this Component's health attribute is changed, this System will be called
        +FelECS::Systems::PassiveRegen.trigger_when_is_changed(@component, :health)
         
        -

        When a Component from this Component Manager is added to an Entity, this System will be called

        +

        If we want these triggers to happen for all Components that belong to specific Component Manager then we can do that instead:

        -

        FelECS::Systems::PassiveRegen.trigger_when_added(@component_manager)

        +
        # When a Component from this Component Manager is added to an Entity, this System will be called
        +FelECS::Systems::PassiveRegen.trigger_when_added(@component_manager)
         
        -

        When a Component from this Component Manager is removed from an Entity, this System will be called

        +# When a Component from this Component Manager is removed from an Entity, this System will be called +FelECS::Systems::PassiveRegen.trigger_when_removed(@component_manager) -

        FelECS::Systems::PassiveRegen.trigger_when_removed(@component_manager)

        - -

        When this Component's health attribute from this Component Manager is changed, this System will be called

        - -

        FelECS::Systems::PassiveRegen.trigger_when_is_set(@component_manager, :health) - ```

        - -
        We can create any number of these links between Systems, Components, and Component Manangers as we like, simply call the method again with our other Components and Component Managers
        -
        - -

        Clearing Alternative Executions

        - -
        If we wish to remove these links that we created, we can do that using the follwing function in any of the following ways:
        -
        -```ruby
        +# When this Component's health attribute from this Component Manager is changed, this System will be called
        +FelECS::Systems::PassiveRegen.trigger_when_is_changed(@component_manager, :health)
         
        -

        clears ALL triggers with this system

        - -
        FelECS::Systems::PassiveRegen.clear_triggers
        -
        +

        We can create any number of these links between Systems, Components, and Component Manangers as we like, simply call the method again with our other Components and Component Managers

        -

        clears ALL triggers with this Component Manager

        - -

        FelECS::Systems::PassiveRegen.clear_triggers(@component)

        - -

        clear the 'trigger_when_added' for this Component

        - -

        FelECS::Systems::PassiveRegen.clear_triggers(@component, :added)

        +

        Clearing Alternative Executions

        -

        clear the 'trigger_when_removed' for this Component

        +

        If we wish to remove these links that we created, we can do that using the follwing function in any of the following ways:

        -

        FelECS::Systems::PassiveRegen.clear_triggers(@component, :removed)

        +
        # clears ALL triggers with this system
        +FelECS::Systems::PassiveRegen.clear_triggers
         
        -

        clear the 'trigger_when_is_set' for this Component specifically for the health attribute

        +# clears ALL triggers with this Component Manager +FelECS::Systems::PassiveRegen.clear_triggers(@component) -

        FelECS::Systems::PassiveRegen.clear_triggers(@component, :is_set, :health) - ```

        +# clear the 'trigger_when_added' for this Component +FelECS::Systems::PassiveRegen.clear_triggers(@component, :added) -
        Likewise we can do the same with Component Managers:
        +# clear the 'trigger_when_removed' for this Component
        +FelECS::Systems::PassiveRegen.clear_triggers(@component, :removed)
         
        -```ruby
        +# clear the 'trigger_when_is_changed' for this Component specifically for the health attribute
        +FelECS::Systems::PassiveRegen.clear_triggers(@component, :is_set, :health)
         
        -

        clears ALL triggers with this Component

        - -

        FelECS::Systems::PassiveRegen.clear_triggers(@component_manager)

        +

        Likewise we can do the same with Component Managers:

        -

        clear the 'trigger_when_added' for this Component Manager

        +
        # clears ALL triggers with this Component
        +FelECS::Systems::PassiveRegen.clear_triggers(@component_manager) 
         
        -

        FelECS::Systems::PassiveRegen.clear_triggers(@component_manager, :added)

        +# clear the 'trigger_when_added' for this Component Manager +FelECS::Systems::PassiveRegen.clear_triggers(@component_manager, :added) -

        clear the 'trigger_when_removed' for this Component Manager

        +# clear the 'trigger_when_removed' for this Component Manager +FelECS::Systems::PassiveRegen.clear_triggers(@component_manager, :removed) -

        FelECS::Systems::PassiveRegen.clear_triggers(@component_manager, :removed)

        - -

        clear the 'trigger_when_is_set' for this Component Manager specifically for the health attribute

        - -

        FelECS::Systems::PassiveRegen.clear_triggers(@component_manager, :is_set, :health) - ```

        +# clear the 'trigger_when_is_changed' for this Component Manager specifically for the health attribute +FelECS::Systems::PassiveRegen.clear_triggers(@component_manager, :is_set, :health) +

        Redefinition

        -
        If we wanted to change what code or logic a given System executes, we could do that with:
        +

        If we wanted to change what code or logic a given System executes, we could do that with:

        -```ruby -FelECS::Systems::PassiveRegen.redefine do -
        - -

        Some new logic or code

        - -
        end
        -```
        +
        FelECS::Systems::PassiveRegen.redefine do
        +  # Some new logic or code
        +end
         

        Scenes

        Creation

        -
        Once we have all the core parts of ECS, we will want to organize our Systems. To do this we will use Scenes to group up Systems so they can quickly be enabled or disabled. Note that [Alternative Executions](#alternative-execution) will occur even if they are not part of a Scene. Here is how we make a new Scene:
        +

        Once we have all the core parts of ECS, we will want to organize our Systems. To do this we will use Scenes to group up Systems so they can quickly be enabled or disabled. Note that Alternative Executions will occur even if they are not part of a Scene. Here is how we make a new Scene:

        -```ruby -@scene = FelECS::Scenes.new('ExampleScene', priority: 5) -``` +
        @scene = FelECS::Scenes.new('ExampleScene', priority: 5)
         

        Accessing

        -
        Just like other classes in FelECS, the name we gave the Scene is how we access it:
        +

        Just like other classes in FelECS, the name we gave the Scene is how we access it:

        -```ruby -@scene = FelECS::Scenes::ExampleScene -``` +
        @scene = FelECS::Scenes::ExampleScene
         

        Adding Systems

        -
        Adding Systems is simple. We can add as many as we want. In this example we add 3 different systems:
        +

        Adding Systems is simple. We can add as many as we want. In this example we add 3 different systems:

        -```ruby +
        FelECS::Scenes::ExampleScene.add(
        +  FelECS::Systems::Render,
        +  @system2,
        +  @system3
        +)
         
        -

        FelECS::Scenes::ExampleScene.add( - FelECS::Systems::Render, - @system2, - @system3 - ) - ```

        -

        Removing Systems

        -
        Removing Systems works similarly:
        +

        Removing Systems works similarly:

        -```ruby +
        FelECS::Scenes::ExampleScene.remove(
        +  FelECS::Systems::Render,
        +  @system2,
        +  @system3
        +)
         
        -

        FelECS::Scenes::ExampleScene.remove( - FelECS::Systems::Render, - @system2, - @system3 - ) - ```

        -

        Clearing

        -
        If you want to remove all Systems from a Scene here is how we do it:
        +

        If you want to remove all Systems from a Scene here is how we do it:

        -```ruby -@scene.clear -``` +
        @scene.clear
         

        Execution

        -
        To execute all Systems within a scene once we can just do:
        +

        To execute all Systems within a scene once we can just do:

        -```ruby -@scene.call -``` - -The Scene will make sure that the systems are executed in the correct order based on their given priorities +
        @scene.call
         
        +

        The Scene will make sure that the systems are executed in the correct order based on their given priorities

        +

        Stage

        Adding Scenes

        -
        Finally we have the Stage. There is only a single Stage and we do not have to create it as it exists by default. By adding a Scene to the Stage we are saying that the Scene is 'active'. To add a Scene we do the following:
        +

        Finally we have the Stage. There is only a single Stage and we do not have to create it as it exists by default. By adding a Scene to the Stage we are saying that the Scene is 'active'. To add a Scene we do the following:

        -```ruby -FelECS::Stage.add FelECS::Scene::ExampleScene -``` +
        FelECS::Stage.add FelECS::Scene::ExampleScene
         

        Removing Scenes

        -
        Likewise we can remove Scenes:
        +

        Likewise we can remove Scenes:

        -```ruby -FelECS::Stage.remove FelECS::Scene::ExampleScene -``` +
        FelECS::Stage.remove FelECS::Scene::ExampleScene
         

        Executing

        -
        On each frame of the game generally we will want to execute the Stage once. When the Stage is executed it is progressing your game 1 frame forward. The Stage will call all Scenes you added to it in the order of their priority. Here is how we do it:
        +

        On each frame of the game generally we will want to execute the Stage once. When the Stage is executed it is progressing your game 1 frame forward. The Stage will call all Scenes you added to it in the order of their priority. Here is how we do it:

        -```ruby -FelECS::Stage.call -``` +
        FelECS::Stage.call
         

        Order

        Setting the order

        -
        To set the order you just need to call `FelECS::Order.sort` and pass Scenes or Systems in the parameters in the order you wish for them to execute
        +

        To set the order you just need to call FelECS::Order.sort and pass Scenes or Systems in the parameters in the order you wish for them to execute

        -```ruby +
        FelECS::Order.sort(
        +  @system1,
        +  @system2,
        +  @system3
        +)
         
        -

        FelECS::Order.sort( - @system1, - @system2, - @system3 - ) - ```

        +

        If you want some Scenes or Systems to have the same priority then just pass them as an array:

        -
        If you want some Scenes or Systems to have the same priority then just pass them as an array:
        -
        -```ruby
        +
        FelECS::Order.sort(
        +  @scene1,
        +  [@scene2_1, @scene2_2],
        +  @scene3
        +) 
         
        -

        FelECS::Order.sort( - @scene1, - [@scene2_1, @scene2_2], - @scene3 - ) - ```

        -

        Closing Notes

        -
        There are some methods I haven't gone over in the overview. If you want to see everything and read in more detail check out the [Documentation](https://felflame.tradam.fyi)!
        -
        +

        There are some methods I haven't gone over in the overview. If you want to see everything and read in more detail check out the Documentation!

        Contribution

        -
        Contributors are welcome! I am always looking to impove the capabilities of game development in Ruby. Feel free to open an issue to discuss a proposed changed or fix. To code a change or fix first fork the project. Next write your changes or fixes. Make sure all your changes and fixes are properly documented using Yard(I will not merge if it is not 100% documented) and make sure everything has tests written for it with Rspec(I will also not merge if it does not have 100% test coverage). Once you have your changes made then simply make a pull request.  
        +

        Contributors are welcome! I am always looking to impove the capabilities of game development in Ruby. Feel free to open an issue to discuss a proposed changed or fix. To code a change or fix first fork the project. Next write your changes or fixes. Make sure all your changes and fixes are properly documented using Yard(I will not merge if it is not 100% documented) and make sure everything has tests written for it with Rspec(I will also not merge if it does not have 100% test coverage). Once you have your changes made then simply make a pull request.

        -If you need help writing documentation or tests feel free to ask! +

        If you need help writing documentation or tests feel free to ask!

        -If you want to contribute to development with a thanks you can always [buy me a coffee ;^)](https://ko-fi.com/tradam) -
        +

        If you want to contribute to development with a thanks you can always buy me a coffee ;^)

  • diff --git a/docs/method_list.html b/docs/method_list.html index 48eea1f..9df50e9 100644 --- a/docs/method_list.html +++ b/docs/method_list.html @@ -44,6 +44,374 @@ diff --git a/docs/top-level-namespace.html b/docs/top-level-namespace.html index 6ab8ca4..c9879d9 100644 --- a/docs/top-level-namespace.html +++ b/docs/top-level-namespace.html @@ -78,6 +78,43 @@ +

    Defined Under Namespace

    +

    + + + Modules: FelECS + + + + +

    + + +

    + Constant Summary + collapse +

    + +
    + +
    FECS = +
    +
    + +

    An alias for FelECS

    + + +
    +
    +
    + + +
    +
    +
    FelECS
    + +
    + @@ -90,7 +127,7 @@ diff --git a/lib/felecs/component_manager.rb b/lib/felecs/component_manager.rb index 36916cb..02e4d05 100644 --- a/lib/felecs/component_manager.rb +++ b/lib/felecs/component_manager.rb @@ -36,8 +36,10 @@ module FelECS attrs_with_defaults[attr] = _default.dup FelECS::Components.const_get(component_name).attr_reader attr FelECS::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) + unless value.equal? send(attr) + instance_variable_set("@#{attr}", value) + attr_changed_trigger_systems(attr) + end end end FelECS::Components.const_get(component_name).define_method(:set_defaults) do diff --git a/mrbgem/mrblib/felecs.rb b/mrbgem/mrblib/felecs.rb index acc7f29..56726b2 100644 --- a/mrbgem/mrblib/felecs.rb +++ b/mrbgem/mrblib/felecs.rb @@ -197,8 +197,10 @@ module FelECS attrs_with_defaults[attr] = _default.dup FelECS::Components.const_get(component_name).attr_reader attr FelECS::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) + unless value.equal? send(attr) + instance_variable_set("@#{attr}", value) + attr_changed_trigger_systems(attr) + end end end FelECS::Components.const_get(component_name).define_method(:set_defaults) do -- cgit v1.2.3