From 809028c3d89993b2bb0651076ba723c11734cf3c Mon Sep 17 00:00:00 2001 From: realtradam Date: Mon, 3 Jan 2022 06:20:55 -0500 Subject: . --- docs/FelFlame.html | 2 +- docs/FelFlame/ComponentManager.html | 182 +++++++++---------- docs/FelFlame/Components.html | 6 +- docs/FelFlame/Entities.html | 104 +++++------ docs/FelFlame/Scenes.html | 120 +++++++------ docs/FelFlame/Stage.html | 58 +++--- docs/FelFlame/Systems.html | 346 ++++++++++++++++-------------------- docs/Felflame_.html | 2 +- docs/_index.html | 2 +- docs/file.README.html | 2 +- docs/index.html | 2 +- docs/method_list.html | 54 +++--- docs/top-level-namespace.html | 2 +- lib/felflame/component_manager.rb | 53 +++++- lib/felflame/entity_manager.rb | 35 +++- lib/felflame/scene_manager.rb | 12 +- lib/felflame/stage_manager.rb | 32 +--- lib/felflame/system_manager.rb | 47 ++++- spec/component_manager_spec.rb | 32 ++-- spec/entity_manager_spec.rb | 33 +--- spec/scene_manager_spec.rb | 4 + spec/stage_manager_spec.rb | 79 +++----- spec/system_manager_spec.rb | 42 ++--- 23 files changed, 611 insertions(+), 640 deletions(-) diff --git a/docs/FelFlame.html b/docs/FelFlame.html index 8fd0fd6..ef9cb69 100644 --- a/docs/FelFlame.html +++ b/docs/FelFlame.html @@ -293,7 +293,7 @@ diff --git a/docs/FelFlame/ComponentManager.html b/docs/FelFlame/ComponentManager.html index 599b547..119a7ed 100644 --- a/docs/FelFlame/ComponentManager.html +++ b/docs/FelFlame/ComponentManager.html @@ -531,23 +531,23 @@
 
 
-109
-110
-111
-112
-113
-114
-115
-116
-117
-118
-119
-120
-121
-122
+156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 -
# File 'lib/felflame/component_manager.rb', line 109
+      
# File 'lib/felflame/component_manager.rb', line 156
 
 def initialize(**attrs)
   # Prepare the object
@@ -614,12 +614,12 @@
       
 
 
-159
-160
-161
+206 +207 +208
-
# File 'lib/felflame/component_manager.rb', line 159
+      
# File 'lib/felflame/component_manager.rb', line 206
 
 def addition_triggers
   @addition_triggers ||= []
@@ -670,12 +670,12 @@
       
 
 
-175
-176
-177
+222 +223 +224
-
# File 'lib/felflame/component_manager.rb', line 175
+      
# File 'lib/felflame/component_manager.rb', line 222
 
 def attr_triggers
   @attr_triggers ||= {}
@@ -726,12 +726,12 @@
       
 
 
-167
-168
-169
+214 +215 +216
-
# File 'lib/felflame/component_manager.rb', line 167
+      
# File 'lib/felflame/component_manager.rb', line 214
 
 def removal_triggers
   @removal_triggers ||= []
@@ -787,12 +787,12 @@
       
 
 
-86
-87
-88
+133 +134 +135
-
# File 'lib/felflame/component_manager.rb', line 86
+      
# File 'lib/felflame/component_manager.rb', line 133
 
 def addition_triggers
   @addition_triggers ||= []
@@ -843,12 +843,12 @@
       
 
 
-102
-103
-104
+149 +150 +151
-
# File 'lib/felflame/component_manager.rb', line 102
+      
# File 'lib/felflame/component_manager.rb', line 149
 
 def attr_triggers
   @attr_triggers ||= {}
@@ -899,12 +899,12 @@
       
 
 
-94
-95
-96
+141 +142 +143
-
# File 'lib/felflame/component_manager.rb', line 94
+      
# File 'lib/felflame/component_manager.rb', line 141
 
 def removal_triggers
   @removal_triggers ||= []
@@ -965,18 +965,18 @@
       
 
 
-213
-214
-215
-216
-217
-218
-219
-220
-221
+260 +261 +262 +263 +264 +265 +266 +267 +268
-
# File 'lib/felflame/component_manager.rb', line 213
+      
# File 'lib/felflame/component_manager.rb', line 260
 
 def attr_changed_trigger_systems(attr)
   systems_to_execute = self.class.attr_triggers[attr]
@@ -1036,22 +1036,22 @@
       
 
 
-224
-225
-226
-227
-228
-229
-230
-231
-232
-233
-234
-235
-236
+271 +272 +273 +274 +275 +276 +277 +278 +279 +280 +281 +282 +283
-
# File 'lib/felflame/component_manager.rb', line 224
+      
# File 'lib/felflame/component_manager.rb', line 271
 
 def delete
   addition_triggers.each do |system|
@@ -1110,12 +1110,12 @@
       
 
 
-188
-189
-190
+235 +236 +237
-
# File 'lib/felflame/component_manager.rb', line 188
+      
# File 'lib/felflame/component_manager.rb', line 235
 
 def entities
   @entities ||= []
@@ -1164,17 +1164,17 @@
       
 
 
-194
-195
-196
-197
-198
-199
-200
-201
+241 +242 +243 +244 +245 +246 +247 +248
-
# File 'lib/felflame/component_manager.rb', line 194
+      
# File 'lib/felflame/component_manager.rb', line 241
 
 def entity
   if entities.empty?
@@ -1233,16 +1233,16 @@
       
 
 
