summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.mdown65
-rw-r--r--README.mdown32
-rw-r--r--docs/FelFlame.html24
-rw-r--r--docs/FelFlame/ComponentManager.html162
-rw-r--r--docs/FelFlame/Components.html2
-rw-r--r--docs/FelFlame/Entities.html2
-rw-r--r--docs/FelFlame/Order.html109
-rw-r--r--docs/FelFlame/Scenes.html2
-rw-r--r--docs/FelFlame/Stage.html2
-rw-r--r--docs/FelFlame/Systems.html2
-rw-r--r--docs/Felflame_.html2
-rw-r--r--docs/_index.html2
-rw-r--r--docs/file.README.html2
-rw-r--r--docs/index.html2
-rw-r--r--docs/method_list.html2
-rw-r--r--docs/top-level-namespace.html2
-rw-r--r--lib/felflame.rb7
-rw-r--r--lib/felflame/component_manager.rb22
-rw-r--r--lib/felflame/order.rb19
-rw-r--r--spec/order_spec.rb71
20 files changed, 366 insertions, 167 deletions
diff --git a/CHANGELOG.mdown b/CHANGELOG.mdown
index e60824f..454c4b8 100644
--- a/CHANGELOG.mdown
+++ b/CHANGELOG.mdown
@@ -14,59 +14,60 @@
![Changed](https://img.shields.io/badge/-Changed-yellow)
- Scenes now have their own priority attribute
- - Stages now sort and execute by Scenes, rather then the net Systems in the Scenes
+- Stages now sort and execute by Scenes, rather then the net Systems in the Scenes
- Component method `.attrs` was renamed to `.to_h`
- Renamed the `data` accessor to `._data`
- Various arrays are automatically compacted
![Added](https://img.shields.io/badge/-Added-brightgreen)
-- Classes and Modules which used a data array now have the entire set of array methods available to their respective Classes and Modules
+ - Classes and Modules which used a data array now have the entire set of array methods available to their respective Classes and Modules
- Convenience methods for accessing a single entity in a component(`@component.entity`) and accessing a single entity in a component(`@entity.component[@component_manager]`)
+ - `FelFlame::Order` class which can set the order if your Scenes and Systems
-![Fixed](https://img.shields.io/badge/-Fixed-blue)
-- Replaced all instances of `sort_by!` with `sort_by` for compatibility with mruby
-- Minor optimizations such as less array duplication
+ ![Fixed](https://img.shields.io/badge/-Fixed-blue)
+ - Replaced all instances of `sort_by!` with `sort_by` for compatibility with mruby
+ - Minor optimizations such as less array duplication
## [3.0.0](https://github.com/realtradam/FelFlame/releases/tag/3.0.0) - 2021-07-12
-![Changed](https://img.shields.io/badge/-Changed-yellow)
-- The Scene alias was changed from ```FelFlame::Sce``` to ```FelFlame::Scn``` as it is more intuitive
+ ![Changed](https://img.shields.io/badge/-Changed-yellow)
+ - The Scene alias was changed from ```FelFlame::Sce``` to ```FelFlame::Scn``` as it is more intuitive
## [2.0.0](https://github.com/realtradam/FelFlame/releases/tag/2.0.0) - 2021-07-10
-![Changed](https://img.shields.io/badge/-Changed-yellow)
-- Entities and Components now reference each other using the objects themselves rather then their id's
-```ruby
+ ![Changed](https://img.shields.io/badge/-Changed-yellow)
+ - Entities and Components now reference each other using the objects themselves rather then their id's
+ ```ruby
# before:
[email protected][@component_manager].each do |component_id|
- # iterate over id's, usually would need to do a lookup to get the component itself
-end
+ @entity.components[@component_manager].each do |component_id|
+# iterate over id's, usually would need to do a lookup to get the component itself
+ end
# after:
[email protected][@component_manager].each do |component|
- # iterate over the components themselves! No need for lookup anymore
-end
-```
-```ruby
+ @entity.components[@component_manager].each do |component|
+# iterate over the components themselves! No need for lookup anymore
+ end
+ ```
+ ```ruby
# same for components referencing entities
# before:
[email protected] do |entity_id|
- #iterate over id's
-end
+ @component.entities.each do |entity_id|
+#iterate over id's
+ end
# after:
[email protected] do |entity|
- # directly iterate over entities themselves!
-end
-```
-
+ @component.entities.each do |entity|
+# directly iterate over entities themselves!
+ end
+ ```
+
## [1.0.2](https://github.com/realtradam/FelFlame/releases/tag/1.0.2) - 2021-07-09
-![Fixed](https://img.shields.io/badge/-Fixed-blue)
-- Stripped superflous files shrinking gem size significantly
+ ![Fixed](https://img.shields.io/badge/-Fixed-blue)
+ - Stripped superflous files shrinking gem size significantly
## [1.0.1](https://github.com/realtradam/FelFlame/releases/tag/1.0.1) - 2021-07-09
-![Fixed](https://img.shields.io/badge/-Fixed-blue)
-- Defining attributes in components are no longer allowed to overwrite methods
+ ![Fixed](https://img.shields.io/badge/-Fixed-blue)
+ - Defining attributes in components are no longer allowed to overwrite methods
## [1.0.0](https://github.com/realtradam/FelFlame/releases/tag/1.0.0) - 2021-07-09
-![Added](https://img.shields.io/badge/-Added-brightgreen)
-- Initial release
+ ![Added](https://img.shields.io/badge/-Added-brightgreen)
+ - Initial release
diff --git a/README.mdown b/README.mdown
index e281b7e..acae578 100644
--- a/README.mdown
+++ b/README.mdown
@@ -20,6 +20,7 @@
* [Systems](#systems)
* [Scenes](#scenes)
* [Stage](#stage)
+ * [Order](#order)
* [Usage](#usage)
* [Entities](#entities-1)
* [Creation](#creation)
@@ -51,6 +52,8 @@
* [Adding Scenes](#adding-scenes)
* [Removing Scenes](#removing-scenes)
* [Executing](#executing)
+ * [Order](#order-1)
+ * [Setting the order](#setting-the-order)
* [Closing Notes](#closing-notes)
* [Contribution](#contribution)
@@ -83,7 +86,7 @@ Systems are where all the logic or code is kept. There is no data stored in here
By using this pattern it allows programmers to easily control what an "object" or entity can do and how much data it needs to have. It avoids the issue of inhertance as no inhertance is ever required in this system. If you need a certain entity to have a certain functionality you just add the relevant component to it, and the systems that automatically go over specific components will give your entitiy the desired functionality.
-**"But your framework also has `Scenes` and a `Stage`, what is that about?"**
+**"But your framework also has `Scenes`, `Stage`, and `Order`, what is that about?"**
---
@@ -93,6 +96,9 @@ Scenes are simply a collection or subset of Systems. This allows for an easy way
### Stage
The Stage is Scenes which are activated. This means any Scenes on the Stage are executed each frame, while the rest of the Systems are not.
+### Order
+Order is a helper class which can set the priority of Scenes and Systems.
+
---
@@ -423,6 +429,30 @@ On each frame of the game generally we will want to execute the Stage once. When
FelFlame::Stage.call
```
+## Order
+
+### Setting the order
+
+To set the order you just need to call `FelFlame::Order.sort` and pass Scenes or Systems in the parameters in the order you wish for them to execute
+
+```ruby
+FelFlame::Order.sort(
+ @system1,
+ @system2,
+ @system3
+)
+```
+
+If you want some Scenes or Systems to have the same priority then just pass them as an array:
+
+```ruby
+FelFlame::Order.sort(
+ @scene1,
+ [@scene2_1, @scene2_2],
+ @scene3
+)
+```
+
## Closing Notes
There are some methods I haven't gone over in the overview. If you want to see everything and read in more detail check out the [Documentation](https://felflame.tradam.fyi)!
diff --git a/docs/FelFlame.html b/docs/FelFlame.html
index 1ec7927..0320860 100644
--- a/docs/FelFlame.html
+++ b/docs/FelFlame.html
@@ -197,6 +197,22 @@
</dt>
<dd><pre class="code"><span class='const'>FelFlame</span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Stage.html" title="FelFlame::Stage (module)">Stage</a></span></span></pre></dd>
+ <dt id="Odr-constant" class="">Odr =
+ <div class="docstring">
+ <div class="discussion">
+ <dl class="rdoc-list note-list"><dt>An alias for {FelFlame
+<dd></dd></dl>
+
+
+ </div>
+</div>
+<div class="tags">
+
+
+</div>
+ </dt>
+ <dd><pre class="code"><span class='const'>FelFlame</span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Order.html" title="FelFlame::Order (module)">Order</a></span></span></pre></dd>
+
</dl>
@@ -273,12 +289,12 @@
<pre class="lines">
-17
18
-19</pre>
+19
+20</pre>
</td>
<td>
- <pre class="code"><span class="info file"># File 'lib/felflame.rb', line 17</span>
+ <pre class="code"><span class="info file"># File 'lib/felflame.rb', line 18</span>
<span class='kw'>def</span> <span class='id identifier rubyid_call'>call</span>
<span class='const'><span class='object_link'><a href="" title="FelFlame (module)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Stage.html" title="FelFlame::Stage (module)">Stage</a></span></span><span class='period'>.</span><span class='id identifier rubyid_call'><span class='object_link'><a href="FelFlame/Stage.html#call-class_method" title="FelFlame::Stage.call (method)">call</a></span></span>
@@ -293,7 +309,7 @@
</div>
<div id="footer">
- Generated on Mon Jan 3 07:34:30 2022 by
+ Generated on Mon Jan 3 08:08:08 2022 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.26 (ruby-2.7.3).
</div>
diff --git a/docs/FelFlame/ComponentManager.html b/docs/FelFlame/ComponentManager.html
index 143fd3a..a29ad10 100644
--- a/docs/FelFlame/ComponentManager.html
+++ b/docs/FelFlame/ComponentManager.html
@@ -507,23 +507,23 @@
<pre class="lines">
-154
-155
-156
-157
-158
-159
-160
-161
-162
-163
-164
-165
-166
-167</pre>
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145</pre>
</td>
<td>
- <pre class="code"><span class="info file"># File 'lib/felflame/component_manager.rb', line 154</span>
+ <pre class="code"><span class="info file"># File 'lib/felflame/component_manager.rb', line 132</span>
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='op'>**</span><span class='id identifier rubyid_attrs'>attrs</span><span class='rparen'>)</span>
<span class='comment'># Prepare the object
@@ -590,12 +590,12 @@
<pre class="lines">
-202
-203
-204</pre>
+180
+181
+182</pre>
</td>
<td>
- <pre class="code"><span class="info file"># File 'lib/felflame/component_manager.rb', line 202</span>
+ <pre class="code"><span class="info file"># File 'lib/felflame/component_manager.rb', line 180</span>
<span class='kw'>def</span> <span class='id identifier rubyid_addition_triggers'>addition_triggers</span>
<span class='ivar'>@addition_triggers</span> <span class='op'>||=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
@@ -646,12 +646,12 @@
<pre class="lines">
-218
-219
-220</pre>
+196
+197
+198</pre>
</td>
<td>
- <pre class="code"><span class="info file"># File 'lib/felflame/component_manager.rb', line 218</span>
+ <pre class="code"><span class="info file"># File 'lib/felflame/component_manager.rb', line 196</span>
<span class='kw'>def</span> <span class='id identifier rubyid_attr_triggers'>attr_triggers</span>
<span class='ivar'>@attr_triggers</span> <span class='op'>||=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
@@ -702,12 +702,12 @@
<pre class="lines">
-210
-211
-212</pre>
+188
+189
+190</pre>
</td>
<td>
- <pre class="code"><span class="info file"># File 'lib/felflame/component_manager.rb', line 210</span>
+ <pre class="code"><span class="info file"># File 'lib/felflame/component_manager.rb', line 188</span>
<span class='kw'>def</span> <span class='id identifier rubyid_removal_triggers'>removal_triggers</span>
<span class='ivar'>@removal_triggers</span> <span class='op'>||=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
@@ -763,12 +763,12 @@
<pre class="lines">
-131
-132
-133</pre>
+109
+110
+111</pre>
</td>
<td>
- <pre class="code"><span class="info file"># File 'lib/felflame/component_manager.rb', line 131</span>
+ <pre class="code"><span class="info file"># File 'lib/felflame/component_manager.rb', line 109</span>
<span class='kw'>def</span> <span class='id identifier rubyid_addition_triggers'>addition_triggers</span>
<span class='ivar'>@addition_triggers</span> <span class='op'>||=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
@@ -819,12 +819,12 @@
<pre class="lines">
-147
-148
-149</pre>
+125
+126
+127</pre>
</td>
<td>
- <pre class="code"><span class="info file"># File 'lib/felflame/component_manager.rb', line 147</span>
+ <pre class="code"><span class="info file"># File 'lib/felflame/component_manager.rb', line 125</span>
<span class='kw'>def</span> <span class='id identifier rubyid_attr_triggers'>attr_triggers</span>
<span class='ivar'>@attr_triggers</span> <span class='op'>||=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
@@ -875,12 +875,12 @@
<pre class="lines">
-139
-140
-141</pre>
+117
+118
+119</pre>
</td>
<td>
- <pre class="code"><span class="info file"># File 'lib/felflame/component_manager.rb', line 139</span>
+ <pre class="code"><span class="info file"># File 'lib/felflame/component_manager.rb', line 117</span>
<span class='kw'>def</span> <span class='id identifier rubyid_removal_triggers'>removal_triggers</span>
<span class='ivar'>@removal_triggers</span> <span class='op'>||=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
@@ -941,22 +941,22 @@
<pre class="lines">
-269
-270
-271
-272
-273
-274
-275
-276
-277
-278
-279
-280
-281</pre>
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259</pre>
</td>
<td>
- <pre class="code"><span class="info file"># File 'lib/felflame/component_manager.rb', line 269</span>
+ <pre class="code"><span class="info file"># File 'lib/felflame/component_manager.rb', line 247</span>
<span class='kw'>def</span> <span class='id identifier rubyid_delete'>delete</span>
<span class='id identifier rubyid_addition_triggers'>addition_triggers</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_system'>system</span><span class='op'>|</span>
@@ -1015,12 +1015,12 @@
<pre class="lines">
-231
-232
-233</pre>
+209
+210
+211</pre>
</td>
<td>
- <pre class="code"><span class="info file"># File 'lib/felflame/component_manager.rb', line 231</span>
+ <pre class="code"><span class="info file"># File 'lib/felflame/component_manager.rb', line 209</span>
<span class='kw'>def</span> <span class='id identifier rubyid_entities'>entities</span>
<span class='ivar'>@entities</span> <span class='op'>||=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
@@ -1069,17 +1069,17 @@
<pre class="lines">
-237
-238
-239
-240
-241
-242
-243
-244</pre>
+215
+216
+217
+218
+219
+220
+221
+222</pre>
</td>
<td>
- <pre class="code"><span class="info file"># File 'lib/felflame/component_manager.rb', line 237</span>
+ <pre class="code"><span class="info file"># File 'lib/felflame/component_manager.rb', line 215</span>
<span class='kw'>def</span> <span class='id identifier rubyid_entity'>entity</span>
<span class='kw'>if</span> <span class='id identifier rubyid_entities'>entities</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span>
@@ -1138,16 +1138,16 @@
<pre class="lines">
-284
-285
-286
-287
-288
-289
-290</pre>
+262
+263
+264
+265
+266
+267
+268</pre>
</td>
<td>
- <pre class="code"><span class="info file"># File 'lib/felflame/component_manager.rb', line 284</span>
+ <pre class="code"><span class="info file"># File 'lib/felflame/component_manager.rb', line 262</span>
<span class='kw'>def</span> <span class='id identifier rubyid_to_h'>to_h</span>
<span class='id identifier rubyid_return_hash'>return_hash</span> <span class='op'>=</span> <span class='id identifier rubyid_instance_variables'>instance_variables</span><span class='period'>.</span><span class='id identifier rubyid_each_with_object'>each_with_object</span><span class='lparen'>(</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_final'>final</span><span class='op'>|</span>
@@ -1205,14 +1205,14 @@
<pre class="lines">
-248
-249
-250
-251
-252</pre>
+226
+227
+228
+229
+230</pre>
</td>
<td>
- <pre class="code"><span class="info file"># File 'lib/felflame/component_manager.rb', line 248</span>
+ <pre class="code"><span class="info file"># File 'lib/felflame/component_manager.rb', line 226</span>
<span class='kw'>def</span> <span class='id identifier rubyid_update_attrs'>update_attrs</span><span class='lparen'>(</span><span class='op'>**</span><span class='id identifier rubyid_opts'>opts</span><span class='rparen'>)</span>
<span class='id identifier rubyid_opts'>opts</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='op'>|</span>
@@ -1229,7 +1229,7 @@
</div>
<div id="footer">
- Generated on Mon Jan 3 07:34:30 2022 by
+ Generated on Mon Jan 3 08:08:08 2022 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.26 (ruby-2.7.3).
</div>
diff --git a/docs/FelFlame/Components.html b/docs/FelFlame/Components.html
index 37c11bf..43a84f0 100644
--- a/docs/FelFlame/Components.html
+++ b/docs/FelFlame/Components.html
@@ -323,7 +323,7 @@
</div>
<div id="footer">
- Generated on Mon Jan 3 07:34:30 2022 by
+ Generated on Mon Jan 3 08:08:08 2022 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.26 (ruby-2.7.3).
</div>
diff --git a/docs/FelFlame/Entities.html b/docs/FelFlame/Entities.html
index 43d61fa..f7ae79a 100644
--- a/docs/FelFlame/Entities.html
+++ b/docs/FelFlame/Entities.html
@@ -782,7 +782,7 @@
</div>
<div id="footer">
- Generated on Mon Jan 3 07:34:30 2022 by
+ Generated on Mon Jan 3 08:08:08 2022 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.26 (ruby-2.7.3).
</div>
diff --git a/docs/FelFlame/Order.html b/docs/FelFlame/Order.html
index b17a786..e55ce58 100644
--- a/docs/FelFlame/Order.html
+++ b/docs/FelFlame/Order.html
@@ -78,12 +78,25 @@
<dl>
<dt>Defined in:</dt>
- <dd>lib/felflame/order.rb</dd>
+ <dd>lib/felflame.rb<span class="defines">,<br />
+ lib/felflame/order.rb</span>
+</dd>
</dl>
</div>
+<h2>Overview</h2><div class="docstring">
+ <div class="discussion">
+
+<p>Sets the priority of a list of Systems or Scenes for you in the order you pass them to this class.</p>
+
+
+ </div>
+</div>
+<div class="tags">
+
+</div>
@@ -92,7 +105,7 @@
<h2>
- Instance Method Summary
+ Class Method Summary
<small><a href="#" class="summary_toggle">collapse</a></small>
</h2>
@@ -101,7 +114,7 @@
<li class="public ">
<span class="summary_signature">
- <a href="#sort-instance_method" title="#sort (instance method)">#<strong>sort</strong>(*sortables) &#x21d2; Object </a>
+ <a href="#sort-class_method" title="sort (class method)">.<strong>sort</strong>(*sortables) &#x21d2; Boolean </a>
@@ -115,7 +128,9 @@
- <span class="summary_desc"><div class='inline'></div></span>
+ <span class="summary_desc"><div class='inline'>
+<p>Sets the priority of all items passed into this method according to the order they were passed.</p>
+</div></span>
</li>
@@ -125,32 +140,96 @@
- <div id="instance_method_details" class="method_details_list">
- <h2>Instance Method Details</h2>
+ <div id="class_method_details" class="method_details_list">
+ <h2>Class Method Details</h2>
<div class="method_details first">
- <h3 class="signature first" id="sort-instance_method">
+ <h3 class="signature first" id="sort-class_method">
+
+ .<strong>sort</strong>(*sortables) &#x21d2; <tt>Boolean</tt>
- #<strong>sort</strong>(*sortables) &#x21d2; <tt>Object</tt>
+
+
+
+</h3><div class="docstring">
+ <div class="discussion">
+
+<p>Sets the priority of all items passed into this method according to the order they were passed. If an array is one of the elements then it will give all of those elements in the array the same priority.</p>
+
+ </div>
+</div>
+<div class="tags">
+ <p class="tag_title">Parameters:</p>
+<ul class="param">
+
+ <li>
+
+ <span class='name'>sortables</span>
+
+
+ <span class='type'>(<tt>(<span class='object_link'><a href="Systems.html" title="FelFlame::Systems (class)">Systems</a></span> and Array&lt;<span class='object_link'><a href="Systems.html" title="FelFlame::Systems (class)">Systems</a></span>&gt;) or (<span class='object_link'><a href="Scenes.html" title="FelFlame::Scenes (class)">Scenes</a></span> and Array&lt;<span class='object_link'><a href="Scenes.html" title="FelFlame::Scenes (class)">Scenes</a></span>&gt;)</tt>)</span>
+
+
+
+ </li>
+</ul>
+<p class="tag_title">Returns:</p>
+<ul class="return">
+
+ <li>
+
+
+ <span class='type'>(<tt>Boolean</tt>)</span>
+
+
+
+ &mdash;
+ <div class='inline'>
+<p><code>true</code>.</p>
+</div>
+
+ </li>
-</h3><table class="source_code">
+</ul>
+
+</div><table class="source_code">
<tr>
<td>
<pre class="lines">
-3
-4</pre>
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21</pre>
</td>
<td>
- <pre class="code"><span class="info file"># File 'lib/felflame/order.rb', line 3</span>
-
-<span class='kw'>def</span> <span class='id identifier rubyid_sort'>sort</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_sortables'>sortables</span><span class='rparen'>)</span>
+ <pre class="code"><span class="info file"># File 'lib/felflame/order.rb', line 10</span>
+
+<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_sort'>sort</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_sortables'>sortables</span><span class='rparen'>)</span>
+ <span class='id identifier rubyid_sortables'>sortables</span><span class='period'>.</span><span class='id identifier rubyid_each_with_index'>each_with_index</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_sorted'>sorted</span><span class='comma'>,</span> <span class='id identifier rubyid_index'>index</span><span class='op'>|</span>
+ <span class='kw'>if</span> <span class='id identifier rubyid_sorted'>sorted</span><span class='period'>.</span><span class='id identifier rubyid_respond_to?'>respond_to?</span> <span class='symbol'>:priority</span>
+ <span class='id identifier rubyid_sorted'>sorted</span><span class='period'>.</span><span class='id identifier rubyid_priority'>priority</span> <span class='op'>=</span> <span class='id identifier rubyid_index'>index</span>
+ <span class='kw'>else</span>
+ <span class='id identifier rubyid_sorted'>sorted</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_item'>item</span><span class='op'>|</span>
+ <span class='id identifier rubyid_item'>item</span><span class='period'>.</span><span class='id identifier rubyid_priority'>priority</span> <span class='op'>=</span> <span class='id identifier rubyid_index'>index</span>
+ <span class='kw'>end</span>
+ <span class='kw'>end</span>
+ <span class='kw'>end</span>
+ <span class='kw'>true</span>
<span class='kw'>end</span></pre>
</td>
</tr>
@@ -162,7 +241,7 @@
</div>
<div id="footer">
- Generated on Mon Jan 3 07:34:30 2022 by
+ Generated on Mon Jan 3 08:08:08 2022 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.26 (ruby-2.7.3).
</div>
diff --git a/docs/FelFlame/Scenes.html b/docs/FelFlame/Scenes.html
index 6245fa6..fd224e6 100644
--- a/docs/FelFlame/Scenes.html
+++ b/docs/FelFlame/Scenes.html
@@ -755,7 +755,7 @@
</div>
<div id="footer">
- Generated on Mon Jan 3 07:34:30 2022 by
+ Generated on Mon Jan 3 08:08:08 2022 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.26 (ruby-2.7.3).
</div>
diff --git a/docs/FelFlame/Stage.html b/docs/FelFlame/Stage.html
index e944f44..2acb4cb 100644
--- a/docs/FelFlame/Stage.html
+++ b/docs/FelFlame/Stage.html
@@ -562,7 +562,7 @@
</div>
<div id="footer">
- Generated on Mon Jan 3 07:34:30 2022 by
+ Generated on Mon Jan 3 08:08:08 2022 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.26 (ruby-2.7.3).
</div>
diff --git a/docs/FelFlame/Systems.html b/docs/FelFlame/Systems.html
index be6a374..4fe103e 100644
--- a/docs/FelFlame/Systems.html
+++ b/docs/FelFlame/Systems.html
@@ -1495,7 +1495,7 @@
</div>
<div id="footer">
- Generated on Mon Jan 3 07:34:30 2022 by
+ Generated on Mon Jan 3 08:08:08 2022 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.26 (ruby-2.7.3).
</div>
diff --git a/docs/Felflame_.html b/docs/Felflame_.html
index ac59bac..ee0ed1d 100644
--- a/docs/Felflame_.html
+++ b/docs/Felflame_.html
@@ -133,7 +133,7 @@
</div>
<div id="footer">
- Generated on Mon Jan 3 07:34:30 2022 by
+ Generated on Mon Jan 3 08:08:08 2022 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.26 (ruby-2.7.3).
</div>
diff --git a/docs/_index.html b/docs/_index.html
index d3becf8..e2c0548 100644
--- a/docs/_index.html
+++ b/docs/_index.html
@@ -183,7 +183,7 @@
</div>
<div id="footer">
- Generated on Mon Jan 3 07:34:30 2022 by
+ Generated on Mon Jan 3 08:08:07 2022 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.26 (ruby-2.7.3).
</div>
diff --git a/docs/file.README.html b/docs/file.README.html
index 8565de7..e075115 100644
--- a/docs/file.README.html
+++ b/docs/file.README.html
@@ -518,7 +518,7 @@ E.g priority 1 will go first, priority 2 will go second, etcetera. </p>
</div></div>
<div id="footer">
- Generated on Mon Jan 3 07:34:30 2022 by
+ Generated on Mon Jan 3 08:08:08 2022 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.26 (ruby-2.7.3).
</div>
diff --git a/docs/index.html b/docs/index.html
index 916cce2..38b9106 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -518,7 +518,7 @@ E.g priority 1 will go first, priority 2 will go second, etcetera. </p>
</div></div>
<div id="footer">
- Generated on Mon Jan 3 07:34:30 2022 by
+ Generated on Mon Jan 3 08:08:07 2022 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.26 (ruby-2.7.3).
</div>
diff --git a/docs/method_list.html b/docs/method_list.html
index e0c8da1..5f38f92 100644
--- a/docs/method_list.html
+++ b/docs/method_list.html
@@ -358,7 +358,7 @@
<li class="even ">
<div class="item">
- <span class='object_link'><a href="FelFlame/Order.html#sort-instance_method" title="FelFlame::Order#sort (method)">#sort</a></span>
+ <span class='object_link'><a href="FelFlame/Order.html#sort-class_method" title="FelFlame::Order.sort (method)">sort</a></span>
<small>FelFlame::Order</small>
</div>
</li>
diff --git a/docs/top-level-namespace.html b/docs/top-level-namespace.html
index 78ec112..0a054fc 100644
--- a/docs/top-level-namespace.html
+++ b/docs/top-level-namespace.html
@@ -127,7 +127,7 @@
</div>
<div id="footer">
- Generated on Mon Jan 3 07:34:30 2022 by
+ Generated on Mon Jan 3 08:08:08 2022 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.26 (ruby-2.7.3).
</div>
diff --git a/lib/felflame.rb b/lib/felflame.rb
index b7a386a..21a6eaf 100644
--- a/lib/felflame.rb
+++ b/lib/felflame.rb
@@ -5,6 +5,7 @@ require_relative 'felflame/component_manager'
require_relative 'felflame/system_manager'
require_relative 'felflame/scene_manager'
require_relative 'felflame/stage_manager'
+require_relative 'felflame/order'
require_relative 'felflame/version'
@@ -39,6 +40,9 @@ module FelFlame
# Stores Scenes you add to it which you want to execute on each frame. When called upon will execute all Systems in the Scenes in the Stage and will execute them according to their priority order.
module Stage; end
+
+ # Sets the priority of a list of Systems or Scenes for you in the order you pass them to this class.
+ module Order; end
end
# An alias for {FelFlame}
@@ -58,3 +62,6 @@ FF::Scn = FelFlame::Scenes
# An alias for {FelFlame::Stage}
FF::Stg = FelFlame::Stage
+
+# An alias for {FelFlame::
+FF::Odr = FelFlame::Order
diff --git a/lib/felflame/component_manager.rb b/lib/felflame/component_manager.rb
index 04faccb..6ac7463 100644
--- a/lib/felflame/component_manager.rb
+++ b/lib/felflame/component_manager.rb
@@ -48,28 +48,6 @@ module FelFlame
FelFlame::Components.const_get(component_name)
end
- # 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
diff --git a/lib/felflame/order.rb b/lib/felflame/order.rb
index 0bed66b..3202b25 100644
--- a/lib/felflame/order.rb
+++ b/lib/felflame/order.rb
@@ -1,6 +1,23 @@
module FelFlame
module Order
- def sort(*sortables)
+
+ # Sets the priority of all items passed into this method
+ # according to the order they were passed.
+ # If an array is one of the elements then it will give all
+ # of those elements in the array the same priority.
+ # @param sortables [(Systems and Array<Systems>) or (Scenes and Array<Scenes>)]
+ # @return [Boolean] +true+.
+ def self.sort(*sortables)
+ sortables.each_with_index do |sorted, index|
+ if sorted.respond_to? :priority
+ sorted.priority = index
+ else
+ sorted.each do |item|
+ item.priority = index
+ end
+ end
+ end
+ true
end
end
end
diff --git a/spec/order_spec.rb b/spec/order_spec.rb
new file mode 100644
index 0000000..2dfe7a6
--- /dev/null
+++ b/spec/order_spec.rb
@@ -0,0 +1,71 @@
+# frozen_string_literal: true
+
+require_relative '../lib/felflame'
+
+# class EntitiesTest < Minitest::Test
+
+describe 'Order' do
+ before :all do
+ @result = []
+ @system0 = FelFlame::Systems.new('System1', priority: 0) do
+ @result.push 0
+ end
+ @system2 = FelFlame::Systems.new('System3', priority: 2) do
+ @result.push 2
+ end
+ @system1 = FelFlame::Systems.new('System2', priority: 1) do
+ @result.push 1
+ end
+
+ @scene1 = FelFlame::Scenes.new('Scene0', priority: 1)
+ @scene0 = FelFlame::Scenes.new('Scene0', priority: 0)
+ end
+
+ before :each do
+ end
+
+ after :each do
+ @result.clear
+ @scene0.clear
+ @scene1.clear
+ @system0.priority = 0
+ @system1.priority = 1
+ @system2.priority = 2
+ @scene0.priority = 0
+ @scene1.priority = 1
+ end
+
+ it 'can sort Scenes' do
+ @scene0.add @system0
+ @scene1.add @system1
+ FelFlame::Order.sort(
+ @scene1,
+ @scene0
+ )
+ expect(@scene1.priority < @scene0.priority).to eq(true)
+ end
+
+ it 'can sort Systems' do
+ @scene0.add @system0, @system1, @system2
+ FelFlame::Order.sort(
+ @system2,
+ @system0,
+ @system1
+ )
+ @scene0.call
+ expect(@result).to eq([2,0,1])
+ end
+
+ it 'can handle array' do
+ FelFlame::Order.sort(
+ @system0,
+ [
+ @system1,
+ @system2
+ ]
+ )
+ expect(@system0.priority < @system1.priority).to eq(true)
+ expect(@system0.priority < @system2.priority).to eq(true)
+ expect(@system1.priority == @system2.priority).to eq(true)
+ end
+end