From 8dcacf9e69214f66be09c120ba474b848047cb53 Mon Sep 17 00:00:00 2001 From: realtradam Date: Sat, 12 Jun 2021 00:57:04 -0400 Subject: unit testing and cleanup --- Gemfile | 2 + Gemfile.lock | 23 ++ Rakefile | 11 +- component_manager.rb | 64 +++--- docs/FelFlame.html | 2 +- docs/FelFlame/Components.html | 22 +- docs/FelFlame/Entities.html | 144 ++++++------ docs/FelFlame/Helper.html | 2 +- docs/FelFlame/Helper/ComponentManager.html | 338 ++++++++++++++--------------- docs/FelFlame/Systems.html | 2 +- docs/_index.html | 2 +- docs/file.README.html | 2 +- docs/index.html | 2 +- docs/method_list.html | 12 +- docs/top-level-namespace.html | 2 +- entity_manager.rb | 67 +++--- helpers/00_tileset.rb | 7 + helpers/01_component.rb | 11 +- tests/_test_helper.rb | 35 --- tests/_test_sample.rb | 14 -- tests/component_manager_test.rb | 62 ------ tests/entity_manager_test.rb | 52 ----- tests/felflame_test.rb | 45 ---- tests/scene_manager_test.rb | 15 -- tests/stage_manager_test.rb | 15 -- tests/system_manager_test.rb | 15 -- 26 files changed, 388 insertions(+), 580 deletions(-) delete mode 100644 tests/_test_helper.rb delete mode 100644 tests/_test_sample.rb delete mode 100644 tests/component_manager_test.rb delete mode 100644 tests/entity_manager_test.rb delete mode 100644 tests/felflame_test.rb delete mode 100644 tests/scene_manager_test.rb delete mode 100644 tests/stage_manager_test.rb delete mode 100644 tests/system_manager_test.rb diff --git a/Gemfile b/Gemfile index d7a8e7f..34f0141 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,9 @@ ruby '2.7.3' group :test do gem 'minitest-reporters', '~> 1.4', '>= 1.4.3', require: false + gem 'rspec', '~> 3.10' gem 'simplecov', '~> 0.21.2', require: false + gem 'simplecov-console', '~> 0.9.1' gem 'simplecov_json_formatter', '~> 0.1.3', require: false end diff --git a/Gemfile.lock b/Gemfile.lock index c52c5d9..5339f9e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,6 +3,7 @@ GEM specs: ansi (1.5.0) builder (3.2.4) + diff-lcs (1.4.4) docile (1.4.0) minitest (5.14.4) minitest-reporters (1.4.3) @@ -11,13 +12,33 @@ GEM minitest (>= 5.0) ruby-progressbar redcarpet (3.5.1) + rspec (3.10.0) + rspec-core (~> 3.10.0) + rspec-expectations (~> 3.10.0) + rspec-mocks (~> 3.10.0) + rspec-core (3.10.1) + rspec-support (~> 3.10.0) + rspec-expectations (3.10.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.10.0) + rspec-mocks (3.10.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.10.0) + rspec-support (3.10.2) ruby-progressbar (1.11.0) simplecov (0.21.2) docile (~> 1.1) simplecov-html (~> 0.11) simplecov_json_formatter (~> 0.1) + simplecov-console (0.9.1) + ansi + simplecov + terminal-table simplecov-html (0.12.3) simplecov_json_formatter (0.1.3) + terminal-table (3.0.1) + unicode-display_width (>= 1.1.1, < 3) + unicode-display_width (2.0.0) yard (0.9.26) PLATFORMS @@ -26,7 +47,9 @@ PLATFORMS DEPENDENCIES minitest-reporters (~> 1.4, >= 1.4.3) redcarpet (~> 3.5, >= 3.5.1) + rspec (~> 3.10) simplecov (~> 0.21.2) + simplecov-console (~> 0.9.1) simplecov_json_formatter (~> 0.1.3) yard (~> 0.9.26) diff --git a/Rakefile b/Rakefile index ff0dcc8..f84e93f 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,6 @@ -require 'rake/testtask' +#require 'rake/testtask' +require 'rspec/core/rake_task' require 'yard' require_relative './codeclimate/export-coverage' @@ -21,6 +22,8 @@ YARD::Rake::YardocTask.new do |t| t.stats_options = ['--list-undoc'] end -Rake::TestTask.new do |t| - t.pattern = "tests/**/*_test.rb" -end +#Rake::TestTask.new do |t| +# t.pattern = "tests/**/*_test.rb" +#end + +RSpec::Core::RakeTask.new :spec diff --git a/component_manager.rb b/component_manager.rb index a7dd423..f4402b3 100644 --- a/component_manager.rb +++ b/component_manager.rb @@ -21,6 +21,10 @@ class FelFlame # @param 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 # @return [ComponentManager] def new(component_name, *attrs, **attrs_with_defaults) + if FelFlame::Components.const_defined?(component_name) + raise(NameError.new, "Component Manager '#{component_name}' is already defined") + end + const_set(component_name, Class.new(FelFlame::Helper::ComponentManager) {}) attrs.each do |attr| FelFlame::Components.const_get(component_name).attr_accessor attr @@ -28,7 +32,7 @@ class FelFlame attrs_with_defaults.each do |attr, _default| FelFlame::Components.const_get(component_name).attr_accessor attr end - FelFlame::Components.const_get(component_name).define_method(:initialize) do + FelFlame::Components.const_get(component_name).define_method(:set_defaults) do attrs_with_defaults.each do |attr, default| instance_variable_set("@#{attr}", default) end @@ -52,8 +56,31 @@ class FelFlame # @return [Integer] attr_accessor :id + # Creates a new component and sets the values of the attributes given to it. If an attritbute is not passed then it will remain as the default. + # @param attrs [Keyword: Value] You can pass any number of Keyword-Value pairs + # @return [Component] + def initialize(**attrs) + # Prepare the object + # (this is a function created with metaprogramming + # in FelFlame::Components + set_defaults + + # Generate ID + new_id = self.class.data.find_index { |i| i.nil? } + new_id = self.class.data.size if new_id.nil? + @id = new_id + + # Fill params + attrs.each do |key, value| + send "#{key}=", value + end + + # Save Component + self.class.data[new_id] = self + end + class <] Array of all Components that belong to a given component manager # @!visibility private def data @data ||= [] @@ -70,32 +97,11 @@ class FelFlame data[component_id] end - # Creates a new component and sets the values of the attributes given to it. If an attritbute is not passed then it will remain as the default. - # @param attrs [Keyword: Value] - # @return [Component] - 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 - - # Iterates over all components within the component manager + # Iterates over all components within the component manager. + # Special Enumerable methods like +map+ or +each_with_index+ are not implemented # @return [Enumerator] - def each - data.each do |component| - yield component - end + def each(&block) + data.compact.each(&block) end end @@ -105,8 +111,8 @@ class FelFlame id end - # A list of components that are linked to the component - # @return [Array] + # A list of entity ids that are linked to the component + # @return [Array] def entities @entities ||= [] end diff --git a/docs/FelFlame.html b/docs/FelFlame.html index e9ab145..b49faea 100644 --- a/docs/FelFlame.html +++ b/docs/FelFlame.html @@ -193,7 +193,7 @@ diff --git a/docs/FelFlame/Components.html b/docs/FelFlame/Components.html index 633c5fb..9c6c0c7 100644 --- a/docs/FelFlame/Components.html +++ b/docs/FelFlame/Components.html @@ -233,12 +233,12 @@
 
 
-41
-42
-43
+45 +46 +47 -
# File 'component_manager.rb', line 41
+      
# File 'component_manager.rb', line 45
 
 def each(&block)
   constants.each(&block)
