From 3ad8d2531329c1696a2bf86db8db9237309281ab Mon Sep 17 00:00:00 2001 From: realtradam Date: Fri, 11 Jun 2021 02:14:57 -0400 Subject: general cleanup --- Gemfile | 14 + Gemfile.lock | 37 + Rakefile | 2 +- component_manager.rb | 42 +- docs/FelFlame.html | 4 +- docs/FelFlame/Components.html | 77 +- docs/FelFlame/Entities.html | 220 +++- docs/FelFlame/Helper.html | 8 +- docs/FelFlame/Helper/ComponentManager.html | 1077 ++++++++++++++++++++ docs/FelFlame/Helper/ComponentManagerTemplate.html | 67 +- docs/FelFlame/Systems.html | 4 +- docs/_index.html | 6 +- docs/class_list.html | 2 +- docs/file.README.html | 510 ++++----- docs/index.html | 510 ++++----- docs/method_list.html | 68 +- docs/top-level-namespace.html | 4 +- entity_manager.rb | 38 +- felflame.rb | 11 +- helpers/01_component.rb | 2 +- 20 files changed, 2012 insertions(+), 691 deletions(-) create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 docs/FelFlame/Helper/ComponentManager.html diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..d7a8e7f --- /dev/null +++ b/Gemfile @@ -0,0 +1,14 @@ +source 'https://rubygems.org' + +ruby '2.7.3' + +group :test do + gem 'minitest-reporters', '~> 1.4', '>= 1.4.3', require: false + gem 'simplecov', '~> 0.21.2', require: false + gem 'simplecov_json_formatter', '~> 0.1.3', require: false +end + +group :docs do + gem 'redcarpet', '~> 3.5', '>= 3.5.1', require: false + gem 'yard', '~> 0.9.26', require: false +end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..c52c5d9 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,37 @@ +GEM + remote: https://rubygems.org/ + specs: + ansi (1.5.0) + builder (3.2.4) + docile (1.4.0) + minitest (5.14.4) + minitest-reporters (1.4.3) + ansi + builder + minitest (>= 5.0) + ruby-progressbar + redcarpet (3.5.1) + ruby-progressbar (1.11.0) + simplecov (0.21.2) + docile (~> 1.1) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-html (0.12.3) + simplecov_json_formatter (0.1.3) + yard (0.9.26) + +PLATFORMS + ruby + +DEPENDENCIES + minitest-reporters (~> 1.4, >= 1.4.3) + redcarpet (~> 3.5, >= 3.5.1) + simplecov (~> 0.21.2) + simplecov_json_formatter (~> 0.1.3) + yard (~> 0.9.26) + +RUBY VERSION + ruby 2.7.3p183 + +BUNDLED WITH + 2.1.4 diff --git a/Rakefile b/Rakefile index 9ca2fdd..ff0dcc8 100644 --- a/Rakefile +++ b/Rakefile @@ -17,7 +17,7 @@ end YARD::Rake::YardocTask.new do |t| t.files = ['component_manager.rb', 'entity_manager.rb', 'felflame.rb'] - t.options = ['--output-dir', './docs'] + t.options = ['--output-dir', './docs', 'yardoc --markup=markdown|textile|rdoc(default)'] t.stats_options = ['--list-undoc'] end diff --git a/component_manager.rb b/component_manager.rb index 16d6300..a7dd423 100644 --- a/component_manager.rb +++ b/component_manager.rb @@ -7,13 +7,21 @@ class FelFlame @component_map = [] class < diff --git a/docs/FelFlame/Components.html b/docs/FelFlame/Components.html index fdb54c0..633c5fb 100644 --- a/docs/FelFlame/Components.html +++ b/docs/FelFlame/Components.html @@ -111,7 +111,7 @@

Creates component managers and allows accessing them them under the Components namespace as Constants

-

To see how component managers are used please look at the Helper::ComponentManagerTemplate documentation.

+

To see how component managers are used please look at the Helper::ComponentManagerTemplate documentation.

TODO: Improve Component overview