-239
-240
-241
-242
-243
-244
-245
+286 +287 +288 +289 +290 +291 +292
-
# File 'lib/felflame/component_manager.rb', line 239
+      
# File 'lib/felflame/component_manager.rb', line 286
 
 def to_h
   return_hash = instance_variables.each_with_object({}) do |key, final|
@@ -1300,14 +1300,14 @@
       
 
 
-205
-206
-207
-208
-209
+252 +253 +254 +255 +256
-
# File 'lib/felflame/component_manager.rb', line 205
+      
# File 'lib/felflame/component_manager.rb', line 252
 
 def update_attrs(**opts)
   opts.each do |key, value|
@@ -1324,7 +1324,7 @@
 
 
       
diff --git a/docs/FelFlame/Components.html b/docs/FelFlame/Components.html
index e3b6167..33d82b3 100644
--- a/docs/FelFlame/Components.html
+++ b/docs/FelFlame/Components.html
@@ -277,7 +277,8 @@
 43
 44
 45
-46
+46 +47
# File 'lib/felflame/component_manager.rb', line 18
@@ -289,6 +290,7 @@
 
 
   const_set(component_name, Class.new(FelFlame::ComponentManager) {})
+  update_const_cache
 
   attrs.each do |attr|
     if FelFlame::Components.const_get(component_name).method_defined?("#{attr}") || FelFlame::Components.const_get(component_name).method_defined?("#{attr}=")
@@ -321,7 +323,7 @@
 
 
       
diff --git a/docs/FelFlame/Entities.html b/docs/FelFlame/Entities.html
index aca4cac..4308d4b 100644
--- a/docs/FelFlame/Entities.html
+++ b/docs/FelFlame/Entities.html
@@ -329,15 +329,7 @@
 8
 9
 10
-11
-12
-13
-14
-15
-16
-17
-18
-19
+11
# File 'lib/felflame/entity_manager.rb', line 7
@@ -345,14 +337,6 @@
 def initialize(*components)
   # Add each component
   add(*components)
-
-  # Fancy method redirection for when the `component` method is called
-  @component_redirect = Object.new
-  @component_redirect.instance_variable_set(:@entity, self)
-  @component_redirect.define_singleton_method(:[]) do |component_manager|
-    instance_variable_get(:@entity).component(component_manager)
-  end
-
   self.class._data.push self
 end
@@ -431,23 +415,23 @@
 
 
+56
+57
+58
+59
+60
+61
+62
 63
 64
 65
 66
 67
 68
-69
-70
-71
-72
-73
-74
-75
-76
+69
-
# File 'lib/felflame/entity_manager.rb', line 63
+      
# File 'lib/felflame/entity_manager.rb', line 56
 
 def add(*components_to_add)
   components_to_add.each do |component|
@@ -538,25 +522,27 @@
       
 
 
+25
+26
+27
+28
+29
+30
+31
+32
 33
 34
 35
 36
-37
-38
-39
-40
-41
-42
-43
-44
+37
-
# File 'lib/felflame/entity_manager.rb', line 33
+      
# File 'lib/felflame/entity_manager.rb', line 25
 
 def component(manager = nil)
   if manager.nil?
-    @component_redirect
+    FelFlame::Entities.component_redirect.entity = self
+    FelFlame::Entities.component_redirect
   else
     if components[manager].nil?
       raise "This entity(#{self}) doesnt have any components of this type: #{manager}"
@@ -610,12 +596,12 @@
       
 
 
-23
-24
-25
+15 +16 +17
-
# File 'lib/felflame/entity_manager.rb', line 23
+      
# File 'lib/felflame/entity_manager.rb', line 15
 
 def components
   @components ||= {}
@@ -669,19 +655,19 @@
       
 
 
+42
+43
+44
+45
+46
+47
+48
 49
 50
-51
-52
-53
-54
-55
-56
-57
-58
+51
-
# File 'lib/felflame/entity_manager.rb', line 49
+      
# File 'lib/felflame/entity_manager.rb', line 42
 
 def delete
   components.each do |component_manager, component_array|
@@ -762,20 +748,20 @@
       
 
 
+86
+87
+88
+89
+90
+91
+92
 93
 94
 95
-96
-97
-98
-99
-100
-101
-102
-103
+96
-
# File 'lib/felflame/entity_manager.rb', line 93
+      
# File 'lib/felflame/entity_manager.rb', line 86
 
 def remove(*components_to_remove)
   components_to_remove.each do |component|
@@ -798,7 +784,7 @@
 
 
       
