From 8badd8f55231a5b569027501ed28d2e13bf9810e Mon Sep 17 00:00:00 2001 From: realtradam Date: Wed, 29 Dec 2021 11:03:24 -0500 Subject: method missing doesnt work --- docs/FelFlame.html | 2 +- docs/FelFlame/ComponentManager.html | 273 ++++++++++-------------------------- docs/FelFlame/Components.html | 2 +- docs/FelFlame/Entities.html | 2 +- docs/FelFlame/Scenes.html | 2 +- docs/FelFlame/Stage.html | 2 +- docs/FelFlame/Systems.html | 2 +- docs/Felflame_.html | 2 +- docs/_index.html | 2 +- docs/file.README.html | 2 +- docs/index.html | 2 +- docs/method_list.html | 106 +++++++------- docs/top-level-namespace.html | 2 +- lib/felflame/component_manager.rb | 44 +++--- spec/component_manager_spec.rb | 45 +++--- spec/entity_manager_spec.rb | 30 ++-- 16 files changed, 205 insertions(+), 315 deletions(-) diff --git a/docs/FelFlame.html b/docs/FelFlame.html index ba3cf89..b08b611 100644 --- a/docs/FelFlame.html +++ b/docs/FelFlame.html @@ -307,7 +307,7 @@ diff --git a/docs/FelFlame/ComponentManager.html b/docs/FelFlame/ComponentManager.html index 95c9fe4..eeba9e6 100644 --- a/docs/FelFlame/ComponentManager.html +++ b/docs/FelFlame/ComponentManager.html @@ -341,7 +341,7 @@
  • - .[](component_id) ⇒ Component + .method_missing(symbol, *args, &block) ⇒ Object @@ -355,33 +355,7 @@ -
    -

    Gets a Component from the given unique ID.

    -
    - -
  • - - -
  • - - - .each(&block) ⇒ Enumerator - - - - - - - - - - - - - -
    -

    Iterates over all components within the component manager.

    -
    +
  • @@ -710,12 +684,12 @@
     
     
    -136
    -137
    -138
    +144 +145 +146 -
    # File 'lib/felflame/component_manager.rb', line 136
    +      
    # File 'lib/felflame/component_manager.rb', line 144
     
     def addition_triggers
       @addition_triggers ||= []
    @@ -766,12 +740,12 @@
           
     
     
    -152
    -153
    -154
    +160 +161 +162
    -
    # File 'lib/felflame/component_manager.rb', line 152
    +      
    # File 'lib/felflame/component_manager.rb', line 160
     
     def attr_triggers
       @attr_triggers ||= {}
    @@ -822,12 +796,12 @@
           
     
     
    -144
    -145
    -146
    +152 +153 +154
    -
    # File 'lib/felflame/component_manager.rb', line 144
    +      
    # File 'lib/felflame/component_manager.rb', line 152
     
     def removal_triggers
       @removal_triggers ||= []
    @@ -1074,136 +1048,37 @@
     
         
           
    -

    - - .[](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

      -
      - -
    • +

      -

    - -
    - - - - -
    -
    -
    -
    -169
    -170
    -171
    -
    -
    # File 'lib/felflame/component_manager.rb', line 169
    -
    -def [](component_id)
    -  data[component_id]
    -end
    -
    -
    - -
    -

    - - .each(&block) ⇒ Enumerator - - + .method_missing(symbol, *args, &block) ⇒ Object -

    -
    - -

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

    - -
    -
    -
    - -

    Returns:

    -
      - -
    • - - - (Enumerator) - - - -
    • -
    - -
    +
    @@ -1260,18 +1135,18 @@
     
     
    -203
    -204
    -205
    -206
    -207
    -208
    -209
    -210
    -211
    +211 +212 +213 +214 +215 +216 +217 +218 +219
     
     
    -176
    -177
    -178
    +126 +127 +128 +129 +130 +131 +132
    -
    # File 'lib/felflame/component_manager.rb', line 176
    +      
    # File 'lib/felflame/component_manager.rb', line 126
     
    -def each(&block)
    -  data.compact.each(&block)
    +def method_missing(symbol, *args, &block)
    +  if symbol.to_s.include? 'each'
    +    self.data.compact.send(symbol, *args, &block)
    +  else
    +    self.data.send(symbol, *args, &block)
    +  end
     end
    -
    # File 'lib/felflame/component_manager.rb', line 203
    +      
    # File 'lib/felflame/component_manager.rb', line 211
     
     def attr_changed_trigger_systems(attr)
       systems_to_execute = self.class.attr_triggers[attr]
    @@ -1331,16 +1206,16 @@
           
     
     
    -235
    -236
    -237
    -238
    -239
    -240
    -241
    +243 +244 +245 +246 +247 +248 +249
    -
    # File 'lib/felflame/component_manager.rb', line 235
    +      
    # File 'lib/felflame/component_manager.rb', line 243
     
     def attrs
       return_hash = instance_variables.each_with_object({}) do |key, final|
    @@ -1398,14 +1273,6 @@
           
     
     
    -215
    -216
    -217
    -218
    -219
    -220
    -221
    -222
     223
     224
     225
    @@ -1415,10 +1282,18 @@
     229
     230
     231
    -232
    +232 +233 +234 +235 +236 +237 +238 +239 +240
    -
    # File 'lib/felflame/component_manager.rb', line 215
    +      
    # File 'lib/felflame/component_manager.rb', line 223
     
     def delete
       addition_triggers.each do |system|
    @@ -1482,12 +1357,12 @@
           
     
     
    -189
    -190
    -191
    +197 +198 +199
    -
    # File 'lib/felflame/component_manager.rb', line 189
    +      
    # File 'lib/felflame/component_manager.rb', line 197
     
     def entities
       @entities ||= []
    @@ -1536,12 +1411,12 @@
           
     
     
    -183
    -184
    -185
    +191 +192 +193
    -
    # File 'lib/felflame/component_manager.rb', line 183
    +      
    # File 'lib/felflame/component_manager.rb', line 191
     
     def to_i
       id
    @@ -1595,14 +1470,14 @@
           
     
     
    -195
    -196
    -197
    -198
    -199
    +203 +204 +205 +206 +207
    -
    # File 'lib/felflame/component_manager.rb', line 195
    +      
    # File 'lib/felflame/component_manager.rb', line 203
     
     def update_attrs(**opts)
       opts.each do |key, value|
    @@ -1619,7 +1494,7 @@
     
     
           
    diff --git a/docs/FelFlame/Components.html b/docs/FelFlame/Components.html
    index 4ebd2dc..b6cd81e 100644
    --- a/docs/FelFlame/Components.html
    +++ b/docs/FelFlame/Components.html
    @@ -421,7 +421,7 @@
     
     
           
    diff --git a/docs/FelFlame/Entities.html b/docs/FelFlame/Entities.html
    index 306b98e..afd5294 100644
    --- a/docs/FelFlame/Entities.html
    +++ b/docs/FelFlame/Entities.html
    @@ -1042,7 +1042,7 @@
     
     
           
    diff --git a/docs/FelFlame/Scenes.html b/docs/FelFlame/Scenes.html
    index a78044b..d8b0578 100644
    --- a/docs/FelFlame/Scenes.html
    +++ b/docs/FelFlame/Scenes.html
    @@ -753,7 +753,7 @@
     
     
           
    diff --git a/docs/FelFlame/Stage.html b/docs/FelFlame/Stage.html
    index 50e9dcb..8478e3f 100644
    --- a/docs/FelFlame/Stage.html
    +++ b/docs/FelFlame/Stage.html
    @@ -588,7 +588,7 @@
     
     
           
    diff --git a/docs/FelFlame/Systems.html b/docs/FelFlame/Systems.html
    index 56e8aca..6912a03 100644
    --- a/docs/FelFlame/Systems.html
    +++ b/docs/FelFlame/Systems.html
    @@ -1531,7 +1531,7 @@
     
     
           
    diff --git a/docs/Felflame_.html b/docs/Felflame_.html
    index 94ef230..483f158 100644
    --- a/docs/Felflame_.html
    +++ b/docs/Felflame_.html
    @@ -133,7 +133,7 @@
     
     
           
    diff --git a/docs/_index.html b/docs/_index.html
    index 61b0c08..5fcfafb 100644
    --- a/docs/_index.html
    +++ b/docs/_index.html
    @@ -168,7 +168,7 @@
     
     
           
    diff --git a/docs/file.README.html b/docs/file.README.html
    index 132fb00..a69ef78 100644
    --- a/docs/file.README.html
    +++ b/docs/file.README.html
    @@ -514,7 +514,7 @@ E.g priority 1 will go first, priority 2 will go second, etcetera.  

    diff --git a/docs/index.html b/docs/index.html index 5038a53..9168208 100644 --- a/docs/index.html +++ b/docs/index.html @@ -514,7 +514,7 @@ E.g priority 1 will go first, priority 2 will go second, etcetera.

    diff --git a/docs/method_list.html b/docs/method_list.html index 4071d1b..b61ff32 100644 --- a/docs/method_list.html +++ b/docs/method_list.html @@ -53,14 +53,6 @@
  • -
    - [] - FelFlame::ComponentManager -
    -
  • - - -
  • #add FelFlame::Scenes @@ -68,7 +60,7 @@
  • -
  • +
  • add FelFlame::Stage @@ -76,7 +68,7 @@
  • -
  • +
  • #add FelFlame::Entities @@ -84,7 +76,7 @@
  • -
  • +
  • #addition_triggers FelFlame::Systems @@ -92,7 +84,7 @@
  • -
  • +
  • #addition_triggers FelFlame::ComponentManager @@ -100,7 +92,7 @@
  • -
  • +
  • addition_triggers FelFlame::ComponentManager @@ -108,7 +100,7 @@
  • -
  • +
  • #attr_changed_trigger_systems FelFlame::ComponentManager @@ -116,7 +108,7 @@
  • -
  • +
  • #attr_triggers FelFlame::Systems @@ -124,7 +116,7 @@
  • -
  • +
  • #attr_triggers FelFlame::ComponentManager @@ -132,7 +124,7 @@
  • -
  • +
  • attr_triggers FelFlame::ComponentManager @@ -140,7 +132,7 @@
  • -
  • +
  • #attrs FelFlame::ComponentManager @@ -148,7 +140,7 @@
  • -
  • +
  • call FelFlame @@ -156,7 +148,7 @@
  • -
  • +
  • #call FelFlame::Scenes @@ -164,7 +156,7 @@
  • -
  • +
  • call FelFlame::Stage @@ -172,7 +164,7 @@
  • -
  • +
  • #call FelFlame::Systems @@ -180,7 +172,7 @@
  • -
  • +
  • #clear FelFlame::Scenes @@ -188,7 +180,7 @@
  • -
  • +
  • clear FelFlame::Stage @@ -196,7 +188,7 @@
  • -
  • +
  • #clear_triggers FelFlame::Systems @@ -204,7 +196,7 @@
  • -
  • +
  • #components FelFlame::Entities @@ -212,7 +204,7 @@
  • -
  • +
  • #const_name FelFlame::Scenes @@ -220,7 +212,7 @@
  • -
  • +
  • #const_name FelFlame::Systems @@ -228,7 +220,7 @@
  • -
  • +
  • #delete FelFlame::Entities @@ -236,7 +228,7 @@
  • -
  • +
  • #delete FelFlame::ComponentManager @@ -244,7 +236,7 @@
  • -
  • +
  • each FelFlame::Entities @@ -252,7 +244,7 @@
  • -
  • +
  • each FelFlame::Systems @@ -260,7 +252,7 @@
  • -
  • +
  • each FelFlame::Components @@ -268,14 +260,6 @@
  • -
  • -
    - each - FelFlame::ComponentManager -
    -
  • - -
  • #entities @@ -333,6 +317,14 @@
  • +
    + method_missing + FelFlame::ComponentManager +
    +
  • + + +
  • new FelFlame::Components @@ -340,7 +332,7 @@
  • -
  • +
  • #priority FelFlame::Systems @@ -348,7 +340,7 @@
  • -
  • +
  • #redefine FelFlame::Systems @@ -356,7 +348,7 @@
  • -
  • +
  • #removal_triggers FelFlame::Systems @@ -364,7 +356,7 @@
  • -
  • +
  • #removal_triggers FelFlame::ComponentManager @@ -372,7 +364,7 @@
  • -
  • +
  • removal_triggers FelFlame::ComponentManager @@ -380,7 +372,7 @@
  • -
  • +
  • #remove FelFlame::Scenes @@ -388,7 +380,7 @@
  • -
  • +
  • remove FelFlame::Stage @@ -396,7 +388,7 @@
  • -
  • +
  • #remove FelFlame::Entities @@ -404,7 +396,7 @@
  • -
  • +
  • scenes FelFlame::Stage @@ -412,7 +404,7 @@
  • -
  • +
  • #systems FelFlame::Scenes @@ -420,7 +412,7 @@
  • -
  • +
  • #to_i FelFlame::Entities @@ -428,7 +420,7 @@
  • -
  • +
  • #to_i FelFlame::ComponentManager @@ -436,7 +428,7 @@
  • -
  • +
  • #trigger_when_added FelFlame::Systems @@ -444,7 +436,7 @@
  • -
  • +
  • #trigger_when_is_changed FelFlame::Systems @@ -452,7 +444,7 @@
  • -
  • +
  • #trigger_when_removed FelFlame::Systems @@ -460,7 +452,7 @@
  • -
  • +
  • #update_attrs FelFlame::ComponentManager diff --git a/docs/top-level-namespace.html b/docs/top-level-namespace.html index 7e418d2..4275c26 100644 --- a/docs/top-level-namespace.html +++ b/docs/top-level-namespace.html @@ -129,7 +129,7 @@
    diff --git a/lib/felflame/component_manager.rb b/lib/felflame/component_manager.rb index 43932d2..2fa4949 100644 --- a/lib/felflame/component_manager.rb +++ b/lib/felflame/component_manager.rb @@ -60,13 +60,13 @@ class FelFlame # Holds the {id unique ID} of a component. The {id ID} is only unique within the scope of the component manager it was created from. # @return [Integer] - attr_reader :id + #attr_reader :id # A seperate attr_writer was made for documentation readability reasons. # Yard will list attr_reader is readonly which is my intention. # This value needs to be changable as it is set by other functions. # @!visibility private - attr_writer :id + #attr_writer :id # Allows overwriting the storage of triggers, such as for clearing. # This method should generally only need to be used internally and @@ -108,9 +108,9 @@ class FelFlame 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 + #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| @@ -118,11 +118,23 @@ class FelFlame end # Save Component - self.class.data[new_id] = self + #self.class.data[new_id] = self + self.class.push self end class <] @@ -224,7 +236,7 @@ class FelFlame #FelFlame::Entities[entity_id].remove self #unless FelFlame::Entities[entity_id].nil? entity.remove self end - self.class.data[id] = nil + self.class.delete self instance_variables.each do |var| instance_variable_set(var, nil) end diff --git a/spec/component_manager_spec.rb b/spec/component_manager_spec.rb index d99d744..203d185 100644 --- a/spec/component_manager_spec.rb +++ b/spec/component_manager_spec.rb @@ -25,16 +25,17 @@ describe 'Components' do end it 'can delete a component' do - component_id = @cmp1.id + #component_id = @cmp1.id @ent0.add @cmp1 - + length = @component_manager.length expect(@cmp1.delete).to be true - expect(@cmp1.id).to be_nil - expect(@component_manager[component_id]).to be_nil + expect(@component_manager.length).to eq(length-1) + #expect(@cmp1.id).to be_nil + #expect(@component_manager[component_id]).to be_nil expect(@cmp1.entities).to eq([]) end - it 'can iterate over all component managers' do + it 'can iterate component managers' do all_components = FelFlame::Components.constants expect(all_components.length).to be > 0 expect(FelFlame::Components.each).to be_an Enumerator @@ -46,7 +47,7 @@ describe 'Components' do it 'can change params on initialization' do @cmp3 = @component_manager.new(param1: 'ok', param2: 10) - expect(@cmp3.attrs).to eq(param1: 'ok', param2: 10, id: @cmp3.id) + expect(@cmp3.attrs).to eq(param1: 'ok', param2: 10) end @@ -60,28 +61,32 @@ describe 'Components' do end it 'can read attrs' do - expect(@cmp0.attrs).to eq(param2: 'def', id: 0) - expect(@cmp1.attrs).to eq(param2: 'def', id: 1) - expect(@cmp2.attrs).to eq(param2: 'def', id: 2) + expect(@cmp0.attrs).to eq(param2: 'def') + expect(@cmp1.attrs).to eq(param2: 'def') + expect(@cmp2.attrs).to eq(param2: 'def') end it 'can set attrs' do expect(@cmp0.param1 = 4).to eq(4) expect(@cmp1.update_attrs(param1: 3, param2: 'new')).to eq(param1: 3, param2: 'new') - expect(@cmp1.attrs).to eq(param1: 3, param2: 'new', id: 1) + expect(@cmp1.attrs).to eq(param1: 3, param2: 'new') end - it 'can be accessed' do - expect(@cmp0).to eq(@component_manager[0]) - expect(@cmp1).to eq(@component_manager[1]) - expect(@cmp2).to eq(@component_manager[2]) + it 'can be used as a singleton' do + expect(@component_manager.first).to eq(@cmp0) end - it 'can get id from to_i' do - expect(@cmp0.id).to eq(@cmp0.to_i) - expect(@cmp1.id).to eq(@cmp1.to_i) - expect(@cmp2.id).to eq(@cmp2.to_i) - end + #it 'can be accessed' do + # expect(@cmp0).to eq(@component_manager[0]) + # expect(@cmp1).to eq(@component_manager[1]) + # expect(@cmp2).to eq(@component_manager[2]) + #end + + #it 'can get id from to_i' do + # expect(@cmp0.id).to eq(@cmp0.to_i) + # expect(@cmp1.id).to eq(@cmp1.to_i) + # expect(@cmp2.id).to eq(@cmp2.to_i) + #end it 'cant overwrite exiting component managers' do FelFlame::Components.new('TestComponent1') @@ -89,7 +94,7 @@ describe 'Components' do end it 'can\'t create an attribute when its name is an existing method' do - expect { FelFlame::Components.new('TestComponent2', :id) }.to raise_error(NameError) + #expect { FelFlame::Components.new('TestComponent2', :id) }.to raise_error(NameError) expect { FelFlame::Components.new('TestComponent2', :addition_triggers) }.to raise_error(NameError) expect { FelFlame::Components.new('TestComponent2', :removal_triggers) }.to raise_error(NameError) expect { FelFlame::Components.new('TestComponent2', :attr_triggers) }.to raise_error(NameError) diff --git a/spec/entity_manager_spec.rb b/spec/entity_manager_spec.rb index ef638c0..7bf941d 100644 --- a/spec/entity_manager_spec.rb +++ b/spec/entity_manager_spec.rb @@ -9,6 +9,7 @@ describe 'Entities' do #end before :all do + $VERBOSE = nil @component_manager ||= FelFlame::Components.new('TestEntity', :param1, param2: 'def') end @@ -32,17 +33,17 @@ describe 'Entities' do expect(@ent0.components[@component_manager].count).to eq(2) end - it 'has correct ID\'s' do - expect(@ent0.id).to eq(0) - expect(@ent1.id).to eq(1) - expect(@ent2.id).to eq(2) - end + #it 'has correct ID\'s' do + # expect(@ent0.id).to eq(0) + # expect(@ent1.id).to eq(1) + # expect(@ent2.id).to eq(2) + #end - it 'can be accessed' do - expect(@ent0).to eq(FelFlame::Entities[0]) - expect(@ent1).to eq(FelFlame::Entities[1]) - expect(@ent2).to eq(FelFlame::Entities[2]) - end + #it 'can be accessed' do + # expect(@ent0).to eq(FelFlame::Entities[0]) + # expect(@ent1).to eq(FelFlame::Entities[1]) + # expect(@ent2).to eq(FelFlame::Entities[2]) + #end it 'can have components attached' do @ent0.add @cmp0 @@ -82,10 +83,15 @@ describe 'Entities' do @cmp1.delete expect(@ent0.components).to eq({@component_manager => [@cmp0,@cmp2]}) @component_manager.each(&:delete) - expect(@component_manager.each.to_a).to eq([]) + $stderr.puts ('HERE HERE ' * 5) + $stderr.puts @component_manager + @component_manager.each do |component| + $stderr.puts component + end + expect(@component_manager.empty?).to be true expect(@ent0.components).to eq({@component_manager => []}) expect(@ent2.components).to eq({@component_manager => []}) FelFlame::Entities.each(&:delete) - expect(FelFlame::Entities.each.to_a).to eq([]) + expect(FelFlame::Entities.empty?).to be true end end -- cgit v1.2.3