@@ -365,12 +365,20 @@
 34
 35
 36
-37
+37 +38 +39 +40 +41
# File 'component_manager.rb', line 23
 
 def new(component_name, *attrs, **attrs_with_defaults)
+  if FelFlame::Components.const_defined?(component_name)
+    raise(NameError.new, "Component Manager '#{component_name}' is already defined")
+  end
+
   const_set(component_name, Class.new(FelFlame::Helper::ComponentManager) {})
   attrs.each do |attr|
     FelFlame::Components.const_get(component_name).attr_accessor attr
@@ -378,7 +386,7 @@
   attrs_with_defaults.each do |attr, _default|
     FelFlame::Components.const_get(component_name).attr_accessor attr
   end
-  FelFlame::Components.const_get(component_name).define_method(:initialize) do
+  FelFlame::Components.const_get(component_name).define_method(:set_defaults) do
     attrs_with_defaults.each do |attr, default|
       instance_variable_set("@#{attr}", default)
     end
@@ -395,7 +403,7 @@
 
 
       
diff --git a/docs/FelFlame/Entities.html b/docs/FelFlame/Entities.html
index 4ba4d6f..38898a8 100644
--- a/docs/FelFlame/Entities.html
+++ b/docs/FelFlame/Entities.html
@@ -250,7 +250,7 @@
         
  • - #add(component) ⇒ Boolean + #add(*components_to_add) ⇒ Boolean @@ -265,7 +265,7 @@
    -

    Returns true when added, or false if it already belongs to the Entity Add a component to the Entity.

    +

    Add any number components to the Entity.

  • @@ -348,7 +348,7 @@
  • - #remove(component) ⇒ Boolean + #remove(*components_to_remove) ⇒ Boolean @@ -481,21 +481,25 @@ 18 19 20 -21
  • +21 +22 +23
    # File 'entity_manager.rb', line 10
     
     def initialize(*components)
       # Assign new unique ID
    -  new_id = self.class.data.find_index { |i| i.nil? }
    +  new_id = self.class.data.find_index(&:nil?)
       new_id = self.class.data.size if new_id.nil?
       self.id = new_id
     
       # Add each component
    -  components.uniq.each do |component|
    -    add component
    -  end
    +  #components.uniq.each do |component|
    +  #  add component
    +  #end
    +  add(*components)
    +
       self.class.data[id] = self
     end
    @@ -639,12 +643,12 @@
     
     
    -103
     104
    -105
    +105 +106 -
    # File 'entity_manager.rb', line 103
    +      
    # File 'entity_manager.rb', line 104
     
     def [](entity_id)
       data[entity_id]
    @@ -693,12 +697,12 @@
           
     
     
    -110
     111
    -112
    +112 +113
    -
    # File 'entity_manager.rb', line 110
    +      
    # File 'entity_manager.rb', line 111
     
     def each(&block)
       data.each(&block)
    @@ -770,10 +774,10 @@
           
     
     
    -118
    +119
    -
    # File 'entity_manager.rb', line 118
    +      
    # File 'entity_manager.rb', line 119
     
     def from_json(json_string, **opts) end
    @@ -790,7 +794,7 @@

    - #add(component) ⇒ Boolean + #add(*components_to_add) ⇒ Boolean @@ -799,7 +803,7 @@

    -

    Returns true when added, or false if it already belongs to the Entity Add a component to the Entity

    +

    Add any number components to the Entity.

    @@ -819,7 +823,7 @@ —
    -

    A component created from any component manager

    +

    Any number of components created from any component manager

    @@ -838,7 +842,7 @@ —
    -

    true if component is added, false if it already is attached

    +

    true if component is added, false if it already is attached or no components given

    @@ -851,6 +855,9 @@
     
     
    +54
    +55
    +56
     57
     58
     59
    @@ -862,24 +869,25 @@
     65
     66
     67
    -68
    -69
    +68
    -
    # File 'entity_manager.rb', line 57
    -
    -def add(component)
    -  if components[component.class.to_s.to_sym].nil?
    -    components[component.class.to_s.to_sym] = [component.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.entities.push id
    -    true
    -  else
    -    false
    +      
    # File 'entity_manager.rb', line 54
    +
    +def add(*components_to_add)
    +  added = false
    +  components_to_add.each do |component|
    +    if components[component.class].nil?
    +      components[component.class] = [component.id]
    +      component.entities.push id
    +      added =true
    +    elsif !components[component.class].include? component.id
    +      components[component.class].push component.id
    +      component.entities.push id
    +      added = true
    +    end
       end
    +  added
     end
    @@ -925,12 +933,12 @@
     
     
    -25
    -26
    -27
    +27 +28 +29
    -
    # File 'entity_manager.rb', line 25
    +      
    # File 'entity_manager.rb', line 27
     
     def components
       @components ||= {}
    @@ -984,8 +992,6 @@
           
     
     
    -37
    -38
     39
     40
     41
    @@ -996,22 +1002,16 @@
     46
     47
     48
    -49
    -50
    -51
    +49
    -
    # File 'entity_manager.rb', line 37
    +      
    # File 'entity_manager.rb', line 39
     
     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].entities.delete(id)
    -      # The following is neater, but doesnt work for some reason :/
    -      #Object.const_get(component_manager)[component_id].entities.delete(id)
    -    end
    +      component_manager[component_id].entities.delete(id)
    +    end
       end
       FelFlame::Entities.data[id] = nil
       @id = nil
    @@ -1026,7 +1026,7 @@
           

    - #remove(component) ⇒ Boolean + #remove(*components_to_remove) ⇒ Boolean @@ -1046,7 +1046,7 @@
  • - component + component_to_remove (Component) @@ -1074,7 +1074,7 @@ —
    -

    true if component is removed, false if it wasnt attached to component

    +

    true if at least one component is removed, false if none of them were attached to the component

  • @@ -1087,6 +1087,7 @@
     
     
    +73
     74
     75
     76
    @@ -1094,18 +1095,21 @@
     78
     79
     80
    -81
    +81 +82

    -
    # File 'entity_manager.rb', line 74
    -
    -def remove(component)
    -  components[component.class.to_s.to_sym].delete component.id
    -  if component.entities.delete id
    -    true
    -  else
    -    false
    +      
    # File 'entity_manager.rb', line 73
    +
    +def remove(*components_to_remove)
    +  removed = false
    +  components_to_remove.each do |component|
    +    components[component.class].delete component.id
    +    if component.entities.delete id
    +      removed = true
    +    end
       end
    +  removed
     end
    @@ -1151,12 +1155,12 @@
     
     
    -31
    -32
    -33
    +33 +34 +35
    -
    # File 'entity_manager.rb', line 31
    +      
    # File 'entity_manager.rb', line 33
     
     def to_i
       id
    @@ -1210,10 +1214,10 @@
           
     
     
    -86
    +87
    -
    # File 'entity_manager.rb', line 86
    +      
    # File 'entity_manager.rb', line 87
     
     def to_json() end
    @@ -1226,7 +1230,7 @@ diff --git a/docs/FelFlame/Helper.html b/docs/FelFlame/Helper.html index ce27679..2dbcd7a 100644 --- a/docs/FelFlame/Helper.html +++ b/docs/FelFlame/Helper.html @@ -132,7 +132,7 @@ diff --git a/docs/FelFlame/Helper/ComponentManager.html b/docs/FelFlame/Helper/ComponentManager.html index c1d0452..acb1cf8 100644 --- a/docs/FelFlame/Helper/ComponentManager.html +++ b/docs/FelFlame/Helper/ComponentManager.html @@ -184,7 +184,7 @@
  • - .each ⇒ Enumerator + .each(&block) ⇒ Enumerator @@ -205,10 +205,19 @@
  • + + +

    + Instance Method Summary + collapse +

    + +
      +
    • - .new(**attrs) ⇒ Component + #attrs ⇒ Hash @@ -223,25 +232,16 @@
      -

      Creates a new component and sets the values of the attributes given to it.

      +

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

    • -
    - -

    - Instance Method Summary - collapse -

    - -
      -
    • - #attrs ⇒ Hash + #delete ⇒ Boolean @@ -256,7 +256,7 @@
      -

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

      +

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

    • @@ -265,7 +265,7 @@
    • - #delete ⇒ Boolean + #entities ⇒ Array<Integer> @@ -280,7 +280,7 @@
      -

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

      +

      A list of entity ids that are linked to the component.

    • @@ -289,13 +289,15 @@
    • - #entities ⇒ Array + #initialize(**attrs) ⇒ Component + constructor + @@ -304,7 +306,7 @@
      -

      A list of components that are linked to the component.

      +

      Creates a new component and sets the values of the attributes given to it.

    • @@ -385,6 +387,103 @@
    +
    +

    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

      +
      + +
    • + +
    + + +
    + + + + +
    +
    +
    +
    +62
    +63
    +64
    +65
    +66
    +67
    +68
    +69
    +70
    +71
    +72
    +73
    +74
    +75
    +76
    +77
    +78
    +79
    +80
    +
    +
    # File 'component_manager.rb', line 62
    +
    +def initialize(**attrs)
    +  # Prepare the object
    +  # (this is a function created with metaprogramming
    +  # in FelFlame::Components
    +  set_defaults
    +
    +  # Generate ID
    +  new_id = self.class.data.find_index { |i| i.nil? }
    +  new_id = self.class.data.size if new_id.nil?
    +  @id = new_id
    +
    +  # Fill params
    +  attrs.each do |key, value|
    +    send "#{key}=", value
    +  end
    +
    +  # Save Component
    +  self.class.data[new_id] = self
    +end
    +
    +
    + +

    Instance Attribute Details

    @@ -430,12 +529,12 @@
     
     
    -53
    -54
    -55
    +57 +58 +59
    -
    # File 'component_manager.rb', line 53
    +      
    # File 'component_manager.rb', line 57
     
     def id
       @id
    @@ -520,12 +619,12 @@
           
     
     
    -69
    -70
    -71
    +96 +97 +98
    -
    # File 'component_manager.rb', line 69
    +      
    # File 'component_manager.rb', line 96
     
     def [](component_id)
       data[component_id]
    @@ -538,7 +637,7 @@
           

    - .eachEnumerator + .each(&block) ⇒ Enumerator @@ -547,7 +646,7 @@

    -

    Iterates over all components within the component manager

    +

    Iterates over all components within the component manager. Special Enumerable methods like map or each_with_index are not implemented

    @@ -574,114 +673,15 @@
     
     
    -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) - - - -
    • - -
    - -
    - - @@ -738,14 +738,14 @@
     
     
    -137
    -138
    -139
    -140
    -141
    +143 +144 +145 +146 +147
    -
    -
    -
    -76
    -77
    -78
    -79
    -80
    -81
    -82
    -83
    -84
    -85
    -86
    -87
    -88
    -89
    -90
    -91
    +103 +104 +105
    -
    # File 'component_manager.rb', line 76
    -
    -def new(**attrs)
    -  new_component = super
    +      
    # File 'component_manager.rb', line 103
     
    -  # 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
    +def each(&block)
    +  data.compact.each(&block)
     end
    -
    # File 'component_manager.rb', line 137
    +      
    # File 'component_manager.rb', line 143
     
     def attrs
       instance_variables.each_with_object({}) do |key, final|
    @@ -801,20 +801,20 @@
           
     
     
    -124
    -125
    -126
    -127
    -128
    -129
     130
     131
     132
     133
    -134
    +134 +135 +136 +137 +138 +139 +140
    -
    # File 'component_manager.rb', line 124
    +      
    # File 'component_manager.rb', line 130
     
     def delete
       entities.each do |entity_id|
    @@ -835,7 +835,7 @@
           

    - #entitiesArray + #entitiesArray<Integer> @@ -844,7 +844,7 @@

    -

    A list of components that are linked to the component

    +

    A list of entity ids that are linked to the component

    @@ -857,7 +857,7 @@
  • - (Array) + (Array<Integer>) @@ -871,12 +871,12 @@
     
     
    -110
    -111
    -112
    +116 +117 +118
  • -
    # File 'component_manager.rb', line 110
    +      
    # File 'component_manager.rb', line 116
     
     def entities
       @entities ||= []
    @@ -925,12 +925,12 @@
           
     
     
    -104
    -105
    -106
    +110 +111 +112
    -
    # File 'component_manager.rb', line 104
    +      
    # File 'component_manager.rb', line 110
     
     def to_i
       id
    @@ -984,12 +984,12 @@
           
     
     
    -146
    -147
    -148
    +152 +153 +154
    -
    # File 'component_manager.rb', line 146
    +      
    # File 'component_manager.rb', line 152
     
     def to_json
       # should return a json or hash of all data in this component
    @@ -1043,14 +1043,14 @@
           
     
     
    -116
    -117
    -118
    -119
    -120
    +122 +123 +124 +125 +126
    -
    # File 'component_manager.rb', line 116
    +      
    # File 'component_manager.rb', line 122
     
     def update_attrs(**opts)
       opts.each do |key, value|
    @@ -1067,7 +1067,7 @@
     
     
           
    diff --git a/docs/FelFlame/Systems.html b/docs/FelFlame/Systems.html
    index a418bfb..2dd4534 100644
    --- a/docs/FelFlame/Systems.html
    +++ b/docs/FelFlame/Systems.html
    @@ -124,7 +124,7 @@
     
     
           
    diff --git a/docs/_index.html b/docs/_index.html
    index 42c4e44..0ae242d 100644
    --- a/docs/_index.html
    +++ b/docs/_index.html
    @@ -164,7 +164,7 @@
     
     
           
    diff --git a/docs/file.README.html b/docs/file.README.html
    index a62e2fd..c1e498b 100644
    --- a/docs/file.README.html
    +++ b/docs/file.README.html
    @@ -353,7 +353,7 @@ complete I will use a more verbose explanation as below to help users of the fra
     
     
           
    diff --git a/docs/index.html b/docs/index.html
    index 333991c..1d9dc01 100644
    --- a/docs/index.html
    +++ b/docs/index.html
    @@ -353,7 +353,7 @@ complete I will use a more verbose explanation as below to help users of the fra
     
     
           
    diff --git a/docs/method_list.html b/docs/method_list.html
    index 065cba8..cdf6aae 100644
    --- a/docs/method_list.html
    +++ b/docs/method_list.html
    @@ -158,24 +158,24 @@
     
       
  • - #initialize - FelFlame::Entities + #initialize + FelFlame::Helper::ComponentManager
  • - new - FelFlame::Components + #initialize + FelFlame::Entities
  • - new - FelFlame::Helper::ComponentManager + new + FelFlame::Components
  • diff --git a/docs/top-level-namespace.html b/docs/top-level-namespace.html index b2bd7c9..869c856 100644 --- a/docs/top-level-namespace.html +++ b/docs/top-level-namespace.html @@ -127,7 +127,7 @@ diff --git a/entity_manager.rb b/entity_manager.rb index 5038630..abbf1d0 100644 --- a/entity_manager.rb +++ b/entity_manager.rb @@ -9,14 +9,16 @@ class FelFlame # @return [Entity] def initialize(*components) # Assign new unique ID - new_id = self.class.data.find_index { |i| i.nil? } + new_id = self.class.data.find_index(&:nil?) new_id = self.class.data.size if new_id.nil? self.id = new_id # Add each component - components.uniq.each do |component| - add component - end + #components.uniq.each do |component| + # add component + #end + add(*components) + self.class.data[id] = self end @@ -37,11 +39,7 @@ class FelFlame 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].entities.delete(id) - # The following is neater, but doesnt work for some reason :/ - #Object.const_get(component_manager)[component_id].entities.delete(id) + component_manager[component_id].entities.delete(id) end end FelFlame::Entities.data[id] = nil @@ -50,34 +48,37 @@ class FelFlame true end - # Returns true when added, or false if it already belongs to the Entity - # 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) - if components[component.class.to_s.to_sym].nil? - components[component.class.to_s.to_sym] = [component.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.entities.push id - true - else - false + # Add any number components to the Entity. + # @param component [Component] Any number of components created from any component manager + # @return [Boolean] true if component is added, false if it already is attached or no components given + def add(*components_to_add) + added = false + components_to_add.each do |component| + if components[component.class].nil? + components[component.class] = [component.id] + component.entities.push id + added =true + elsif !components[component.class].include? component.id + components[component.class].push component.id + component.entities.push id + added = true + end end + added end # 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) - components[component.class.to_s.to_sym].delete component.id - if component.entities.delete id - true - else - false + # @param component_to_remove [Component] A component created from any component manager + # @return [Boolean] true if at least one component is removed, false if none of them were attached to the component + def remove(*components_to_remove) + removed = false + components_to_remove.each do |component| + components[component.class].delete component.id + if component.entities.delete id + removed = true + end end + removed end # Export all data into a JSON String which can then be saved into a file @@ -87,7 +88,7 @@ class FelFlame class <] Array of all Entities that exist # @!visibility private def data @data ||= [] diff --git a/helpers/00_tileset.rb b/helpers/00_tileset.rb index 3890550..c4293cb 100644 --- a/helpers/00_tileset.rb +++ b/helpers/00_tileset.rb @@ -1,3 +1,9 @@ +# Coverage Ignored because the functionality of this +# code will not be used for the core of FelFlame. +# It will most likely be released as a seperate package +# The code will most likely be kept here until it +# eventually will be migrated to a new git repo +# :nocov: class Helper # Returns a loaded map and its dependecies(images,json) # If any are missing then it will load them from files @@ -47,3 +53,4 @@ class Helper end end end +# :nocov: diff --git a/helpers/01_component.rb b/helpers/01_component.rb index cedc32e..2065d0c 100644 --- a/helpers/01_component.rb +++ b/helpers/01_component.rb @@ -1,6 +1,8 @@ class FelFlame class Helper +=begin + # Unused: class Level < FelFlame::Helper::ComponentManager class <= SimpleCov.minimum_coverage[:line] - 'good' - else - 'bad' - end - else - 'unknown' - end - end -end -=end - -SimpleCov.start do - SimpleCov.add_filter 'tests' - SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([ - SimpleCov::Formatter::HTMLFormatter, - SimpleCov::Formatter::JSONFormatter - #SimpleCovSmallBadge::Formatter - ]) -end - -require 'minitest/autorun' -require 'minitest/reporters' - -Minitest::Reporters.use! diff --git a/tests/_test_sample.rb b/tests/_test_sample.rb deleted file mode 100644 index afc3384..0000000 --- a/tests/_test_sample.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'minitest/autorun' -require_relative '_test_helper.rb' - -require_relative 'stuff_we_testing' - -describe 'Sample' do - before do - #setup vars here - end - - it 'does something' do - #_(@thing).mustequal 'something - end -end diff --git a/tests/component_manager_test.rb b/tests/component_manager_test.rb deleted file mode 100644 index 195eff3..0000000 --- a/tests/component_manager_test.rb +++ /dev/null @@ -1,62 +0,0 @@ -require 'minitest/autorun' -require_relative '_test_helper.rb' - -require_relative '../felflame.rb' - -describe 'Components' do - before(:all) do - FelFlame::Components.new('Test', :param1, param2: 'default') - #setup vars here - end - - after do - FelFlame::Components::Test.each.delete - end - - it 'can create new component types' do - _(FelFlame::Components.new('Test2', :p, k: 'something')).must_equal\ - FelFlame::Components::Test2 - end - - it 'can make new components' do - _(FelFlame::Components::Test.new).must_equal FelFlame::Components::Test.get(0) - end - - it 'can set values' do - test = FelFlame::Components::Test.new - _(test.param1 = 'ok').must_equal 'ok' - _(test.param1).must_equal 'ok' - end - - it 'can add to entity' do - flunk - end - - it 'can remove from entity' do - flunk - end - - it 'can delete component' do - flunk - end - - it 'can dump single component' do - flunk - end - - it 'can load single component' do - flunk - end - - it 'can be added as \'when added\' trigger to system' do - flunk - end - - it 'can be added as \'when removed\' trigger to system' do - flunk - end - - it 'can be added as \'when is_set\' trigger to system' do - flunk - end -end diff --git a/tests/entity_manager_test.rb b/tests/entity_manager_test.rb deleted file mode 100644 index 09d21b5..0000000 --- a/tests/entity_manager_test.rb +++ /dev/null @@ -1,52 +0,0 @@ -require 'minitest/autorun' -require_relative '_test_helper.rb' - -require_relative '../felflame.rb' - -describe 'Entities' do - before do - @one = FelFlame::Entities.new - @two = FelFlame::Entities.new - @three = FelFlame::Entities.new - end - - after do - FelFlame::Entities.delete(0) - FelFlame::Entities.delete(1) - FelFlame::Entities.delete(2) - end - - it 'has correct ID\'s' do - _(@one.id).must_equal 0 - _(@two.id).must_equal 1 - _(@three.id).must_equal 2 - end - - it 'can be accessed' do - _(@one).must_equal FelFlame::Entities.get(0) - _(@two).must_equal FelFlame::Entities.get(1) - _(@three).must_equal FelFlame::Entities.get(2) - end - - it 'can be deleted' do - _(FelFlame::Entities.delete(0)).assert - _(FelFlame::Entities.get(0)).assert_nil - _(FelFlame::Entities.delete(7)).refute - end - - it 'can be dumped' do - flunk 'need to add dump test' - @one.dump - end - - it 'can load dumps' do - flunk 'need to add this test' - end - it 'can have components added' do - flunk 'make this test' - end - - it 'can have components removed' do - flunk 'make this test' - end -end diff --git a/tests/felflame_test.rb b/tests/felflame_test.rb deleted file mode 100644 index debb6f9..0000000 --- a/tests/felflame_test.rb +++ /dev/null @@ -1,45 +0,0 @@ -require 'minitest/autorun' -require_relative '_test_helper.rb' - -require_relative '../felflame.rb' - -describe 'Entities' do - before do - end - - it 'cant find constant' do - assert_raises(NameError, 'uninitialized constant DoesntExist') { - FelFlame::DoesntExist - } - end - - it 'can\'t find method' do - assert_raises(NoMethodError) { - FelFlame.wrong - } - end - - it 'FelFlame aliased to FF' do - _(FF).must_equal FelFlame - end - - it 'Entities aliased to Ent' do - _(FF::Ent).must_equal FelFlame::Entities - end - - it 'Components aliased to Cmp' do - _(FF::Cmp).must_equal FelFlame::Components - end - - it 'Systems aliased to Sys' do - _(FF::Sys).must_equal FelFlame::Systems - end - - it 'Scenes aliased to Scn' do - _(FF::Scn).must_equal FelFlame::Scene - end - - it 'Stage aliased to Stg' do - _(FF::Stg).must_equal FelFlame::Stage - end -end diff --git a/tests/scene_manager_test.rb b/tests/scene_manager_test.rb deleted file mode 100644 index 38febb8..0000000 --- a/tests/scene_manager_test.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'minitest/autorun' -require_relative '_test_helper.rb' - -require_relative '../scene_manager.rb' - -describe 'Sample' do - before do - #setup vars here - end - - it 'does something' do - _(4).must_equal 4 - #_(@thing).mustequal 'something - end -end diff --git a/tests/stage_manager_test.rb b/tests/stage_manager_test.rb deleted file mode 100644 index 69fda0a..0000000 --- a/tests/stage_manager_test.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'minitest/autorun' -require_relative '_test_helper.rb' - -require_relative '../stage_manager.rb' - -describe 'Sample' do - before do - #setup vars here - end - - it 'does something' do - _(4).must_equal 4 - #_(@thing).mustequal 'something - end -end diff --git a/tests/system_manager_test.rb b/tests/system_manager_test.rb deleted file mode 100644 index e02b283..0000000 --- a/tests/system_manager_test.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'minitest/autorun' -require_relative '_test_helper.rb' - -require_relative '../system_manager.rb' - -describe 'Sample' do - before do - #setup vars here - end - - it 'does something' do - _(4).must_equal 4 - #_(@thing).mustequal 'something - end -end -- cgit v1.2.3