diff --git a/docs/FelFlame/Scenes.html b/docs/FelFlame/Scenes.html
index 2c160fe..5a73e20 100644
--- a/docs/FelFlame/Scenes.html
+++ b/docs/FelFlame/Scenes.html
@@ -124,7 +124,7 @@
       
  • - #const_name ⇒ Object + #priority ⇒ Object @@ -133,8 +133,6 @@ - readonly - @@ -144,7 +142,7 @@
    -

    The Constant name assigned to this Scene.

    +

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

  • @@ -267,7 +265,7 @@
  • - #initialize(name) ⇒ Scenes + #initialize(name, priority: 0) ⇒ Scenes @@ -323,7 +321,7 @@

    - #initialize(name) ⇒ Scenes + #initialize(name, priority: 0) ⇒ Scenes @@ -366,17 +364,17 @@
     
     
    -14
    -15
    -16
    -17
    +20 +21 +22 +23

  • -
    # File 'lib/felflame/scene_manager.rb', line 14
    +      
    # File 'lib/felflame/scene_manager.rb', line 20
     
    -def initialize(name)
    +def initialize(name, priority: 0)
    +  self.priority = priority
       FelFlame::Scenes.const_set(name, self)
    -  @const_name = name
     end
    @@ -389,11 +387,11 @@

    Instance Attribute Details

    - +
    -

    +

    - #const_nameObject (readonly) + #priorityObject @@ -402,7 +400,7 @@

    -

    The Constant name assigned to this Scene

    +

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

    @@ -416,15 +414,15 @@
     
     
    -4
    -5
    -6
    +10 +11 +12
    -
    # File 'lib/felflame/scene_manager.rb', line 4
    +      
    # File 'lib/felflame/scene_manager.rb', line 10
     
    -def const_name
    -  @const_name
    +def priority
    +  @priority
     end
    @@ -472,12 +470,12 @@
     
     
    -21
    -22
    -23
    +27 +28 +29
    -
    # File 'lib/felflame/scene_manager.rb', line 21
    +      
    # File 'lib/felflame/scene_manager.rb', line 27
     
     def systems
       @systems ||= []
    @@ -538,20 +536,24 @@
           
     
     
    -34
    -35
    -36
    -37
    -38
    -39
    +40 +41 +42 +43 +44 +45 +46 +47
    -
    # File 'lib/felflame/scene_manager.rb', line 34
    +      
    # File 'lib/felflame/scene_manager.rb', line 40
     
     def add(*systems_to_add)
       self.systems |= systems_to_add
       self.systems = systems.sort_by(&:priority)
    -  FelFlame::Stage.update_systems_list if FelFlame::Stage.scenes.include? self
    +  systems_to_add.each do |system|
    +    system.scenes |= [self]
    +  end
       true
     end
    @@ -603,13 +605,13 @@
     
     
    -27
    -28
    -29
    -30
    +33 +34 +35 +36
    -
    # File 'lib/felflame/scene_manager.rb', line 27
    +      
    # File 'lib/felflame/scene_manager.rb', line 33
     
     def call
       systems.each(&:call)
    @@ -664,19 +666,25 @@
           
     
     
    -52
    -53
    -54
    -55
    -56
    +58 +59 +60 +61 +62 +63 +64 +65
    -
    # File 'lib/felflame/scene_manager.rb', line 52
    +      
    # File 'lib/felflame/scene_manager.rb', line 58
     
     def clear
    +  systems.each do |system|
    +    system.scenes.delete self
    +  end
       systems.clear
    -  FelFlame::Stage.update_systems_list if FelFlame::Stage.scenes.include? self
    -  true
    +  #FelFlame::Stage.update_systems_list if FelFlame::Stage.scenes.include? self
    +  true
     end
    @@ -727,20 +735,16 @@
     
     
    -43
    -44
    -45
    -46
    -47
    -48
    +51 +52 +53 +54
    -
    # File 'lib/felflame/scene_manager.rb', line 43
    +      
    # File 'lib/felflame/scene_manager.rb', line 51
     
     def remove(*systems_to_remove)
       self.systems -= systems_to_remove
    -  self.systems = systems.sort_by(&:priority)
    -  FelFlame::Stage.update_systems_list if FelFlame::Stage.scenes.include? self
       true
     end
    @@ -753,7 +757,7 @@ diff --git a/docs/FelFlame/Stage.html b/docs/FelFlame/Stage.html index b2e961b..892810b 100644 --- a/docs/FelFlame/Stage.html +++ b/docs/FelFlame/Stage.html @@ -289,12 +289,12 @@
     
     
    -58
    -59
    -60
    +40 +41 +42
    -
    # File 'lib/felflame/stage_manager.rb', line 58
    +      
    # File 'lib/felflame/stage_manager.rb', line 40
     
     def scenes
       @scenes ||= []
    @@ -359,20 +359,14 @@
     12
     13
     14
    -15
    -16
    -17
    -18
    +15
    # File 'lib/felflame/stage_manager.rb', line 11
     
     def add(*scenes_to_add)
       self.scenes |= scenes_to_add
    -  scenes_to_add.each do |scene|
    -    self.systems |= scene.systems
    -  end
    -  self.systems = systems.sort_by(&:priority)
    +  self.scenes = scenes.sort_by(&:priority)
       true
     end
    @@ -424,16 +418,16 @@
     
     
    -51
    -52
    -53
    -54
    +33 +34 +35 +36
    -
    # File 'lib/felflame/stage_manager.rb', line 51
    +      
    # File 'lib/felflame/stage_manager.rb', line 33
     
     def call
    -  systems.each(&:call)
    +  self.scenes.each(&:call)
       true
     end
    @@ -485,18 +479,16 @@
     
     
    -43
    -44
    -45
    -46
    -47
    +26 +27 +28 +29
    -
    # File 'lib/felflame/stage_manager.rb', line 43
    +      
    # File 'lib/felflame/stage_manager.rb', line 26
     
     def clear
    -  systems.clear
    -  scenes.clear
    +  self.scenes.clear
       true
     end
    @@ -548,18 +540,16 @@
     
     
    -22
    -23
    -24
    -25
    -26
    +19 +20 +21 +22
    -
    # File 'lib/felflame/stage_manager.rb', line 22
    +      
    # File 'lib/felflame/stage_manager.rb', line 19
     
     def remove(*scenes_to_remove)
       self.scenes -= scenes_to_remove
    -  update_systems_list
       true
     end
    @@ -572,7 +562,7 @@ diff --git a/docs/FelFlame/Systems.html b/docs/FelFlame/Systems.html index e549566..7f5d18c 100644 --- a/docs/FelFlame/Systems.html +++ b/docs/FelFlame/Systems.html @@ -85,11 +85,6 @@ -
    -
    Extended by:
    -
    Enumerable
    -
    - @@ -187,7 +182,7 @@
  • - #const_name ⇒ Object + #priority ⇒ Object @@ -196,8 +191,6 @@ - readonly - @@ -207,7 +200,7 @@
    -

    The Constant name assigned to this System.

    +

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

  • @@ -216,7 +209,7 @@
  • - #priority ⇒ Object + #removal_triggers ⇒ Array<Component> @@ -225,6 +218,8 @@ + readonly + @@ -234,7 +229,7 @@
    -

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

    +

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

  • @@ -243,7 +238,7 @@
  • - #removal_triggers ⇒ Array<Component> + #scenes ⇒ Object @@ -252,8 +247,6 @@ - readonly - @@ -262,9 +255,7 @@ -
    -

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

    -
    +
  • @@ -285,7 +276,7 @@
  • - .each(&block) ⇒ Enumerator + .const_cache ⇒ Object @@ -300,7 +291,7 @@
    -

    Iterate over all Systems, sorted by their priority.

    +

    Stores the systems in Components.

  • @@ -488,8 +479,7 @@ - -
    +

    Constructor Details

    @@ -586,21 +576,23 @@
     
     
    -71
    -72
    -73
    -74
    -75
    -76
    +116 +117 +118 +119 +120 +121 +122
    -
    # File 'lib/felflame/system_manager.rb', line 71
    +      
    # File 'lib/felflame/system_manager.rb', line 116
     
     def initialize(name, priority: 0, &block)
       FelFlame::Systems.const_set(name, self)
    -  @const_name = name
    +  FelFlame::Systems.update_const_cache
       @priority = priority
       @block = block
    +  @scenes = []
     end
    @@ -653,12 +645,12 @@
     
     
    -24
    -25
    -26
    +33 +34 +35
    -
    # File 'lib/felflame/system_manager.rb', line 24
    +      
    # File 'lib/felflame/system_manager.rb', line 33
     
     def addition_triggers
       @addition_triggers ||= []
    @@ -709,12 +701,12 @@
           
     
     
    -42
    -43
    -44
    +51 +52 +53
    -
    # File 'lib/felflame/system_manager.rb', line 42
    +      
    # File 'lib/felflame/system_manager.rb', line 51
     
     def attr_triggers
       @attr_triggers ||= {}
    @@ -725,49 +717,6 @@
     
         
           
    -      
    -      
    -

    - - #const_nameObject (readonly) - - - - - -

    -
    - -

    The Constant name assigned to this System

    - - -
    -
    -
    - - -
    - - - - -
    -
    -
    -
    -7
    -8
    -9
    -
    -
    # File 'lib/felflame/system_manager.rb', line 7
    -
    -def const_name
    -  @const_name
    -end
    -
    -
    - -

    @@ -851,12 +800,12 @@
     
     
    -33
    -34
    -35
    +42 +43 +44

    -
    # File 'lib/felflame/system_manager.rb', line 33
    +      
    # File 'lib/felflame/system_manager.rb', line 42
     
     def removal_triggers
       @removal_triggers ||= []
    @@ -866,6 +815,38 @@
     
     
         
    +      
    +      
    +      
    +

    + + #scenesObject + + + + + +

    + + + + +
    +
    +
    +
    +17
    +18
    +19
    +
    +
    # File 'lib/felflame/system_manager.rb', line 17
    +
    +def scenes
    +  @scenes ||= []
    +end
    +
    +
    + @@ -874,9 +855,9 @@
    -

    +

    - .each(&block) ⇒ Enumerator + .const_cacheObject @@ -885,26 +866,13 @@

    -

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

    +

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

    -

    Returns:

    -
      - -
    • - - - (Enumerator) - - - -
    • - -
    @@ -912,15 +880,15 @@
     
     
    -51
    -52
    -53
    +63 +64 +65 @@ -959,12 +927,12 @@
     
     
    -79
    -80
    -81
    +125 +126 +127
    -
    # File 'lib/felflame/system_manager.rb', line 51
    +      
    # File 'lib/felflame/system_manager.rb', line 63
     
    -def each(&block)
    -  constants.map { |sym| const_get(sym) }.sort_by(&:priority).reverse.each(&block)
    +def const_cache
    +  @const_cache || update_const_cache
     end
    -
    # File 'lib/felflame/system_manager.rb', line 79
    +      
    # File 'lib/felflame/system_manager.rb', line 125
     
     def call
       @block.call
    @@ -1077,52 +1045,6 @@
           
     
     
    -111
    -112
    -113
    -114
    -115
    -116
    -117
    -118
    -119
    -120
    -121
    -122
    -123
    -124
    -125
    -126
    -127
    -128
    -129
    -130
    -131
    -132
    -133
    -134
    -135
    -136
    -137
    -138
    -139
    -140
    -141
    -142
    -143
    -144
    -145
    -146
    -147
    -148
    -149
    -150
    -151
    -152
    -153
    -154
    -155
    -156
     157
     158
     159
    @@ -1143,10 +1065,56 @@
     174
     175
     176
    -177
    +177 +178 +179 +180 +181 +182 +183 +184 +185 +186 +187 +188 +189 +190 +191 +192 +193 +194 +195 +196 +197 +198 +199 +200 +201 +202 +203 +204 +205 +206 +207 +208 +209 +210 +211 +212 +213 +214 +215 +216 +217 +218 +219 +220 +221 +222 +223
    -
    # File 'lib/felflame/system_manager.rb', line 111
    +      
    # File 'lib/felflame/system_manager.rb', line 157
     
     def clear_triggers(*trigger_types, component_or_manager: nil)
       trigger_types = [:addition_triggers, :removal_triggers, :attr_triggers] if trigger_types.empty?
    @@ -1266,12 +1234,12 @@
           
     
     
    -84
    -85
    -86
    +130 +131 +132
    -
    # File 'lib/felflame/system_manager.rb', line 84
    +      
    # File 'lib/felflame/system_manager.rb', line 130
     
     def redefine(&block)
       @block = block
    @@ -1345,14 +1313,14 @@
           
     
     
    -182
    -183
    -184
    -185
    -186
    +228 +229 +230 +231 +232
    -
    # File 'lib/felflame/system_manager.rb', line 182
    +      
    # File 'lib/felflame/system_manager.rb', line 228
     
     def trigger_when_added(component_or_manager)
       self.addition_triggers |= [component_or_manager]
    @@ -1408,22 +1376,22 @@
           
     
     
    -199
    -200
    -201
    -202
    -203
    -204
    -205
    -206
    -207
    -208
    -209
    -210
    -211
    +245 +246 +247 +248 +249 +250 +251 +252 +253 +254 +255 +256 +257
    -
    # File 'lib/felflame/system_manager.rb', line 199
    +      
    # File 'lib/felflame/system_manager.rb', line 245
     
     def trigger_when_is_changed(component_or_manager, attr)
       if component_or_manager.attr_triggers[attr].nil?
    @@ -1507,14 +1475,14 @@
           
     
     
    -191
    -192
    -193
    -194
    -195
    +237 +238 +239 +240 +241
    -
    # File 'lib/felflame/system_manager.rb', line 191
    +      
    # File 'lib/felflame/system_manager.rb', line 237
     
     def trigger_when_removed(component_or_manager)
       self.removal_triggers |= [component_or_manager]
    @@ -1531,7 +1499,7 @@
     
     
           
    diff --git a/docs/Felflame_.html b/docs/Felflame_.html
    index ea9bbfc..eda8518 100644
    --- a/docs/Felflame_.html
    +++ b/docs/Felflame_.html
    @@ -133,7 +133,7 @@
     
     
           
    diff --git a/docs/_index.html b/docs/_index.html
    index 4b3f2de..a183a99 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 7deb23f..11b0848 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 a77181a..5333a27 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 0efe4fe..d8253e9 100644 --- a/docs/method_list.html +++ b/docs/method_list.html @@ -198,21 +198,13 @@
  • - #const_name - FelFlame::Scenes -
    -
  • - - -
  • -
    - #const_name + const_cache FelFlame::Systems
  • -
  • +
  • #delete FelFlame::Entities @@ -220,7 +212,7 @@
  • -
  • +
  • #delete FelFlame::ComponentManager @@ -228,14 +220,6 @@
  • -
  • -
    - each - FelFlame::Systems -
    -
  • - -
  • #entities @@ -293,6 +277,14 @@
  • +
    + #priority + FelFlame::Scenes +
    +
  • + + +
  • #priority FelFlame::Systems @@ -300,7 +292,7 @@
  • -
  • +
  • #redefine FelFlame::Systems @@ -308,7 +300,7 @@
  • -
  • +
  • #removal_triggers FelFlame::Systems @@ -316,7 +308,7 @@
  • -
  • +
  • #removal_triggers FelFlame::ComponentManager @@ -324,7 +316,7 @@
  • -
  • +
  • removal_triggers FelFlame::ComponentManager @@ -332,7 +324,7 @@
  • -
  • +
  • #remove FelFlame::Scenes @@ -340,7 +332,7 @@
  • -
  • +
  • remove FelFlame::Stage @@ -348,7 +340,7 @@
  • -
  • +
  • #remove FelFlame::Entities @@ -356,7 +348,7 @@
  • -
  • +
  • scenes FelFlame::Stage @@ -364,6 +356,14 @@
  • +
  • +
    + #scenes + FelFlame::Systems +
    +
  • + +
  • #systems diff --git a/docs/top-level-namespace.html b/docs/top-level-namespace.html index 26c3c67..9462bb1 100644 --- a/docs/top-level-namespace.html +++ b/docs/top-level-namespace.html @@ -127,7 +127,7 @@
    diff --git a/lib/felflame/component_manager.rb b/lib/felflame/component_manager.rb index ca5be89..d015d99 100644 --- a/lib/felflame/component_manager.rb +++ b/lib/felflame/component_manager.rb @@ -22,6 +22,7 @@ module FelFlame const_set(component_name, Class.new(FelFlame::ComponentManager) {}) + update_const_cache attrs.each do |attr| if FelFlame::Components.const_get(component_name).method_defined?("#{attr}") || FelFlame::Components.const_get(component_name).method_defined?("#{attr}=") @@ -48,8 +49,51 @@ module FelFlame # Makes component module behave like an array of component # managers with additional methods for managing the array # @!visibility private + ##def respond_to_missing?(method, *) + # if constants.respond_to? method + # true + # else + # super + # end + #end + + ## Makes component module behave like arrays with additional + ## methods for managing the array + ## @!visibility private + #def method_missing(method, *args, **kwargs, &block) + # if constants.respond_to? method + # constants.send(method, *args, **kwargs, &block) + # else + # super + # end + #end + + # Stores the components managers in {FelFlame::Components}. This + # is needed because calling `FelFlame::Components.constants` + # will not let you iterate over the value of the constants + # but will instead give you an array of symbols. This caches + # the convertion of those symbols to the actual value of the + # constants + # @!visibility private + def const_cache + @const_cache || update_const_cache + end + + # Updates the array that stores the constants. + # Used internally by FelFlame + # @!visibility private + def update_const_cache + @const_cache = self.constants.map do |constant| + self.const_get constant + end + end + + # Forwards undefined methods to the array of constants + # if the array can handle the request. Otherwise tells + # the programmer their code errored + # @!visibility private def respond_to_missing?(method, *) - if constants.respond_to? method + if const_cache.respond_to? method true else super @@ -60,12 +104,15 @@ module FelFlame # methods for managing the array # @!visibility private def method_missing(method, *args, **kwargs, &block) - if constants.respond_to? method - constants.send(method, *args, **kwargs, &block) + if const_cache.respond_to? method + const_cache.send(method, *args, **kwargs, &block) else super end end + + + end end diff --git a/lib/felflame/entity_manager.rb b/lib/felflame/entity_manager.rb index 9489f29..2ae0849 100644 --- a/lib/felflame/entity_manager.rb +++ b/lib/felflame/entity_manager.rb @@ -7,14 +7,6 @@ module FelFlame def initialize(*components) # Add each component add(*components) - - # Fancy method redirection for when the `component` method is called - @component_redirect = Object.new - @component_redirect.instance_variable_set(:@entity, self) - @component_redirect.define_singleton_method(:[]) do |component_manager| - instance_variable_get(:@entity).component(component_manager) - end - self.class._data.push self end @@ -32,7 +24,8 @@ module FelFlame # @return [Component] def component(manager = nil) if manager.nil? - @component_redirect + FelFlame::Entities.component_redirect.entity = self + FelFlame::Entities.component_redirect else if components[manager].nil? raise "This entity(#{self}) doesnt have any components of this type: #{manager}" @@ -130,6 +123,30 @@ module FelFlame end end + # Fancy method redirection for when the `component` method is called + # in an Entity + # WARNING: This method will not correctly work with multithreading + # @!visibility private + def component_redirect + if @component_redirect + @component_redirect + else + @component_redirect = Object.new + @component_redirect.instance_variable_set(:@entity, nil) + @component_redirect.define_singleton_method(:entity) do + instance_variable_get(:@entity) + end + @component_redirect.define_singleton_method(:entity=) do |value| + instance_variable_set(:@entity, value) + end + @component_redirect.define_singleton_method(:[]) do |component_manager| + self.entity.component(component_manager) + end + @component_redirect + end + end + + # @return [Array] Array of all Entities that exist # @!visibility private diff --git a/lib/felflame/scene_manager.rb b/lib/felflame/scene_manager.rb index 2b0d714..9ac7924 100644 --- a/lib/felflame/scene_manager.rb +++ b/lib/felflame/scene_manager.rb @@ -12,11 +12,13 @@ module FelFlame def priority=(priority) @priority = priority FelFlame::Stage.scenes = FelFlame::Stage.scenes.sort_by(&:priority) + priority end # Create a new Scene using the name given # @param name [String] String format must follow requirements of a constant - def initialize(name) + def initialize(name, priority: 0) + self.priority = priority FelFlame::Scenes.const_set(name, self) end @@ -41,19 +43,13 @@ module FelFlame systems_to_add.each do |system| system.scenes |= [self] end - #FelFlame::Stage.update_systems_list if FelFlame::Stage.scenes.include? self - #true + true end # Removes any number of Systems from this Scene # @return [Boolean] +true+ def remove(*systems_to_remove) self.systems -= systems_to_remove - self.systems = systems.sort_by(&:priority) - #systems_to_remove.each do |system| - # system.scenes.delete system - #end - #FelFlame::Stage.update_systems_list if FelFlame::Stage.scenes.include? self true end diff --git a/lib/felflame/stage_manager.rb b/lib/felflame/stage_manager.rb index 4ea33da..50dad5f 100644 --- a/lib/felflame/stage_manager.rb +++ b/lib/felflame/stage_manager.rb @@ -10,11 +10,7 @@ module FelFlame # @return [Boolean] +true+ def add(*scenes_to_add) self.scenes |= scenes_to_add - #scenes_to_add.each do |scene| - # self.systems |= scene.systems - #end self.scenes = scenes.sort_by(&:priority) - #self.systems = systems.sort_by(&:priority) true end @@ -22,37 +18,20 @@ module FelFlame # @return [Boolean] +true+ def remove(*scenes_to_remove) self.scenes -= scenes_to_remove - self.scenes = scenes.sort_by(&:priority) - #update_systems_list true end - # Updates the list of systems from the Scenes added to the Stage and make sure they are ordered correctly - # This is used internally by FelFlame and shouldn't need to be ever used by developers - # @return [Boolean] +true+ - # @!visibility private - #def update_systems_list - # systems.clear - # scenes.each do |scene| - # self.systems |= scene.systems - # end - # self.systems = systems.sort_by(&:priority) - # true - #end - # Clears all Scenes that were added to the Stage # @return [Boolean] +true+ def clear - #systems.clear - scenes.clear + self.scenes.clear true end # Executes one frame of the game. This executes all the Systems in the Scenes added to the Stage. Systems that exist in two or more different Scenes will still only get executed once. # @return [Boolean] +true+ def call - #systems.each(&:call) - scenes.each(&:call) + self.scenes.each(&:call) true end @@ -61,13 +40,6 @@ module FelFlame def scenes @scenes ||= [] end - - # Stores systems in the order the stage manager needs to call them - # This method should generally only need to be used internally and not by a game developer - # @!visibility private - #def systems - # @systems ||= [] - #end end end end diff --git a/lib/felflame/system_manager.rb b/lib/felflame/system_manager.rb index ab9b3b3..480b84a 100644 --- a/lib/felflame/system_manager.rb +++ b/lib/felflame/system_manager.rb @@ -53,13 +53,49 @@ module FelFlame end class < 0 expect(FelFlame::Components.each).to be_an Enumerator - FelFlame::Components.each do |component_manager| - all_components.delete component_manager.to_s.to_sym - end - expect(all_components).to eq([]) end it 'can change params on initialization' do @@ -117,17 +123,11 @@ describe 'Components' do expect(@component_manager.first).to eq(@cmp0) 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 'can be accessed' do + expect(@component_manager[0].respond_to? :param1).to eq(true) + expect(@component_manager[1].respond_to? :param1).to eq(true) + expect(@component_manager[2].respond_to? :param1).to eq(true) + end it 'cant overwrite exiting component managers' do FelFlame::Components.new('TestComponent1') diff --git a/spec/entity_manager_spec.rb b/spec/entity_manager_spec.rb index 424b162..0a18495 100644 --- a/spec/entity_manager_spec.rb +++ b/spec/entity_manager_spec.rb @@ -4,10 +4,6 @@ require_relative '../lib/felflame.rb' describe 'Entities' do - #let :component_manager do - # @component_manager ||= FelFlame::Components.new('Test', :param1, param2: 'def') - #end - before :all do $VERBOSE = nil @component_manager ||= FelFlame::Components.new('TestEntity', :param1, param2: 'def') @@ -33,8 +29,6 @@ describe 'Entities' do it 'can get a single component' do expect { @ent0.component[@component_manager] }.to raise_error(RuntimeError) - #$stderr.rewind - #$stderr.string.chomp.should eq("This component belongs to NO entities but you called the method that is intended for components belonging to a single entity.\nYou may have a bug in your logic.") @ent0.add @cmp0 expect(@ent0.component[@component_manager]).to eq(@cmp0) expect(@ent0.component[@component_manager]).to eq(@ent0.component(@component_manager)) @@ -53,6 +47,9 @@ describe 'Entities' do it 'responds to array methods' do expect(FelFlame::Entities.respond_to?(:[])).to be true expect(FelFlame::Entities.respond_to?(:each)).to be true + FelFlame::Entities.each do |entity| + expect(entity.respond_to? :components).to be true + end expect(FelFlame::Entities.respond_to?(:filter)).to be true expect(FelFlame::Entities.respond_to?(:first)).to be true expect(FelFlame::Entities.respond_to?(:last)).to be true @@ -69,21 +66,15 @@ 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 '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(FelFlame::Entities[0].respond_to? :components).to eq(true) + expect(FelFlame::Entities[1].respond_to? :components).to eq(true) + expect(FelFlame::Entities[2].respond_to? :components).to eq(true) + end it 'can have components attached' do @ent0.add @cmp0 - expect(@ent0.components[@component_manager][0]).to eq(@cmp0) + expect(@ent0.component[@component_manager]).to eq(@cmp0) @ent1.add @cmp1, @cmp2 expect(@ent1.components[@component_manager].length).to eq(2) @@ -91,12 +82,6 @@ describe 'Entities' do expect(@ent1.components[@component_manager].include?(@cmp2)).to be true end - #it 'can get id from to_i' do - # expect(@ent0.id).to eq(@ent0.to_i) - # expect(@ent1.id).to eq(@ent1.to_i) - # expect(@ent2.id).to eq(@ent2.to_i) - #end - it 'can have components removed' do @ent0.add @cmp0 expect(@ent0.remove @cmp0).to be true diff --git a/spec/scene_manager_spec.rb b/spec/scene_manager_spec.rb index 0a209a3..3f305b9 100644 --- a/spec/scene_manager_spec.rb +++ b/spec/scene_manager_spec.rb @@ -65,4 +65,8 @@ describe 'Scenes' do @scene.call expect(@cmp.order).to eq([3, 1, 2]) end + + it 'will return priority when setting priority' do + expect(@scene.priority = 3).to eq(3) + end end diff --git a/spec/stage_manager_spec.rb b/spec/stage_manager_spec.rb index 0aa8690..b8fc70c 100644 --- a/spec/stage_manager_spec.rb +++ b/spec/stage_manager_spec.rb @@ -5,36 +5,30 @@ require_relative '../lib/felflame.rb' describe 'Stage' do before :all do @component_manager ||= FelFlame::Components.new('TestStage', order: Array.new) - @system2 = FelFlame::Systems.new('StageTest', priority: 50) do - @component_manager.each do |component| - component.order.push 2 - end + @system2 = FelFlame::Systems.new('StageTest', priority: 1) do + @component_manager.first.order.push 2 end - @system1 = FelFlame::Systems.new('StageMana', priority: 1) do - @component_manager.each do |component| - component.order.push 1 - end + @system1 = FelFlame::Systems.new('StageMana', priority: 3) do + @component_manager.first.order.push 1 end - @system3 = FelFlame::Systems.new('StageSpell', priority: 100) do - @component_manager.each do |component| - component.order.push 3 - end + @system3 = FelFlame::Systems.new('StageSpell', priority: 2) do + @scene1.add @system1 + @scene2.add @system2 + @scene3.add @system3 + @component_manager.first.order.push 3 end - @scene1 = FelFlame::Scenes.new('TestStage1') - @scene2 = FelFlame::Scenes.new('TestStage2') - @scene3 = FelFlame::Scenes.new('TestStage3') + @scene1 = FelFlame::Scenes.new('TestStage1', priority: 1) + @scene2 = FelFlame::Scenes.new('TestStage2', priority: 2) + @scene3 = FelFlame::Scenes.new('TestStage3', priority: 3) end before :each do @cmp = @component_manager.new - @scene1.add @system1 - @scene2.add @system2 - @scene3.add @system3 end after :each do - FelFlame::Entities.each(&:delete) - @component_manager.each(&:delete) + FelFlame::Entities.reverse_each(&:delete) + @component_manager.reverse_each(&:delete) @scene1.clear @scene2.clear @scene3.clear @@ -43,61 +37,28 @@ describe 'Stage' do it 'can add Scenes' do FelFlame::Stage.add @scene2, @scene1, @scene3 - expect(FelFlame::Stage.scenes).to eq([@scene2, @scene1, @scene3]) - expect(FelFlame::Stage.systems).to eq([@system1, @system2, @system3]) + expect(FelFlame::Stage.scenes).to eq([@scene1, @scene2, @scene3]) end it 'can remove Scenes' do FelFlame::Stage.add @scene1, @scene2, @scene3 FelFlame::Stage.remove @scene1, @scene3 expect(FelFlame::Stage.scenes).to eq([@scene2]) - expect(FelFlame::Stage.systems).to eq([@system2]) end it 'can clear Scenes' do FelFlame::Stage.add @scene1, @scene2, @scene3 FelFlame::Stage.clear expect(FelFlame::Stage.scenes).to eq([]) - expect(FelFlame::Stage.systems).to eq([]) - end - - it 'can execute Systems in the correct order' do - FelFlame::Stage.add @scene2, @scene1, @scene3 - FelFlame::Stage.call - expect(@cmp.order).to eq([1, 2, 3]) end - it 'can add Systems to Scenes already added in Stage' do + it 'can call Scenes in correct order' do FelFlame::Stage.add @scene2, @scene1, @scene3 - system2p5 = FelFlame::Systems.new('StageAddingTest', priority: 75) do - @component_manager.each do |component| - component.order.push 2.5 - end - end - @scene2.add system2p5 - @scene3.add system2p5 - FelFlame::Stage.call - expect(@cmp.order).to eq([1,2,2.5,3]) - end - - it 'can remove Systems to Scenes already added in Stage' do - FelFlame::Stage.add @scene2, @scene1, @scene3 - system2p5 = FelFlame::Systems.new('StageAddingTest', priority: 75) do - @component_manager.each do |component| - component.order.push 2.5 - end - end - @scene2.add system2p5 - @scene3.add system2p5 - @scene2.remove @system2 + @scene1.add @system1 + @scene2.add @system2 + @scene3.add @system3 FelFlame::Stage.call - expect(@cmp.order).to eq([1,2.5,3]) + expect(@component_manager.first.order).to eq([1,2,3]) end - it 'can have Systems change priority in an existing Stage' do - FelFlame::Stage.add @scene2, @scene1, @scene3 - @system2.priority = 0 - FelFlame::Stage.call - expect(@cmp.order).to eq([2,1,3]) - end end diff --git a/spec/system_manager_spec.rb b/spec/system_manager_spec.rb index 3d2e3dc..f15ebaa 100644 --- a/spec/system_manager_spec.rb +++ b/spec/system_manager_spec.rb @@ -1,6 +1,6 @@ require_relative '../lib/felflame.rb' -describe 'Components' do +describe 'Systems' do before :all do @component_manager ||= FelFlame::Components.new('TestSystems', health: 10, whatever: 'imp', mana: 10) @@ -23,10 +23,11 @@ describe 'Components' do end it 'can create a system' do - FelFlame::Systems.new('Test99') do + @@testitr += 1 + sys = FelFlame::Systems.new("Test#{@@testitr}") do 'Works' end - expect(FelFlame::Systems::Test99.call).to eq('Works') + expect(sys.call).to eq('Works') end it 'can be redefined' do @@ -36,26 +37,27 @@ describe 'Components' do expect(@system.call).to eq('very neat') end - it 'can iterate over the sorted systems by priority' do - FelFlame::Systems.new('Test2', priority: 1) {} - FelFlame::Systems.new('Test3', priority: 50) {} - FelFlame::Systems.new('Test4', priority: 7) {} - answer_key = ['Test3', 'Test4', 'Test2'] - test = FelFlame::Systems.each.to_a - # converts the system name to the constant, compares their positions making sure they are sorted - # higher priority should be placed first - expect(test.map(&:const_name).find_index(answer_key[0])).to be <= test.map(&:const_name).find_index(answer_key[1]) - expect(test.map(&:const_name).find_index(answer_key[0])).to be <= test.map(&:const_name).find_index(answer_key[2]) - expect(test.map(&:const_name).find_index(answer_key[1])).to be >= test.map(&:const_name).find_index(answer_key[0]) - expect(test.map(&:const_name).find_index(answer_key[1])).to be <= test.map(&:const_name).find_index(answer_key[2]) - expect(test.map(&:const_name).find_index(answer_key[2])).to be >= test.map(&:const_name).find_index(answer_key[0]) - expect(test.map(&:const_name).find_index(answer_key[2])).to be >= test.map(&:const_name).find_index(answer_key[1]) + it 'responds to array methods' do + expect(FelFlame::Systems.respond_to?(:[])).to be true + expect(FelFlame::Systems.respond_to?(:each)).to be true + FelFlame::Systems.each do |system| + expect(system.respond_to? :call).to be true + end + expect(FelFlame::Systems.respond_to?(:filter)).to be true + expect(FelFlame::Systems.respond_to?(:first)).to be true + expect(FelFlame::Systems.respond_to?(:last)).to be true + expect(FelFlame::Systems.respond_to?(:somethingwrong)).to be false + end + + it 'dont respond to missing methods' do + expect { FelFlame::Systems.somethingwrong }.to raise_error(NoMethodError) end it 'can manipulate components' do init1 = 27 init2 = 130 multiple = 3 + iter = 10 first = @component_manager.new(health: init1) second = @component_manager.new(health: init2) @system.redefine do @@ -66,11 +68,11 @@ describe 'Components' do @system.call expect(first.health).to eq(init1 -= multiple) expect(second.health).to eq(init2 -= multiple) - 10.times do + iter.times do @system.call end - expect(first.health).to eq(init1 - (multiple * 10)) - expect(second.health).to eq(init2 - (multiple * 10)) + expect(first.health).to eq(init1 - (multiple * iter)) + expect(second.health).to eq(init2 - (multiple * iter)) end it 'can clear triggers from components and systems' do -- cgit v1.2.3