@@ -163,7 +163,7 @@
  • - .new(component_name, *attrs, **attrs_with_defaults) ⇒ Object + .new(component_name, *attrs, **attrs_with_defaults) ⇒ ComponentManager @@ -178,7 +178,7 @@
    -

    Creates a new component manager.

    +

    Creates a new component manager.

  • @@ -206,7 +206,7 @@
    -

    Iterate over all existing component managers. You also call other enumerable methods instead of each, such as `each_with_index` or `select`

    +

    Iterate over all existing component managers. You also call other enumerable methods instead of each, such as each_with_index or select

    @@ -233,12 +233,12 @@
     
     
    -32
    -33
    -34
    +41 +42 +43 -
    # File 'component_manager.rb', line 32
    +      
    # File 'component_manager.rb', line 41
     
     def each(&block)
       constants.each(&block)
    @@ -251,7 +251,7 @@
           

    - .new(component_name, *attrs, **attrs_with_defaults) ⇒ Object + .new(component_name, *attrs, **attrs_with_defaults) ⇒ ComponentManager @@ -260,13 +260,25 @@

    -

    Creates a new component manager.

    +

    Creates a new component manager.

    -

    Parameters:

    + +
    +

    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.
    +FelFlame::Component.new('Health', :max, :current, color: 'red')
    + +
    +

    Parameters:

    • @@ -306,7 +318,7 @@ attrs_with_defaults - (Keywords) + (Keyword: DefaultValue) @@ -319,6 +331,19 @@
    +

    Returns:

    +
      + +
    • + + + (ComponentManager) + + + +
    • + +
    @@ -326,26 +351,27 @@
     
     
    -15
    -16
    -17
    -18
    -19
    -20
    -21
    -22
     23
     24
     25
     26
     27
    -28
    +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 @@ -368,9 +395,9 @@ diff --git a/docs/FelFlame/Entities.html b/docs/FelFlame/Entities.html index b6f4bb7..4ba4d6f 100644 --- a/docs/FelFlame/Entities.html +++ b/docs/FelFlame/Entities.html @@ -184,7 +184,7 @@
    -

    Gets an Entity from the given unique ID.

    +

    Gets an Entity from the given unique ID.

    @@ -211,6 +211,30 @@

    Iterates over all entities.

    + + + +
  • + + + .from_json(json_string, **opts) ⇒ Object + + + + + + + + + + + + + +
    +

    Creates a new entity using the data from a JSON string TODO: This function is not yet complete.

    +
    +
  • @@ -265,7 +289,7 @@
    -

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

    +

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

    @@ -298,7 +322,7 @@
  • - #initialize(*components) ⇒ Entities + #initialize(*components) ⇒ Entity @@ -315,7 +339,7 @@
    -

    Creating a new component.

    +

    Creating a new Entity.

  • @@ -403,7 +427,7 @@

    - #initialize(*components) ⇒ Entities + #initialize(*components) ⇒ Entity @@ -412,7 +436,7 @@

    -

    Creating a new component

    +

    Creating a new Entity

    @@ -426,13 +450,13 @@ components - (Component) + (Components)
    -

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

    +

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

    @@ -446,7 +470,6 @@
     
     
    -9
     10
     11
     12
    @@ -457,10 +480,11 @@
     17
     18
     19
    -20
    +20 +21
    -
    # File 'component_manager.rb', line 15
    +      
    # File 'component_manager.rb', line 23
     
     def new(component_name, *attrs, **attrs_with_defaults)
    -  const_set(component_name, Class.new(FelFlame::Helper::ComponentManagerTemplate) {})
    +  const_set(component_name, Class.new(FelFlame::Helper::ComponentManager) {})
       attrs.each do |attr|
         FelFlame::Components.const_get(component_name).attr_accessor attr
       end
    @@ -357,6 +383,7 @@
           instance_variable_set("@#{attr}", default)
         end
       end
    +  FelFlame::Components.const_get(component_name)
     end
    -
    # File 'entity_manager.rb', line 9
    +      
    # File 'entity_manager.rb', line 10
     
     def initialize(*components)
       # Assign new unique ID
    @@ -559,13 +583,22 @@
     
    -

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

    +

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

    -

    Parameters:

    + +
    +

    Examples:

    + + +
    # This gets the Entity with ID 7
    +FelFlame::Entities[7]
    + +
    +

    Parameters:

    • @@ -606,12 +639,12 @@
       
       
      -97
      -98
      -99
      +103 +104 +105
    -
    # File 'entity_manager.rb', line 97
    +      
    # File 'entity_manager.rb', line 103
     
     def [](entity_id)
       data[entity_id]
    @@ -633,7 +666,7 @@
     
    -

    Iterates over all entities. In general when using ECS the use of this method should never be neccassary unless you are doing something very wrong, however I will not stop you. You also call other enumerable methods instead of each, such as `each_with_index` or `select`

    +

    Iterates over all entities. In general when using ECS the use of this method should never be neccassary unless you are doing something very wrong, however I will not stop you. You also call other enumerable methods instead of each, such as each_with_index or select

    @@ -660,12 +693,12 @@
     
     
    -104
    -105
    -106
    +110 +111 +112
    -
    # File 'entity_manager.rb', line 104
    +      
    # File 'entity_manager.rb', line 110
     
     def each(&block)
       data.each(&block)
    @@ -673,6 +706,79 @@
         
    +
    + +
    +

    + + .from_json(json_string, **opts) ⇒ Object + + + + + +

    +
    + +

    Creates a new entity using the data from a JSON string TODO: This function is not yet complete

    + + +
    +
    +
    +

    Parameters:

    +
      + +
    • + + json_string + + + (String) + + + + — +
      +

      A string that was exported originally using the to_json function

      +
      + +
    • + +
    • + + opts + + + (Keywords) + + + + — +
      +

      What values(its ID or the component IDs) should be overwritten TODO: this might change

      +
      + +
    • + +
    + + +
    + + + + +
    +
    +
    +
    +118
    +
    +
    # File 'entity_manager.rb', line 118
    +
    +def from_json(json_string, **opts) end
    +
    @@ -745,9 +851,6 @@
     
     
    -54
    -55
    -56
     57
     58
     59
    @@ -757,19 +860,22 @@
     63
     64
     65
    -66
    +66 +67 +68 +69 -
    # File 'entity_manager.rb', line 54
    +      
    # File 'entity_manager.rb', line 57
     
    -def add component
    +def add(component)
       if components[component.class.to_s.to_sym].nil?
         components[component.class.to_s.to_sym] = [component.id]
    -    component.linked_entities.push id
    +    component.entities.push id
         true
       elsif !components[component.class.to_s.to_sym].include? component.id
         components[component.class.to_s.to_sym].push component.id
    -    component.linked_entities.push id
    +    component.entities.push id
         true
       else
         false
    @@ -792,7 +898,7 @@
     
    -

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

    +

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

    @@ -819,12 +925,12 @@
     
     
    -24
     25
    -26
    +26 +27
    -
    # File 'entity_manager.rb', line 24
    +      
    # File 'entity_manager.rb', line 25
     
     def components
       @components ||= {}
    @@ -878,7 +984,6 @@
           
     
     
    -36
     37
     38
     39
    @@ -890,18 +995,23 @@
     45
     46
     47
    -48
    +48 +49 +50 +51
    -
    # File 'entity_manager.rb', line 36
    +      
    # File 'entity_manager.rb', line 37
     
     def delete
       components.each do |component_manager, component_array|
         component_array.each do |component_id|
           FelFlame.const_get(
             component_manager.to_s.delete_prefix('FelFlame::')
    -      )[component_id].linked_entities.delete(id)
    -    end
    +      )[component_id].entities.delete(id)
    +      # The following is neater, but doesnt work for some reason :/
    +      #Object.const_get(component_manager)[component_id].entities.delete(id)
    +    end
       end
       FelFlame::Entities.data[id] = nil
       @id = nil
    @@ -977,21 +1087,21 @@
           
     
     
    -71
    -72
    -73
     74
     75
     76
     77
    -78
    +78 +79 +80 +81
    -
    # File 'entity_manager.rb', line 71
    +      
    # File 'entity_manager.rb', line 74
     
    -def remove component
    +def remove(component)
       components[component.class.to_s.to_sym].delete component.id
    -  if component.linked_entities.delete id
    +  if component.entities.delete id
         true
       else
         false
    @@ -1041,12 +1151,12 @@
           
     
     
    -30
     31
    -32
    +32 +33
    -
    # File 'entity_manager.rb', line 30
    +      
    # File 'entity_manager.rb', line 31
     
     def to_i
       id
    @@ -1100,14 +1210,12 @@
           
     
     
    -83
    -84
    +86
    -
    # File 'entity_manager.rb', line 83
    +      
    # File 'entity_manager.rb', line 86
     
    -def to_json
    -end
    +def to_json() end
    @@ -1118,9 +1226,9 @@ diff --git a/docs/FelFlame/Helper.html b/docs/FelFlame/Helper.html index 7633b49..ce27679 100644 --- a/docs/FelFlame/Helper.html +++ b/docs/FelFlame/Helper.html @@ -102,7 +102,7 @@

    Overview

    -

    Namespace for helper functions and inheritance classes

    +

    Namespace for helper functions and template classes

    @@ -116,7 +116,7 @@ - Classes: ComponentManagerTemplate + Classes: ComponentManager

    @@ -132,9 +132,9 @@
    diff --git a/docs/FelFlame/Helper/ComponentManager.html b/docs/FelFlame/Helper/ComponentManager.html new file mode 100644 index 0000000..c1d0452 --- /dev/null +++ b/docs/FelFlame/Helper/ComponentManager.html @@ -0,0 +1,1077 @@ + + + + + + + Class: FelFlame::Helper::ComponentManager + + — Documentation by YARD 0.9.26 + + + + + + + + + + + + + + + + + + + +
    + + +

    Class: FelFlame::Helper::ComponentManager + + + +

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

    Overview

    +
    + +

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

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

    Instance Attribute Summary collapse

    + + + + + + +

    + Class Method Summary + collapse +

    + + + +

    + Instance Method Summary + collapse +

    + +
      + +
    • + + + #attrs ⇒ Hash + + + + + + + + + + + + + +
      +

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

      +
      + +
    • + + +
    • + + + #delete ⇒ Boolean + + + + + + + + + + + + + +
      +

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

      +
      + +
    • + + +
    • + + + #entities ⇒ Array + + + + + + + + + + + + + +
      +

      A list of components that are linked to the component.

      +
      + +
    • + + +
    • + + + #to_i ⇒ Integer + + + + + + + + + + + + + +
      +

      An alias for the ID Reader.

      +
      + +
    • + + +
    • + + + #to_json ⇒ String + + + + + + + + + + + + + +
      +

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

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

      Update attribute values using a hash or keywords.

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

    Instance Attribute Details

    + + + +
    +

    + + #idInteger + + + + + +

    +
    + +

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

    + + +
    +
    +
    + +

    Returns:

    +
      + +
    • + + + (Integer) + + + +
    • + +
    + +
    + + + + +
    +
    +
    +
    +53
    +54
    +55
    +
    +
    # File 'component_manager.rb', line 53
    +
    +def id
    +  @id
    +end
    +
    +
    + +
    + + +
    +

    Class Method Details

    + + +
    +

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

    +
    + +

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

    + + +
    +
    +
    + +
    +

    Examples:

    + + +
    # this gets the 'Health' Component with ID 7
    +FelFlame::Components::Health[7]
    + +
    +

    Parameters:

    +
      + +
    • + + component_id + + + (Integer) + + + +
    • + +
    + +

    Returns:

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

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

      +
      + +
    • + +
    + +
    + + + + +
    +
    +
    +
    +69
    +70
    +71
    +
    +
    # File 'component_manager.rb', line 69
    +
    +def [](component_id)
    +  data[component_id]
    +end
    +
    +
    + +
    +

    + + .eachEnumerator + + + + + +

    +
    + +

    Iterates over all components within the component manager

    + + +
    +
    +
    + +

    Returns:

    +
      + +
    • + + + (Enumerator) + + + +
    • + +
    + +
    + + + + +
    +
    +
    +
    +95
    +96
    +97
    +98
    +99
    +
    +
    # File 'component_manager.rb', line 95
    +
    +def each
    +  data.each do |component|
    +    yield component
    +  end
    +end
    +
    +
    + +
    +

    + + .new(**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) + + + +
    • + +
    + +

    Returns:

    +
      + +
    • + + + (Component) + + + +
    • + +
    + +
    + + + + +
    +
    +
    +
    +76
    +77
    +78
    +79
    +80
    +81
    +82
    +83
    +84
    +85
    +86
    +87
    +88
    +89
    +90
    +91
    +
    +
    # File 'component_manager.rb', line 76
    +
    +def new(**attrs)
    +  new_component = super
    +
    +  # Generate ID
    +  new_id = self.data.find_index { |i| i.nil? }
    +  new_id = self.data.size if new_id.nil?
    +  new_component.id = new_id
    +
    +  # Fill params
    +  attrs.each do |key, value|
    +    new_component.send "#{key}=", value
    +  end
    +
    +  # Save Component
    +  data[new_id] = new_component
    +end
    +
    +
    + +
    + +
    +

    Instance Method Details

    + + +
    +

    + + #attrsHash + + + + + +

    +
    + +

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

    + + +
    +
    +
    + +

    Returns:

    +
      + +
    • + + + (Hash) + + + + — +
      +

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

      +
      + +
    • + +
    + +
    + + + + +
    +
    +
    +
    +137
    +138
    +139
    +140
    +141
    +
    +
    # File 'component_manager.rb', line 137
    +
    +def attrs
    +  instance_variables.each_with_object({}) do |key, final|
    +    final[key.to_s.delete_prefix('@').to_sym] = instance_variable_get(key)
    +  end
    +end
    +
    +
    + +
    +

    + + #deleteBoolean + + + + + +

    +
    + +

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

    + + +
    +
    +
    + +

    Returns:

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

      true.

      +
      + +
    • + +
    + +
    + + + + +
    +
    +
    +
    +124
    +125
    +126
    +127
    +128
    +129
    +130
    +131
    +132
    +133
    +134
    +
    +
    # File 'component_manager.rb', line 124
    +
    +def delete
    +  entities.each do |entity_id|
    +    FelFlame::Entities[entity_id].remove self
    +  end
    +  self.class.data[id] = nil
    +  @entities = nil
    +  instance_variables.each do |var|
    +    instance_variable_set(var, nil)
    +  end
    +  true
    +end
    +
    +
    + +
    +

    + + #entitiesArray + + + + + +

    +
    + +

    A list of components that are linked to the component

    + + +
    +
    +
    + +

    Returns:

    +
      + +
    • + + + (Array) + + + +
    • + +
    + +
    + + + + +
    +
    +
    +
    +110
    +111
    +112
    +
    +
    # File 'component_manager.rb', line 110
    +
    +def entities
    +  @entities ||= []
    +end
    +
    +
    + +
    +

    + + #to_iInteger + + + + + +

    +
    + +

    An alias for the ID Reader

    + + +
    +
    +
    + +

    Returns:

    +
      + +
    • + + + (Integer) + + + +
    • + +
    + +
    + + + + +
    +
    +
    +
    +104
    +105
    +106
    +
    +
    # File 'component_manager.rb', line 104
    +
    +def to_i
    +  id
    +end
    +
    +
    + +
    +

    + + #to_jsonString + + + + + +

    +
    + +

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

    + + +
    +
    +
    + +

    Returns:

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

      a JSON formatted String

      +
      + +
    • + +
    + +
    + + + + +
    +
    +
    +
    +146
    +147
    +148
    +
    +
    # File 'component_manager.rb', line 146
    +
    +def to_json
    +  # should return a json or hash of all data in this component
    +end
    +
    +
    + +
    +

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

    +
    + +

    Update attribute values using a hash or keywords.

    + + +
    +
    +
    + +

    Returns:

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

      Hash of updated attributes

      +
      + +
    • + +
    + +
    + + + + +
    +
    +
    +
    +116
    +117
    +118
    +119
    +120
    +
    +
    # File 'component_manager.rb', line 116
    +
    +def update_attrs(**opts)
    +  opts.each do |key, value|
    +    send "#{key}=", value
    +  end
    +end
    +
    +
    + +
    + +
    + + + +
    + + \ No newline at end of file diff --git a/docs/FelFlame/Helper/ComponentManagerTemplate.html b/docs/FelFlame/Helper/ComponentManagerTemplate.html index 801fab1..b97dff0 100644 --- a/docs/FelFlame/Helper/ComponentManagerTemplate.html +++ b/docs/FelFlame/Helper/ComponentManagerTemplate.html @@ -552,14 +552,14 @@
     
     
    -79
     80
     81
     82
    -83
    +83 +84
    -
    # File 'component_manager.rb', line 79
    +      
    # File 'component_manager.rb', line 80
     
     def each
       data.each do |component|
    @@ -589,7 +589,22 @@
       
     
     
    +

    Parameters:

    +
      +
    • + + attrs + + + (Keywords) + + + +
    • + +
    +
    @@ -597,7 +612,6 @@
     
     
    -60
     61
     62
     63
    @@ -612,10 +626,11 @@
     72
     73
     74
    -75
    +75 +76
    -
    # File 'component_manager.rb', line 60
    +      
    # File 'component_manager.rb', line 61
     
     def new(**attrs)
       new_component = super
    @@ -688,14 +703,14 @@
           
     
     
    -121
     122
     123
     124
    -125
    +125 +126
    -
    # File 'component_manager.rb', line 121
    +      
    # File 'component_manager.rb', line 122
     
     def attrs
       instance_variables.each_with_object({}) do |key, final|
    @@ -751,7 +766,6 @@
           
     
     
    -108
     109
     110
     111
    @@ -761,10 +775,11 @@
     115
     116
     117
    -118
    +118 +119
    -
    # File 'component_manager.rb', line 108
    +      
    # File 'component_manager.rb', line 109
     
     def delete
       linked_entities.each do |entity_id|
    @@ -821,12 +836,12 @@
           
     
     
    -94
     95
    -96
    +96 +97
    -
    # File 'component_manager.rb', line 94
    +      
    # File 'component_manager.rb', line 95
     
     def linked_entities
       @linked_entities ||= []
    @@ -875,12 +890,12 @@
           
     
     
    -88
     89
    -90
    +90 +91
    -
    # File 'component_manager.rb', line 88
    +      
    # File 'component_manager.rb', line 89
     
     def to_i
       id
    @@ -934,12 +949,12 @@
           
     
     
    -130
     131
    -132
    +132 +133
    -
    # File 'component_manager.rb', line 130
    +      
    # File 'component_manager.rb', line 131
     
     def to_json
       # should return a json or hash of all data in this component
    @@ -993,14 +1008,14 @@
           
     
     
    -100
     101
     102
     103
    -104
    +104 +105
    -
    # File 'component_manager.rb', line 100
    +      
    # File 'component_manager.rb', line 101
     
     def update_attrs(**opts)
       opts.each do |key, value|
    @@ -1017,9 +1032,9 @@
     
     
           
     
         
    diff --git a/docs/FelFlame/Systems.html b/docs/FelFlame/Systems.html
    index a2bdfc7..a418bfb 100644
    --- a/docs/FelFlame/Systems.html
    +++ b/docs/FelFlame/Systems.html
    @@ -124,9 +124,9 @@
     
     
           
     
         
    diff --git a/docs/_index.html b/docs/_index.html
    index 21765b7..42c4e44 100644
    --- a/docs/_index.html
    +++ b/docs/_index.html
    @@ -81,7 +81,7 @@
               
    • - ComponentManagerTemplate + ComponentManager (FelFlame::Helper) @@ -164,9 +164,9 @@ diff --git a/docs/class_list.html b/docs/class_list.html index 34de204..63d72d5 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 cad9754..a62e2fd 100644 --- a/docs/file.README.html +++ b/docs/file.README.html @@ -57,17 +57,16 @@
      -
      -

      FelFlame

      +

      FelFlame

      -

      Maintainability -Test Coverage -Documentation Coverage

      +

      Maintainability +Test Coverage +Documentation Coverage

      What is this?

      This is a Ruby ECS Framework for developing games. It is still a work in progress in the early stages, is not fit for use, and does not work. -It is designed to be platform agnostic, this means it should be able to work by plugging it into any ruby game engine/library/toolkit with minimal modifications.

      +It is designed to be platform agnostic, this means it should be able to work by plugging it into any ruby game engine/library/toolkit with minimal modifications.

      I wanted a reusable framework so I could quickly and effectively develop games. I also want it to be more complete, as opposed to barebones or boilerplate. I plan to eventually add functionality outside of just ECS such as loading tilesets, a camera system, etc. that are built into the framework to work seamlessly.

      @@ -78,280 +77,285 @@ I plan to eventually add functionality outside of just ECS such as loading tiles

      Systems, Scenes, and the Stage still needs to be implemented

      +

      You can view the Documentation here

      +

      Specification

      Below are the specifications I have imagined for this framework and have been written out. They are subject to change as FelFlame is developed and used.

      Aliases:

      -

      ruby -FF = FelFlame -FF::Ent = FelFlame::Entities -FF::Cmp = FelFlame::Components -FF::Sys = FelFlame::Systems -FF::Sce = FelFlame::Scenes -FF::Stg = FelFlame::Stage - -## Classes:

      - -

      FF::Entities

      -

      ```ruby -FF::Ent.new(@component1, @component2) -@entity = FF::Ent.get(entity_id) -FF::Ent.delete(entity_id) -@entity.id # => unique entity id

      - -

      @entity.add @component -@entity.remove @component -@entity.dump # => [:id, :scenes, :components] -FF::Ent.load @entity_dump -```

      - -

      FF::Components

      -

      ```ruby -FF::Cmp.new(‘Name’, ‘param1’, param2: ‘default’) -FF::Cmp::Name.new(param1: value1) -@component = FF::Cmp::Name.get(component_id) -FF::Cmp::Name.get_by_entity(entity_id) # gets array of components -@component.set(param2: ‘not default’) -@component.param2 = ‘different not default’ -FF::Cmp::Name.detach(entity_id: ent_id, component_id: cmp_id) -FF::Cmp::Name.remove_entity(entity_id) # Removes entity from any components -FF::Cmp::Name.delete_component(component_id) # deletes component and removes from all relevant entities -@component.dump # returns hash of all variables!(and the id) -FF::Cmp::Name.load @component_dump

      - -

      FF::Cmp::Health.added # => returns values for sys to setup -FF::Cmp::Health.removed # => returns values for sys to setup -FF::Cmp::Health.is_set(‘var’) # => returns values for sys to setup -```

      - -

      FF::Systems

      -

      ruby -FF::Sys.new(name: 'Render', position: 5, frame: 1) do - @component.each do - # functionality - end -end -FF::Sys::Render.trigger_when FF::Cmp::Health.added -FF::Sys::Render.trigger_when FF::Cmp::Health.removed -FF::Sys::Render.trigger_when FF::Cmp::Health.is_set('var') -

      - -

      FF::Scenes

      -

      ruby -FF::Scn.new(name: 'Scene1', position: 1) -FF::Scn::Scene1.add @entity -FF::Scn::Scene1.add FF::Sys::Render -FF::Scn::Scene1.entities # => [id_1, id_7, etc] -FF::Scn::Scene1.systems # => [:Render, :Damage, etc] -FF::Scn::Scene1.dump # => [:name, :entities, :systems] -FF::Scn::Scene1.load @scene_dump -

      - -

      FF::Stage

      -

      ruby -FF::Stg.add FF::Scn::Scene1 -FF::Stg.remove FF::Scn::Scene1 -FF::Stg.scene # => [:Scene1, :Scene2, etc] -FF::Stg.dump # => [:Scene1, :Scene2, etc] -FF::Stg.load @stage_dump -FF::Stg.clear -

      + +
      FF = FelFlame
      +FF::Ent = FelFlame::Entities
      +FF::Cmp = FelFlame::Components
      +FF::Sys = FelFlame::Systems
      +FF::Sce = FelFlame::Scenes
      +FF::Stg = FelFlame::Stage
      +
      + +

      Classes:

      + +

      FF::Entities

      + +
      FF::Ent.new(@component1, @component2)
      +@entity = FF::Ent.get(entity_id)
      +FF::Ent.delete(entity_id)
      +@entity.id # => unique entity id
      +
      +@entity.add @component
      +@entity.remove @component
      +@entity.dump # => [:id, :scenes, :components]
      +FF::Ent.load @entity_dump
      +
      + +

      FF::Components

      + +
      FF::Cmp.new('Name', 'param1', param2: 'default')
      +FF::Cmp::Name.new(param1: value1)
      +@component = FF::Cmp::Name.get(component_id)
      +FF::Cmp::Name.get_by_entity(entity_id) # gets array of components
      +@component.set(param2: 'not default')
      +@component.param2 = 'different not default'
      +FF::Cmp::Name.detach(entity_id: ent_id, component_id: cmp_id)
      +FF::Cmp::Name.remove_entity(entity_id) # Removes entity from any components
      +FF::Cmp::Name.delete_component(component_id) # deletes component and removes from all relevant entities
      +@component.dump # returns hash of all variables!(and the id)
      +FF::Cmp::Name.load @component_dump
      +
      +FF::Cmp::Health.added # => returns values for sys to setup
      +FF::Cmp::Health.removed # => returns values for sys to setup
      +FF::Cmp::Health.is_set('var') # => returns values for sys to setup
      +
      + +

      FF::Systems

      + +
      FF::Sys.new(name: 'Render', position: 5, frame: 1) do
      +    @component.each do
      +        # functionality
      +    end
      +end
      +FF::Sys::Render.trigger_when FF::Cmp::Health.added
      +FF::Sys::Render.trigger_when FF::Cmp::Health.removed
      +FF::Sys::Render.trigger_when FF::Cmp::Health.is_set('var')
      +
      + +

      FF::Scenes

      + +
      FF::Scn.new(name: 'Scene1', position: 1)
      +FF::Scn::Scene1.add @entity
      +FF::Scn::Scene1.add FF::Sys::Render
      +FF::Scn::Scene1.entities # => [id_1, id_7, etc]
      +FF::Scn::Scene1.systems # => [:Render, :Damage, etc]
      +FF::Scn::Scene1.dump # => [:name, :entities, :systems]
      +FF::Scn::Scene1.load @scene_dump
      +
      + +

      FF::Stage

      + +
      FF::Stg.add FF::Scn::Scene1
      +FF::Stg.remove FF::Scn::Scene1
      +FF::Stg.scene # => [:Scene1, :Scene2, etc]
      +FF::Stg.dump # => [:Scene1, :Scene2, etc]
      +FF::Stg.load @stage_dump
      +FF::Stg.clear
      +

      FelFlame

      -

      ruby -FF.dump # => all data -FF.load @felflame_dump - -— -blank
      -blank
      -blank
      -— -# Ramblings: -Was my originally written up specs. Rewrote it as what is written above to be more clear. + +

      FF.dump # => all data
      +FF.load @felflame_dump
      +
      + +
      + +

      blank
      +blank

      + +

      blank

      + +

      Ramblings:

      + +

      Was my originally written up specs. Rewrote it as what is written above to be more clear. The below are more verbose but not as helpful for me for implementation. Once the framework is complete I will use a more verbose explanation as below to help users of the framework.

      -
      +

      Creating Entities:

      -

      ```ruby -# Plain: -@my_entity = FF:Ent.new

      - -

      With components:

      -

      FF::Ent.new(FF::Cmp::Position.new(var1: ‘val’, var3: ‘change_default’), - FF::Cmp::Health.new(hp: 20), - FF::Cmp::Poison.new(dps: 3), - FF::Cmp::Poison.new(dps: 2), # This entity has 2 of the same component in it! - FF::Cmp::Selection.get(component_id)) # Components can belong to multiple entities, this component already existed elsewhere! -```

      +
      # Plain:
      +@my_entity = FF:Ent.new
       
      -

      Adding and Removing Components from Entities: -```ruby -@my_entity = FF::Ent.get(entity_id)

      +# With components: +FF::Ent.new(FF::Cmp::Position.new(var1: 'val', var3: 'change_default'), + FF::Cmp::Health.new(hp: 20), + FF::Cmp::Poison.new(dps: 3), + FF::Cmp::Poison.new(dps: 2), # This entity has 2 of the same component in it! + FF::Cmp::Selection.get(component_id)) # Components can belong to multiple entities, this component already existed elsewhere! +
      -

      @my_entity.remove(component_id) -# Remove the specific component with that id

      +

      Adding and Removing Components from Entities:

      -

      @my_entity.remove(FF::Cmp::Poison) -# Removes all components of that type

      +
      @my_entity = FF::Ent.get(entity_id)
       
      -

      @my_entity.add(FF::Cmp::Selection.new) -# Adds a new Component -```

      +@my_entity.remove(component_id) +# Remove the specific component with that id + +@my_entity.remove(FF::Cmp::Poison) +# Removes all components of that type + +@my_entity.add(FF::Cmp::Selection.new) +# Adds a new Component +

      Creating Component Class:

      -

      ruby -# Creating a component 'factory': -FF::Cmp.new('Name', 'var1', 'var2', var3: 'default') # Name, *no_default, **with_default -

      - -

      And then using those components: -ruby -@new_cmp = FF::Cmp::Name.new(var1: 'oke') # var3 will be 'default', var2 will be nil -@new_cmp.var2 = 3 # now var2 is set -@new_cmp.set(var1: 'nope', var3: 'different') # var1 and var3 are now changed! -@new_cmp.to_hash # returns the hash of all variables! -

      - -

      Referencing Components: -ruby -FF::Cmp::Name.get(component_id) # gets component by their unique id -FF::Cmp::Name.get_by_entity(entity_id) # gets component that is attached to the entitry -# will return array of components if there is multiple of same component -# if it returns array, see the `dump` section. Need to add custom method to the array -

      - -

      Creating Systems: -ruby -FF::Sys.new(name: 'Render', position: 5, frame: 1) do -# position is the order in which systems get executed, can be overlapping but then order is unexpected between same positions -# frame is on which frame the system will be called. 0 is never, 1 is on each frame, 2 is every other frame, etc - FF::Cmp::Position.each do - #render your sprite - end -end -

      - -

      Enabling Systems: -```ruby -# By default systems are not enabled. You need to add them to a scene -FF::Scn::Scene1.add FF::Sys::Render

      - -

      They can also be disabled by removing them

      -

      FF::Scn::Scene1.remove FF::Sys::Render -```

      - -

      Custom Hooks: -```ruby -# Systems can be configured to be called whenever a certain component is added, removed or set -FF::Sys::Damage.trigger_when FF::Cmp::Health.added -FF::Sys::Revive.trigger_when FF::Cmp::Health.removed -FF::Sys::Healup.trigger_when FF::Cmp::Health.is_set

      - -

      Systems can also be manually called so you can code custom hooks!

      -

      FF::Sys::Restore.run -```

      - -

      Scenes contain Entities and Systems -```ruby -FF::Scn.new(name: ‘Scene1’, position: 1) -# Multiple scenes could be ran at once, if they do then they will run according -# to their positions as explained above

      - -

      FF::Scn::Scene1.add FF::Entity.get(entity_id) -# You can also just pass the id on its own => FF::Scn::Scene1.add entity_id -FF::Scn::Scene1.add FF::Entity.new

      - -

      FF::Scn::Scene1.add FF::Sys::Render -```

      - -

      To List Systems and Enties -ruby -FF::Scn::Scene1.get_entities # => [id_1, id_7, etc] -FF::Scn::Scene1.get_systems # => [:Render, :Damage, etc] -

      - -

      To run a Scene it must be added to the Stage -ruby -FF::Stg.add FF::Scn::Scene1 -

      - -

      Or remove it: -ruby -FF::Stg.remove FF::Scn::Scene1 -

      - -

      Show all Scenes on the Stage: -ruby -FF::Stg.scenes # => [:Scene1, :Scene2, etc] -

      - -

      Remove all Scenes from the Stage: -ruby -FF::Stg.clear -

      - -

      You can save the current game state: -ruby -@json_save_data = FF.dump -

      - -

      You can also specifically choose what you want to save: -```ruby -@hash_entity = FF::Ent.get(entity_id).dump -# to save all components related to a player

      - -

      @hash_component_single = FF::Cmp::Health.get(component_id).dump -# save all data in the single component(needs to handle arrays of components)

      - -

      @hash_component = FF::Cmp::Health.dump -# save all components of a certain component type

      - -

      @hash_components_all = FF::Cmp.dump -# save all components

      - -

      @hash_scene = FF::Scn::Scene1.dump -# save all entities, components, and activated systems in a given scene -```

      - -

      And then they can be loaded back in: -ruby -FF::Ent.load(@hash_entity) -FF::Cmp::Health.load(@hash_component) -FF::Cmp.load(@hash_component) -FF::Cmp.load(@hash_components_all) -FF::Scn.load(@Hash_scene) -

      - -

      To Do List(old)

      - -
      +
      # Creating a component 'factory':
      +FF::Cmp.new('Name', 'var1', 'var2',  var3: 'default') # Name, *no_default, **with_default
      +
      + +

      And then using those components:

      + +
      @new_cmp = FF::Cmp::Name.new(var1: 'oke') # var3 will be 'default', var2 will be nil
      +@new_cmp.var2 = 3 # now var2 is set
      +@new_cmp.set(var1: 'nope', var3: 'different') # var1 and var3 are now changed!
      +@new_cmp.to_hash # returns the hash of all variables!
      +
      + +

      Referencing Components:

      + +
      FF::Cmp::Name.get(component_id) # gets component by their unique id
      +FF::Cmp::Name.get_by_entity(entity_id) # gets component that is attached to the entitry
      +# will return array of components if there is multiple of same component
      +# if it returns array, see the `dump` section. Need to add custom method to the array
      +
      + +

      Creating Systems:

      + +
      FF::Sys.new(name: 'Render', position: 5, frame: 1) do 
      +# position is the order in which systems get executed, can be overlapping but then order is unexpected between same positions
      +# frame is on which frame the system will be called. 0 is never, 1 is on each frame, 2 is every other frame, etc
      +    FF::Cmp::Position.each do
      +        #render your sprite
      +    end
      +end
      +
      + +

      Enabling Systems:

      + +
      # By default systems are not enabled. You need to add them to a scene
      +FF::Scn::Scene1.add FF::Sys::Render
      +
      +# They can also be disabled by removing them
      +FF::Scn::Scene1.remove FF::Sys::Render
      +
      + +

      Custom Hooks:

      + +
      # Systems can be configured to be called whenever a certain component is added, removed or set
      +FF::Sys::Damage.trigger_when FF::Cmp::Health.added
      +FF::Sys::Revive.trigger_when FF::Cmp::Health.removed
      +FF::Sys::Healup.trigger_when FF::Cmp::Health.is_set
      +
      +# Systems can also be manually called so you can code custom hooks!
      +FF::Sys::Restore.run
      +
      + +

      Scenes contain Entities and Systems

      + +
      FF::Scn.new(name: 'Scene1', position: 1)
      +# Multiple scenes could be ran at once, if they do then they will run according
      +# to their positions as explained above
      +
      +FF::Scn::Scene1.add FF::Entity.get(entity_id)
      +# You can also just pass the id on its own => FF::Scn::Scene1.add entity_id
      +FF::Scn::Scene1.add FF::Entity.new
      +
      +FF::Scn::Scene1.add FF::Sys::Render
      +
      + +

      To List Systems and Enties

      + +
      FF::Scn::Scene1.get_entities # => [id_1, id_7, etc]
      +FF::Scn::Scene1.get_systems  # => [:Render, :Damage, etc]
      +
      + +

      To run a Scene it must be added to the Stage

      + +
      FF::Stg.add FF::Scn::Scene1
      +
      + +

      Or remove it:

      + +
      FF::Stg.remove FF::Scn::Scene1
      +
      + +

      Show all Scenes on the Stage:

      + +
      FF::Stg.scenes # => [:Scene1, :Scene2, etc]
      +
      + +

      Remove all Scenes from the Stage:

      + +
      FF::Stg.clear
      +
      + +

      You can save the current game state:

      + +
      @json_save_data = FF.dump
      +
      + +

      You can also specifically choose what you want to save:

      + +
      @hash_entity = FF::Ent.get(entity_id).dump
      +# to save all components related to a player
      +
      +@hash_component_single = FF::Cmp::Health.get(component_id).dump
      +# save all data in the single component(needs to handle arrays of components)
      +
      +@hash_component = FF::Cmp::Health.dump
      +# save all components of a certain component type
      +
      +@hash_components_all = FF::Cmp.dump
      +# save all components
      +
      +@hash_scene = FF::Scn::Scene1.dump
      +# save all entities, components, and activated systems in a given scene
      +
      + +

      And then they can be loaded back in:

      + +
      FF::Ent.load(@hash_entity)
      +FF::Cmp::Health.load(@hash_component)
      +FF::Cmp.load(@hash_component)
      +FF::Cmp.load(@hash_components_all)
      +FF::Scn.load(@Hash_scene)
      +
      + +

      To Do List(old)

      + +
      + +
        +
      • [ ] Some level of hierarchical support?
      • +
      • [ ] One Component to many entities.
      • +
      • [ ] Multiple of same component to one entity
      • +
      • [ ] State Machine?
      • +
      • [ ] Systems execute code on an event
          -
        • [ ] Some level of hierarchical support?
        • -
        • [ ] One Component to many entities.
        • -
        • [ ] Multiple of same component to one entity
        • -
        • [ ] State Machine?
        • -
        • [ ] Systems execute code on an event -
            -
          • [ ] Adding/removing/setting component is event
          • -
          • [ ] Frame is an event
          • -
          -
        • -
        • [ ] System Execution Order
        • -
        • [ ] Save Dump/Load
        • +
        • [ ] Adding/removing/setting component is event
        • +
        • [ ] Frame is an event
        • +
      • +
      • [ ] System Execution Order
      • +
      • [ ] Save Dump/Load
      diff --git a/docs/index.html b/docs/index.html index c5dd3b9..333991c 100644 --- a/docs/index.html +++ b/docs/index.html @@ -57,17 +57,16 @@
      -
      -

      FelFlame

      +

      FelFlame

      -

      Maintainability -Test Coverage -Documentation Coverage

      +

      Maintainability +Test Coverage +Documentation Coverage

      What is this?

      This is a Ruby ECS Framework for developing games. It is still a work in progress in the early stages, is not fit for use, and does not work. -It is designed to be platform agnostic, this means it should be able to work by plugging it into any ruby game engine/library/toolkit with minimal modifications.

      +It is designed to be platform agnostic, this means it should be able to work by plugging it into any ruby game engine/library/toolkit with minimal modifications.

      I wanted a reusable framework so I could quickly and effectively develop games. I also want it to be more complete, as opposed to barebones or boilerplate. I plan to eventually add functionality outside of just ECS such as loading tilesets, a camera system, etc. that are built into the framework to work seamlessly.

      @@ -78,280 +77,285 @@ I plan to eventually add functionality outside of just ECS such as loading tiles

      Systems, Scenes, and the Stage still needs to be implemented

      +

      You can view the Documentation here

      +

      Specification

      Below are the specifications I have imagined for this framework and have been written out. They are subject to change as FelFlame is developed and used.

      Aliases:

      -

      ruby -FF = FelFlame -FF::Ent = FelFlame::Entities -FF::Cmp = FelFlame::Components -FF::Sys = FelFlame::Systems -FF::Sce = FelFlame::Scenes -FF::Stg = FelFlame::Stage - -## Classes:

      - -

      FF::Entities

      -

      ```ruby -FF::Ent.new(@component1, @component2) -@entity = FF::Ent.get(entity_id) -FF::Ent.delete(entity_id) -@entity.id # => unique entity id

      - -

      @entity.add @component -@entity.remove @component -@entity.dump # => [:id, :scenes, :components] -FF::Ent.load @entity_dump -```

      - -

      FF::Components

      -

      ```ruby -FF::Cmp.new(‘Name’, ‘param1’, param2: ‘default’) -FF::Cmp::Name.new(param1: value1) -@component = FF::Cmp::Name.get(component_id) -FF::Cmp::Name.get_by_entity(entity_id) # gets array of components -@component.set(param2: ‘not default’) -@component.param2 = ‘different not default’ -FF::Cmp::Name.detach(entity_id: ent_id, component_id: cmp_id) -FF::Cmp::Name.remove_entity(entity_id) # Removes entity from any components -FF::Cmp::Name.delete_component(component_id) # deletes component and removes from all relevant entities -@component.dump # returns hash of all variables!(and the id) -FF::Cmp::Name.load @component_dump

      - -

      FF::Cmp::Health.added # => returns values for sys to setup -FF::Cmp::Health.removed # => returns values for sys to setup -FF::Cmp::Health.is_set(‘var’) # => returns values for sys to setup -```

      - -

      FF::Systems

      -

      ruby -FF::Sys.new(name: 'Render', position: 5, frame: 1) do - @component.each do - # functionality - end -end -FF::Sys::Render.trigger_when FF::Cmp::Health.added -FF::Sys::Render.trigger_when FF::Cmp::Health.removed -FF::Sys::Render.trigger_when FF::Cmp::Health.is_set('var') -

      - -

      FF::Scenes

      -

      ruby -FF::Scn.new(name: 'Scene1', position: 1) -FF::Scn::Scene1.add @entity -FF::Scn::Scene1.add FF::Sys::Render -FF::Scn::Scene1.entities # => [id_1, id_7, etc] -FF::Scn::Scene1.systems # => [:Render, :Damage, etc] -FF::Scn::Scene1.dump # => [:name, :entities, :systems] -FF::Scn::Scene1.load @scene_dump -

      - -

      FF::Stage

      -

      ruby -FF::Stg.add FF::Scn::Scene1 -FF::Stg.remove FF::Scn::Scene1 -FF::Stg.scene # => [:Scene1, :Scene2, etc] -FF::Stg.dump # => [:Scene1, :Scene2, etc] -FF::Stg.load @stage_dump -FF::Stg.clear -

      + +
      FF = FelFlame
      +FF::Ent = FelFlame::Entities
      +FF::Cmp = FelFlame::Components
      +FF::Sys = FelFlame::Systems
      +FF::Sce = FelFlame::Scenes
      +FF::Stg = FelFlame::Stage
      +
      + +

      Classes:

      + +

      FF::Entities

      + +
      FF::Ent.new(@component1, @component2)
      +@entity = FF::Ent.get(entity_id)
      +FF::Ent.delete(entity_id)
      +@entity.id # => unique entity id
      +
      +@entity.add @component
      +@entity.remove @component
      +@entity.dump # => [:id, :scenes, :components]
      +FF::Ent.load @entity_dump
      +
      + +

      FF::Components

      + +
      FF::Cmp.new('Name', 'param1', param2: 'default')
      +FF::Cmp::Name.new(param1: value1)
      +@component = FF::Cmp::Name.get(component_id)
      +FF::Cmp::Name.get_by_entity(entity_id) # gets array of components
      +@component.set(param2: 'not default')
      +@component.param2 = 'different not default'
      +FF::Cmp::Name.detach(entity_id: ent_id, component_id: cmp_id)
      +FF::Cmp::Name.remove_entity(entity_id) # Removes entity from any components
      +FF::Cmp::Name.delete_component(component_id) # deletes component and removes from all relevant entities
      +@component.dump # returns hash of all variables!(and the id)
      +FF::Cmp::Name.load @component_dump
      +
      +FF::Cmp::Health.added # => returns values for sys to setup
      +FF::Cmp::Health.removed # => returns values for sys to setup
      +FF::Cmp::Health.is_set('var') # => returns values for sys to setup
      +
      + +

      FF::Systems

      + +
      FF::Sys.new(name: 'Render', position: 5, frame: 1) do
      +    @component.each do
      +        # functionality
      +    end
      +end
      +FF::Sys::Render.trigger_when FF::Cmp::Health.added
      +FF::Sys::Render.trigger_when FF::Cmp::Health.removed
      +FF::Sys::Render.trigger_when FF::Cmp::Health.is_set('var')
      +
      + +

      FF::Scenes

      + +
      FF::Scn.new(name: 'Scene1', position: 1)
      +FF::Scn::Scene1.add @entity
      +FF::Scn::Scene1.add FF::Sys::Render
      +FF::Scn::Scene1.entities # => [id_1, id_7, etc]
      +FF::Scn::Scene1.systems # => [:Render, :Damage, etc]
      +FF::Scn::Scene1.dump # => [:name, :entities, :systems]
      +FF::Scn::Scene1.load @scene_dump
      +
      + +

      FF::Stage

      + +
      FF::Stg.add FF::Scn::Scene1
      +FF::Stg.remove FF::Scn::Scene1
      +FF::Stg.scene # => [:Scene1, :Scene2, etc]
      +FF::Stg.dump # => [:Scene1, :Scene2, etc]
      +FF::Stg.load @stage_dump
      +FF::Stg.clear
      +

      FelFlame

      -

      ruby -FF.dump # => all data -FF.load @felflame_dump - -— -blank
      -blank
      -blank
      -— -# Ramblings: -Was my originally written up specs. Rewrote it as what is written above to be more clear. + +

      FF.dump # => all data
      +FF.load @felflame_dump
      +
      + +
      + +

      blank
      +blank

      + +

      blank

      + +

      Ramblings:

      + +

      Was my originally written up specs. Rewrote it as what is written above to be more clear. The below are more verbose but not as helpful for me for implementation. Once the framework is complete I will use a more verbose explanation as below to help users of the framework.

      -
      +

      Creating Entities:

      -

      ```ruby -# Plain: -@my_entity = FF:Ent.new

      - -

      With components:

      -

      FF::Ent.new(FF::Cmp::Position.new(var1: ‘val’, var3: ‘change_default’), - FF::Cmp::Health.new(hp: 20), - FF::Cmp::Poison.new(dps: 3), - FF::Cmp::Poison.new(dps: 2), # This entity has 2 of the same component in it! - FF::Cmp::Selection.get(component_id)) # Components can belong to multiple entities, this component already existed elsewhere! -```

      +
      # Plain:
      +@my_entity = FF:Ent.new
       
      -

      Adding and Removing Components from Entities: -```ruby -@my_entity = FF::Ent.get(entity_id)

      +# With components: +FF::Ent.new(FF::Cmp::Position.new(var1: 'val', var3: 'change_default'), + FF::Cmp::Health.new(hp: 20), + FF::Cmp::Poison.new(dps: 3), + FF::Cmp::Poison.new(dps: 2), # This entity has 2 of the same component in it! + FF::Cmp::Selection.get(component_id)) # Components can belong to multiple entities, this component already existed elsewhere! +
      -

      @my_entity.remove(component_id) -# Remove the specific component with that id

      +

      Adding and Removing Components from Entities:

      -

      @my_entity.remove(FF::Cmp::Poison) -# Removes all components of that type

      +
      @my_entity = FF::Ent.get(entity_id)
       
      -

      @my_entity.add(FF::Cmp::Selection.new) -# Adds a new Component -```

      +@my_entity.remove(component_id) +# Remove the specific component with that id + +@my_entity.remove(FF::Cmp::Poison) +# Removes all components of that type + +@my_entity.add(FF::Cmp::Selection.new) +# Adds a new Component +

      Creating Component Class:

      -

      ruby -# Creating a component 'factory': -FF::Cmp.new('Name', 'var1', 'var2', var3: 'default') # Name, *no_default, **with_default -

      - -

      And then using those components: -ruby -@new_cmp = FF::Cmp::Name.new(var1: 'oke') # var3 will be 'default', var2 will be nil -@new_cmp.var2 = 3 # now var2 is set -@new_cmp.set(var1: 'nope', var3: 'different') # var1 and var3 are now changed! -@new_cmp.to_hash # returns the hash of all variables! -

      - -

      Referencing Components: -ruby -FF::Cmp::Name.get(component_id) # gets component by their unique id -FF::Cmp::Name.get_by_entity(entity_id) # gets component that is attached to the entitry -# will return array of components if there is multiple of same component -# if it returns array, see the `dump` section. Need to add custom method to the array -

      - -

      Creating Systems: -ruby -FF::Sys.new(name: 'Render', position: 5, frame: 1) do -# position is the order in which systems get executed, can be overlapping but then order is unexpected between same positions -# frame is on which frame the system will be called. 0 is never, 1 is on each frame, 2 is every other frame, etc - FF::Cmp::Position.each do - #render your sprite - end -end -

      - -

      Enabling Systems: -```ruby -# By default systems are not enabled. You need to add them to a scene -FF::Scn::Scene1.add FF::Sys::Render

      - -

      They can also be disabled by removing them

      -

      FF::Scn::Scene1.remove FF::Sys::Render -```

      - -

      Custom Hooks: -```ruby -# Systems can be configured to be called whenever a certain component is added, removed or set -FF::Sys::Damage.trigger_when FF::Cmp::Health.added -FF::Sys::Revive.trigger_when FF::Cmp::Health.removed -FF::Sys::Healup.trigger_when FF::Cmp::Health.is_set

      - -

      Systems can also be manually called so you can code custom hooks!

      -

      FF::Sys::Restore.run -```

      - -

      Scenes contain Entities and Systems -```ruby -FF::Scn.new(name: ‘Scene1’, position: 1) -# Multiple scenes could be ran at once, if they do then they will run according -# to their positions as explained above

      - -

      FF::Scn::Scene1.add FF::Entity.get(entity_id) -# You can also just pass the id on its own => FF::Scn::Scene1.add entity_id -FF::Scn::Scene1.add FF::Entity.new

      - -

      FF::Scn::Scene1.add FF::Sys::Render -```

      - -

      To List Systems and Enties -ruby -FF::Scn::Scene1.get_entities # => [id_1, id_7, etc] -FF::Scn::Scene1.get_systems # => [:Render, :Damage, etc] -

      - -

      To run a Scene it must be added to the Stage -ruby -FF::Stg.add FF::Scn::Scene1 -

      - -

      Or remove it: -ruby -FF::Stg.remove FF::Scn::Scene1 -

      - -

      Show all Scenes on the Stage: -ruby -FF::Stg.scenes # => [:Scene1, :Scene2, etc] -

      - -

      Remove all Scenes from the Stage: -ruby -FF::Stg.clear -

      - -

      You can save the current game state: -ruby -@json_save_data = FF.dump -

      - -

      You can also specifically choose what you want to save: -```ruby -@hash_entity = FF::Ent.get(entity_id).dump -# to save all components related to a player

      - -

      @hash_component_single = FF::Cmp::Health.get(component_id).dump -# save all data in the single component(needs to handle arrays of components)

      - -

      @hash_component = FF::Cmp::Health.dump -# save all components of a certain component type

      - -

      @hash_components_all = FF::Cmp.dump -# save all components

      - -

      @hash_scene = FF::Scn::Scene1.dump -# save all entities, components, and activated systems in a given scene -```

      - -

      And then they can be loaded back in: -ruby -FF::Ent.load(@hash_entity) -FF::Cmp::Health.load(@hash_component) -FF::Cmp.load(@hash_component) -FF::Cmp.load(@hash_components_all) -FF::Scn.load(@Hash_scene) -

      - -

      To Do List(old)

      - -
      +
      # Creating a component 'factory':
      +FF::Cmp.new('Name', 'var1', 'var2',  var3: 'default') # Name, *no_default, **with_default
      +
      + +

      And then using those components:

      + +
      @new_cmp = FF::Cmp::Name.new(var1: 'oke') # var3 will be 'default', var2 will be nil
      +@new_cmp.var2 = 3 # now var2 is set
      +@new_cmp.set(var1: 'nope', var3: 'different') # var1 and var3 are now changed!
      +@new_cmp.to_hash # returns the hash of all variables!
      +
      + +

      Referencing Components:

      + +
      FF::Cmp::Name.get(component_id) # gets component by their unique id
      +FF::Cmp::Name.get_by_entity(entity_id) # gets component that is attached to the entitry
      +# will return array of components if there is multiple of same component
      +# if it returns array, see the `dump` section. Need to add custom method to the array
      +
      + +

      Creating Systems:

      + +
      FF::Sys.new(name: 'Render', position: 5, frame: 1) do 
      +# position is the order in which systems get executed, can be overlapping but then order is unexpected between same positions
      +# frame is on which frame the system will be called. 0 is never, 1 is on each frame, 2 is every other frame, etc
      +    FF::Cmp::Position.each do
      +        #render your sprite
      +    end
      +end
      +
      + +

      Enabling Systems:

      + +
      # By default systems are not enabled. You need to add them to a scene
      +FF::Scn::Scene1.add FF::Sys::Render
      +
      +# They can also be disabled by removing them
      +FF::Scn::Scene1.remove FF::Sys::Render
      +
      + +

      Custom Hooks:

      + +
      # Systems can be configured to be called whenever a certain component is added, removed or set
      +FF::Sys::Damage.trigger_when FF::Cmp::Health.added
      +FF::Sys::Revive.trigger_when FF::Cmp::Health.removed
      +FF::Sys::Healup.trigger_when FF::Cmp::Health.is_set
      +
      +# Systems can also be manually called so you can code custom hooks!
      +FF::Sys::Restore.run
      +
      + +

      Scenes contain Entities and Systems

      + +
      FF::Scn.new(name: 'Scene1', position: 1)
      +# Multiple scenes could be ran at once, if they do then they will run according
      +# to their positions as explained above
      +
      +FF::Scn::Scene1.add FF::Entity.get(entity_id)
      +# You can also just pass the id on its own => FF::Scn::Scene1.add entity_id
      +FF::Scn::Scene1.add FF::Entity.new
      +
      +FF::Scn::Scene1.add FF::Sys::Render
      +
      + +

      To List Systems and Enties

      + +
      FF::Scn::Scene1.get_entities # => [id_1, id_7, etc]
      +FF::Scn::Scene1.get_systems  # => [:Render, :Damage, etc]
      +
      + +

      To run a Scene it must be added to the Stage

      + +
      FF::Stg.add FF::Scn::Scene1
      +
      + +

      Or remove it:

      + +
      FF::Stg.remove FF::Scn::Scene1
      +
      + +

      Show all Scenes on the Stage:

      + +
      FF::Stg.scenes # => [:Scene1, :Scene2, etc]
      +
      + +

      Remove all Scenes from the Stage:

      + +
      FF::Stg.clear
      +
      + +

      You can save the current game state:

      + +
      @json_save_data = FF.dump
      +
      + +

      You can also specifically choose what you want to save:

      + +
      @hash_entity = FF::Ent.get(entity_id).dump
      +# to save all components related to a player
      +
      +@hash_component_single = FF::Cmp::Health.get(component_id).dump
      +# save all data in the single component(needs to handle arrays of components)
      +
      +@hash_component = FF::Cmp::Health.dump
      +# save all components of a certain component type
      +
      +@hash_components_all = FF::Cmp.dump
      +# save all components
      +
      +@hash_scene = FF::Scn::Scene1.dump
      +# save all entities, components, and activated systems in a given scene
      +
      + +

      And then they can be loaded back in:

      + +
      FF::Ent.load(@hash_entity)
      +FF::Cmp::Health.load(@hash_component)
      +FF::Cmp.load(@hash_component)
      +FF::Cmp.load(@hash_components_all)
      +FF::Scn.load(@Hash_scene)
      +
      + +

      To Do List(old)

      + +
      + +
        +
      • [ ] Some level of hierarchical support?
      • +
      • [ ] One Component to many entities.
      • +
      • [ ] Multiple of same component to one entity
      • +
      • [ ] State Machine?
      • +
      • [ ] Systems execute code on an event
          -
        • [ ] Some level of hierarchical support?
        • -
        • [ ] One Component to many entities.
        • -
        • [ ] Multiple of same component to one entity
        • -
        • [ ] State Machine?
        • -
        • [ ] Systems execute code on an event -
            -
          • [ ] Adding/removing/setting component is event
          • -
          • [ ] Frame is an event
          • -
          -
        • -
        • [ ] System Execution Order
        • -
        • [ ] Save Dump/Load
        • +
        • [ ] Adding/removing/setting component is event
        • +
        • [ ] Frame is an event
        • +
      • +
      • [ ] System Execution Order
      • +
      • [ ] Save Dump/Load
      diff --git a/docs/method_list.html b/docs/method_list.html index 10114af..065cba8 100644 --- a/docs/method_list.html +++ b/docs/method_list.html @@ -46,8 +46,8 @@
    • - [] - FelFlame::Helper::ComponentManagerTemplate + [] + FelFlame::Helper::ComponentManager
    • @@ -70,8 +70,8 @@
    • - #attrs - FelFlame::Helper::ComponentManagerTemplate + #attrs + FelFlame::Helper::ComponentManager
    • @@ -86,8 +86,8 @@
    • - #delete - FelFlame::Helper::ComponentManagerTemplate + #delete + FelFlame::Helper::ComponentManager
    • @@ -110,8 +110,8 @@
    • - each - FelFlame::Helper::ComponentManagerTemplate + each + FelFlame::Helper::ComponentManager
    • @@ -126,15 +126,15 @@
    • - #id - FelFlame::Helper::ComponentManagerTemplate + #entities + FelFlame::Helper::ComponentManager
    • - #id + from_json FelFlame::Entities
    • @@ -142,69 +142,77 @@
    • - #initialize - FelFlame::Entities + #id + FelFlame::Helper::ComponentManager
    • - #linked_entities - FelFlame::Helper::ComponentManagerTemplate + #id + FelFlame::Entities
    • - new - FelFlame::Components + #initialize + FelFlame::Entities
    • - new - FelFlame::Helper::ComponentManagerTemplate + new + FelFlame::Components
    • - #remove - FelFlame::Entities + new + FelFlame::Helper::ComponentManager
    • - #to_i - FelFlame::Helper::ComponentManagerTemplate + #remove + FelFlame::Entities
    • - #to_i - FelFlame::Entities + #to_i + FelFlame::Helper::ComponentManager
    • - #to_json - FelFlame::Helper::ComponentManagerTemplate + #to_i + FelFlame::Entities
    • +
      + #to_json + FelFlame::Helper::ComponentManager +
      +
    • + + +
    • #to_json FelFlame::Entities @@ -212,10 +220,10 @@
    • -
    • +
    • - #update_attrs - FelFlame::Helper::ComponentManagerTemplate + #update_attrs + FelFlame::Helper::ComponentManager
    • diff --git a/docs/top-level-namespace.html b/docs/top-level-namespace.html index c924992..b2bd7c9 100644 --- a/docs/top-level-namespace.html +++ b/docs/top-level-namespace.html @@ -127,9 +127,9 @@ diff --git a/entity_manager.rb b/entity_manager.rb index f699c95..5038630 100644 --- a/entity_manager.rb +++ b/entity_manager.rb @@ -4,8 +4,9 @@ class FelFlame # @return [Integer] attr_accessor :id - # Creating a new component - # @param components [Component] Can be any number of components, identical duplicated will be automatically purged however different components from the same component manager are allowed. + # Creating a new Entity + # @param components [Components] Can be any number of components, identical duplicates will be automatically purged however different components from the same component manager are allowed. + # @return [Entity] def initialize(*components) # Assign new unique ID new_id = self.class.data.find_index { |i| i.nil? } @@ -19,7 +20,7 @@ class FelFlame self.class.data[id] = self end - # A hash that uses component manager constant names as keys, and where the values of those keys are arrays that contain the IDs of components attached to this entity. + # A hash that uses component manager constant names as keys, and where the values of those keys are arrays that contain the {FelFlame::Helper::ComponentManager#id IDs} of the components attached to this entity. # @return [Hash] def components @components ||= {} @@ -38,7 +39,9 @@ class FelFlame component_array.each do |component_id| FelFlame.const_get( component_manager.to_s.delete_prefix('FelFlame::') - )[component_id].linked_entities.delete(id) + )[component_id].entities.delete(id) + # The following is neater, but doesnt work for some reason :/ + #Object.const_get(component_manager)[component_id].entities.delete(id) end end FelFlame::Entities.data[id] = nil @@ -51,14 +54,14 @@ class FelFlame # Add a component to the Entity # @param component [Component] A component created from any component manager # @return [Boolean] true if component is added, false if it already is attached - def add component + def add(component) if components[component.class.to_s.to_sym].nil? components[component.class.to_s.to_sym] = [component.id] - component.linked_entities.push id + component.entities.push id true elsif !components[component.class.to_s.to_sym].include? component.id components[component.class.to_s.to_sym].push component.id - component.linked_entities.push id + component.entities.push id true else false @@ -68,9 +71,9 @@ class FelFlame # Remove a component from the Entity # @param component [Component] A component created from any component manager # @return [Boolean] true if component is removed, false if it wasnt attached to component - def remove component + def remove(component) components[component.class.to_s.to_sym].delete component.id - if component.linked_entities.delete id + if component.entities.delete id true else false @@ -80,8 +83,7 @@ class FelFlame # Export all data into a JSON String which can then be saved into a file # TODO: This function is not yet complete # @return [String] A JSON formatted String - def to_json - end + def to_json() end class <