felflame 1.0.1 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -2
- data/.ruby-version +1 -0
- data/CHANGELOG.mdown +60 -5
- data/Gemfile +2 -3
- data/Gemfile.lock +4 -4
- data/README.mdown +127 -74
- data/Rakefile +30 -10
- data/bin/console +3 -3
- data/docs/FelFlame/ComponentManager.html +131 -519
- data/docs/FelFlame/Components.html +29 -119
- data/docs/FelFlame/Entities.html +125 -387
- data/docs/FelFlame/Order.html +251 -0
- data/docs/FelFlame/Scenes.html +72 -68
- data/docs/FelFlame/Stage.html +30 -56
- data/docs/FelFlame/Systems.html +208 -244
- data/docs/FelFlame.html +34 -32
- data/docs/Felflame_.html +143 -0
- data/docs/_index.html +24 -4
- data/docs/class_list.html +1 -1
- data/docs/file.README.html +145 -83
- data/docs/file.version.html +74 -0
- data/docs/index.html +145 -83
- data/docs/method_list.html +52 -108
- data/docs/top-level-namespace.html +5 -5
- data/felflame.gemspec +22 -22
- data/lib/felflame/component_manager.rb +99 -71
- data/lib/felflame/entity_manager.rb +84 -59
- data/lib/felflame/order.rb +24 -0
- data/lib/felflame/scene_manager.rb +23 -12
- data/lib/felflame/stage_manager.rb +10 -33
- data/lib/felflame/system_manager.rb +92 -47
- data/lib/felflame/version.rb +5 -1
- data/lib/felflame.rb +23 -15
- metadata +34 -53
- data/.yardopts +0 -13
- data/codeclimate/env.rb +0 -1
- data/codeclimate/export-coverage.rb +0 -16
- data/codeclimate/test-reporter-latest-linux-amd64 +0 -0
- data/deprecated/components/00_renderable.rb +0 -19
- data/deprecated/components/01_sprite.rb +0 -57
- data/deprecated/components/02_label.rb +0 -32
- data/deprecated/components/03_player_control.rb +0 -26
- data/deprecated/components/04_map.rb +0 -21
- data/deprecated/components/05_interactable.rb +0 -16
- data/deprecated/components/06_collidable.rb +0 -22
- data/deprecated/components/07_battle.rb +0 -4
- data/deprecated/components/07_indoor.rb +0 -4
- data/deprecated/components/07_overworld.rb +0 -16
- data/deprecated/components/debug_singleton.rb +0 -13
- data/deprecated/helpers/00_tileset.rb +0 -56
- data/deprecated/helpers/01_component.rb +0 -74
- data/deprecated/systems/00_update_levels.rb +0 -34
- data/deprecated/systems/10_player.rb +0 -41
- data/deprecated/systems/99_render.rb +0 -37
- data/logos/felflame-logo-text.png +0 -0
- data/logos/felflame-logo-text.svg +0 -172
- data/logos/felflame-logo.png +0 -0
- data/logos/felflame-logo.svg +0 -97
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: edb62769a2de8d0770e86a9e1462acf08f0212adcfb5022e77976f787bd8d04f
|
4
|
+
data.tar.gz: 0e6b390b1c35c6ace23cc296dc30aac9389b35fe47a01b31a32aa3375b320f96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e5dc06f74e3cca7da3a1fe93359adee2d224e027156c5d9f1047d21895a3c96791c0f8907fdbf30496b4256be04d645b6f2fd8a8bb69b9a8a2220defcd96b9c
|
7
|
+
data.tar.gz: 9a61a13a77b2ac6196a5405bb614971212bde523f59f85826ef0a4839f78b255947e97ec19c80745df248e90c78bc97589a963f46c609794c41af32fdd4caaa9
|
data/.rubocop.yml
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.3
|
data/CHANGELOG.mdown
CHANGED
@@ -8,11 +8,66 @@
|
|
8
8
|
![Deprecated](https://img.shields.io/badge/-Deprecated-orange)
|
9
9
|
![Removed](https://img.shields.io/badge/-Removed-red)
|
10
10
|
|
11
|
+
## [4.0.0](https://github.com/realtradam/FelFlame/releases/tag/4.0.0) - 2021-12-30
|
12
|
+
![Removed](https://img.shields.io/badge/-Removed-red)
|
13
|
+
- Removed all ids as they were not used
|
14
|
+
|
15
|
+
![Changed](https://img.shields.io/badge/-Changed-yellow)
|
16
|
+
- Scenes now have their own priority attribute
|
17
|
+
- Stages now sort and execute by Scenes, rather then the net Systems in the Scenes
|
18
|
+
- Component method `.attrs` was renamed to `.to_h`
|
19
|
+
- Renamed the `data` accessor to `._data`
|
20
|
+
- Various arrays are automatically compacted
|
21
|
+
|
22
|
+
![Added](https://img.shields.io/badge/-Added-brightgreen)
|
23
|
+
- Classes and Modules which used a data array now have the entire set of array methods available to their respective Classes and Modules
|
24
|
+
- Convenience methods for accessing a single entity in a component(`@component.entity`) and accessing a single entity in a component(`@entity.component[@component_manager]`)
|
25
|
+
- `FelFlame::Order` class which can set the order if your Scenes and Systems
|
26
|
+
|
27
|
+
![Fixed](https://img.shields.io/badge/-Fixed-blue)
|
28
|
+
- Replaced all instances of `sort_by!` with `sort_by` for compatibility with mruby
|
29
|
+
- Minor optimizations such as less array duplication
|
30
|
+
|
31
|
+
## [3.0.0](https://github.com/realtradam/FelFlame/releases/tag/3.0.0) - 2021-07-12
|
32
|
+
![Changed](https://img.shields.io/badge/-Changed-yellow)
|
33
|
+
- The Scene alias was changed from ```FelFlame::Sce``` to ```FelFlame::Scn``` as it is more intuitive
|
34
|
+
|
35
|
+
## [2.0.0](https://github.com/realtradam/FelFlame/releases/tag/2.0.0) - 2021-07-10
|
36
|
+
![Changed](https://img.shields.io/badge/-Changed-yellow)
|
37
|
+
- Entities and Components now reference each other using the objects themselves rather then their id's
|
38
|
+
```ruby
|
39
|
+
# before:
|
40
|
+
@entity.components[@component_manager].each do |component_id|
|
41
|
+
# iterate over id's, usually would need to do a lookup to get the component itself
|
42
|
+
end
|
43
|
+
|
44
|
+
# after:
|
45
|
+
@entity.components[@component_manager].each do |component|
|
46
|
+
# iterate over the components themselves! No need for lookup anymore
|
47
|
+
end
|
48
|
+
```
|
49
|
+
```ruby
|
50
|
+
# same for components referencing entities
|
51
|
+
# before:
|
52
|
+
@component.entities.each do |entity_id|
|
53
|
+
#iterate over id's
|
54
|
+
end
|
55
|
+
|
56
|
+
# after:
|
57
|
+
@component.entities.each do |entity|
|
58
|
+
# directly iterate over entities themselves!
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
62
|
+
|
63
|
+
## [1.0.2](https://github.com/realtradam/FelFlame/releases/tag/1.0.2) - 2021-07-09
|
64
|
+
![Fixed](https://img.shields.io/badge/-Fixed-blue)
|
65
|
+
- Stripped superflous files shrinking gem size significantly
|
66
|
+
|
11
67
|
## [1.0.1](https://github.com/realtradam/FelFlame/releases/tag/1.0.1) - 2021-07-09
|
12
|
-
![Fixed](https://img.shields.io/badge/-Fixed-blue)
|
13
|
-
- Defining attributes in components are no longer allowed to overwrite methods
|
68
|
+
![Fixed](https://img.shields.io/badge/-Fixed-blue)
|
69
|
+
- Defining attributes in components are no longer allowed to overwrite methods
|
14
70
|
|
15
71
|
## [1.0.0](https://github.com/realtradam/FelFlame/releases/tag/1.0.0) - 2021-07-09
|
16
|
-
|
17
|
-
|
18
|
-
- Initial release
|
72
|
+
![Added](https://img.shields.io/badge/-Added-brightgreen)
|
73
|
+
- Initial release
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
felflame (
|
4
|
+
felflame (4.0.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -18,10 +18,10 @@ GEM
|
|
18
18
|
minitest (>= 5.0)
|
19
19
|
ruby-progressbar
|
20
20
|
parallel (1.20.1)
|
21
|
-
parser (3.0.
|
21
|
+
parser (3.0.2.0)
|
22
22
|
ast (~> 2.4.1)
|
23
23
|
rainbow (3.0.0)
|
24
|
-
rake (13.0.
|
24
|
+
rake (13.0.6)
|
25
25
|
redcarpet (3.5.1)
|
26
26
|
regexp_parser (2.1.1)
|
27
27
|
rexml (3.2.5)
|
@@ -38,7 +38,7 @@ GEM
|
|
38
38
|
diff-lcs (>= 1.2.0, < 2.0)
|
39
39
|
rspec-support (~> 3.10.0)
|
40
40
|
rspec-support (3.10.2)
|
41
|
-
rubocop (1.
|
41
|
+
rubocop (1.18.3)
|
42
42
|
parallel (~> 1.10)
|
43
43
|
parser (>= 3.0.0.0)
|
44
44
|
rainbow (>= 2.2.2, < 4.0)
|
data/README.mdown
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
![FelFlame](https://filestorage.catgirls.rodeo/images/felflame-logo-smaller-text.png)
|
1
|
+
![FelFlame](https://raw.githubusercontent.com/realtradam/FelFlame/master/logos/felflame-logo-text.png)
|
2
|
+
<!-- ![FelFlame](https://filestorage.catgirls.rodeo/images/felflame-logo-smaller-text.png) -->
|
3
3
|
|
4
4
|
[![Maintainability](https://api.codeclimate.com/v1/badges/56d425d9078e98efb74b/maintainability)](https://codeclimate.com/github/realtradam/FelFlame/maintainability)
|
5
5
|
[![Test Coverage](https://api.codeclimate.com/v1/badges/56d425d9078e98efb74b/test_coverage)](https://codeclimate.com/github/realtradam/FelFlame/test_coverage)
|
@@ -13,46 +13,49 @@
|
|
13
13
|
|
14
14
|
<!-- vim-markdown-toc GFM -->
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
16
|
+
* [What is FelFlame?](#what-is-felflame)
|
17
|
+
* [What is ECS?](#what-is-ecs)
|
18
|
+
* [Components](#components)
|
19
|
+
* [Entities](#entities)
|
20
|
+
* [Systems](#systems)
|
21
|
+
* [Scenes](#scenes)
|
22
|
+
* [Stage](#stage)
|
23
|
+
* [Order](#order)
|
24
|
+
* [Usage](#usage)
|
24
25
|
* [Entities](#entities-1)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
* [Creation](#creation)
|
27
|
+
* [Accessing](#accessing)
|
28
|
+
* [Adding and Removing Components](#adding-and-removing-components)
|
29
|
+
* [Accessing Entities' Attached Components](#accessing-entities-attached-components)
|
30
|
+
* [Deletion](#deletion)
|
30
31
|
* [Components](#components-1)
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
* [Creating a Component Manager](#creating-a-component-manager)
|
33
|
+
* [Creating a Component from a Component Manager](#creating-a-component-from-a-component-manager)
|
34
|
+
* [Accessing](#accessing-1)
|
35
|
+
* [Accessing Attributes and Changing Them](#accessing-attributes-and-changing-them)
|
36
|
+
* [Deleting Components](#deleting-components)
|
37
|
+
* [Accessing Components' attached Entities](#accessing-components-attached-entities)
|
37
38
|
* [Systems](#systems-1)
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
* [Creation](#creation-1)
|
40
|
+
* [Execution](#execution)
|
41
|
+
* [Alternative Execution](#alternative-execution)
|
42
|
+
* [Clearing Alternative Executions](#clearing-alternative-executions)
|
43
|
+
* [Redefinition](#redefinition)
|
43
44
|
* [Scenes](#scenes-1)
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
* [Creation](#creation-2)
|
46
|
+
* [Accessing](#accessing-2)
|
47
|
+
* [Adding Systems](#adding-systems)
|
48
|
+
* [Removing Systems](#removing-systems)
|
49
|
+
* [Clearing](#clearing)
|
50
|
+
* [Execution](#execution-1)
|
50
51
|
* [Stage](#stage-1)
|
51
|
-
|
52
|
-
|
53
|
-
|
52
|
+
* [Adding Scenes](#adding-scenes)
|
53
|
+
* [Removing Scenes](#removing-scenes)
|
54
|
+
* [Executing](#executing)
|
55
|
+
* [Order](#order-1)
|
56
|
+
* [Setting the order](#setting-the-order)
|
54
57
|
* [Closing Notes](#closing-notes)
|
55
|
-
|
58
|
+
* [Contribution](#contribution)
|
56
59
|
|
57
60
|
<!-- vim-markdown-toc -->
|
58
61
|
|
@@ -62,7 +65,7 @@ FelFlame is an ECS framework for developing games in the Ruby language. FelFlame
|
|
62
65
|
|
63
66
|
1. **Engine Agnostic:** FelFlame has been designed to be rendering engine agnostic as long as the target rendering engine is written in Ruby. This means that this framework can be dropped into existing rendering engines such as [Ruby2D](http://www.ruby2d.com) or [DRGTK](https://dragonruby.org/toolkit/game) with little modifications.
|
64
67
|
2. **Easily Extensible:** FelFlame has been designed such that extensions to its capabilities can be easily added. Extensions such as rendering engine wrappers, premade systems, premade components, etcetera can be easily coded and then distributed as gems.
|
65
|
-
3. **
|
68
|
+
3. **Principle of (My) Least Astonishment:** I want to develop games using a language and framework I love and makes sense to me, inspired by the [Philosophy of the creator of Ruby](https://en.wikipedia.org/wiki/Ruby_(programming_language)#Philosophy).
|
66
69
|
|
67
70
|
# What is ECS?
|
68
71
|
ECS is a software architectural pattern that is used in video game development. Traditionally games were programmed using an object oriented method, while ECS instead attempts to program games using a data oriented method instead.
|
@@ -83,7 +86,7 @@ Systems are where all the logic or code is kept. There is no data stored in here
|
|
83
86
|
|
84
87
|
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.
|
85
88
|
|
86
|
-
**"But your framework also has `Scenes` and
|
89
|
+
**"But your framework also has `Scenes`, `Stage`, and `Order`, what is that about?"**
|
87
90
|
|
88
91
|
---
|
89
92
|
|
@@ -93,13 +96,19 @@ Scenes are simply a collection or subset of Systems. This allows for an easy way
|
|
93
96
|
### Stage
|
94
97
|
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.
|
95
98
|
|
99
|
+
### Order
|
100
|
+
Order is a helper class which can set the priority of Scenes and Systems.
|
101
|
+
|
96
102
|
---
|
97
103
|
|
98
|
-
If all of this sounds very confusing, don't worry. A video tutorial series is in the works where I will build a game using this framework and explain every step of the way. You can also read some examples and explanations below.
|
99
104
|
|
100
105
|
# Usage
|
101
106
|
|
102
|
-
|
107
|
+
There are 2 ways of using FelFlame. You can either `include` it as a gem in your project if your game engine supports this. The other option is to download the single file export of FelFlame and then `require_relative` this file in your project. The single file export takes all the ruby code in the various files and concatenates them into a single file so it is more portable and easy to add.
|
108
|
+
|
109
|
+
To use the gem method you can do the following: install the gem using `gem install felflame` or using bundler `bundle add felflame` and then require it in your project like so: `require 'felflame'`.
|
110
|
+
|
111
|
+
To use the single file export method you simply download the felflame.rb file from the [releases page on Github](https://github.com/realtradam/FelFlame/releases) and add it to your source folder and add a `require relative 'felflame.rb'` line or wherever you have placed the file to use it.
|
103
112
|
|
104
113
|
## Entities
|
105
114
|
|
@@ -109,29 +118,24 @@ Entities are essentially "objects" in the game world. To create a new Entity we
|
|
109
118
|
```ruby
|
110
119
|
@entity = FelFlame::Entities.new
|
111
120
|
```
|
112
|
-
or if we want to add (any number of)components to it:
|
121
|
+
or if we want to add (any number of)components to it when creating it:
|
113
122
|
|
114
123
|
```ruby
|
115
124
|
@entity = FelFlame::Entites.new(
|
116
125
|
FelFlame::Components::Health.new,
|
117
126
|
@component,
|
118
|
-
FelFlame::Components::
|
127
|
+
FelFlame::Components::EnemyTeam.first
|
119
128
|
)
|
120
129
|
```
|
121
130
|
|
122
131
|
### Accessing
|
123
|
-
|
132
|
+
Oftentimes you will not be accessing an Entity this way. Later we will shows you a more common way of accessing entities.
|
133
|
+
If you need to you can access Entities using the `Entities` module:
|
124
134
|
|
125
135
|
```ruby
|
126
136
|
@entity = FelFlame::Entities[2]
|
127
|
-
|
128
|
-
|
129
|
-
### Get ID
|
130
|
-
Entity ID's are generated starting from 0 and ascending, unless if there is a missing ID because of a deleted
|
131
|
-
entity where a new entity will claim that ID. To get the ID of an Entity:
|
132
|
-
|
133
|
-
```ruby
|
134
|
-
@entity.id
|
137
|
+
@entity = FelFlame::Entities.first
|
138
|
+
@entity = FelFlame::Entities.each # you can iterate over all entities this way. Any valid array method can be used
|
135
139
|
```
|
136
140
|
|
137
141
|
### Adding and Removing Components
|
@@ -142,8 +146,19 @@ We can still add or remove Components from an Entity after it has been created.
|
|
142
146
|
@entity.remove @component
|
143
147
|
```
|
144
148
|
|
149
|
+
### Accessing Entities' Attached Components
|
150
|
+
This is the most common way of accessing an Entity
|
151
|
+
|
152
|
+
When Components are added to Entities, they can be accessed from the Entity. By using a Component Manager as a key we can access an array of all components created from that Component Manager that are attached to an entity:
|
153
|
+
|
154
|
+
```ruby
|
155
|
+
@entity.components[@component_manager] # => [@component1, @component2, @component3]
|
156
|
+
```
|
157
|
+
|
145
158
|
### Deletion
|
146
|
-
To have all Components from an Entity removed and the Entity deleted we do the following:
|
159
|
+
To have all Components from an Entity **removed** and the Entity deleted we do the following:
|
160
|
+
|
161
|
+
NOTE: The components will **not be deleted**. They are simply **removed** from the entity and then the entity is destroyed. You must handle component deletion yourself as for example singleton components need to removed instead of deleted.
|
147
162
|
|
148
163
|
```ruby
|
149
164
|
@entity.delete
|
@@ -173,20 +188,19 @@ Now that we have a component manager we can make components from it like so:
|
|
173
188
|
@component = FelFlame::Components::Stats.new
|
174
189
|
```
|
175
190
|
|
176
|
-
Or we can even
|
191
|
+
Or we can even override the defaults when creating the component:
|
177
192
|
|
178
193
|
```ruby
|
179
194
|
@component = FelFlame::Components::Stats.new(armour: 'steel')
|
180
195
|
```
|
181
196
|
|
182
|
-
### Accessing
|
183
|
-
|
184
|
-
These IDs are only unique within the scope of their respective Component Managers.
|
185
|
-
Here is how we can get the ID, as well as how to access a Component from its Component Manager.
|
197
|
+
### Accessing
|
198
|
+
You can access components using any array method.
|
186
199
|
|
187
200
|
```ruby
|
188
201
|
@component = FelFlame::Components::Stats[2]
|
189
|
-
@component
|
202
|
+
@component = FelFlame::Components::Stats.first
|
203
|
+
@component = FelFlame::Components::Stats.each # you can use iterators this way
|
190
204
|
```
|
191
205
|
|
192
206
|
### Accessing Attributes and Changing Them
|
@@ -198,31 +212,36 @@ Here are the ways to edit attrubutes, followed by the ways to read them.
|
|
198
212
|
```
|
199
213
|
```ruby
|
200
214
|
@component.hp # => 95
|
201
|
-
@component.
|
215
|
+
@component.to_h # => {armour: 'Leather', hp: 95}
|
202
216
|
```
|
203
217
|
|
204
218
|
### Deleting Components
|
205
|
-
Deleting a Component is the same
|
219
|
+
Deleting a Component is the same convention as deleting an Entity. When a Component is deleted referenced to it such as to entities are automatically cleared.
|
206
220
|
|
207
221
|
```ruby
|
208
222
|
@component.delete
|
209
223
|
```
|
210
224
|
|
211
|
-
###
|
212
|
-
|
225
|
+
### Accessing Components' attached Entities
|
226
|
+
Components also keep track of what Entities are using it. To access this list we do the following:
|
227
|
+
|
213
228
|
```ruby
|
214
|
-
|
215
|
-
|
216
|
-
|
229
|
+
@component.entities # => [@entity1, @entity2, @entity3]
|
230
|
+
|
231
|
+
# get the first entity attached.
|
232
|
+
# this will throw a warning if there is more or less then
|
233
|
+
# exactly one entity
|
234
|
+
@component.entity # => @entity
|
217
235
|
```
|
218
236
|
|
237
|
+
|
219
238
|
## Systems
|
220
239
|
|
221
240
|
### Creation
|
222
241
|
We can create Systems like so:
|
223
242
|
|
224
243
|
```ruby
|
225
|
-
FelFlame::Systems.new(
|
244
|
+
FelFlame::Systems.new('Render', priority: 2) do
|
226
245
|
# Code and Logic
|
227
246
|
end
|
228
247
|
```
|
@@ -234,12 +253,14 @@ FelFlame::Systems::Render
|
|
234
253
|
```
|
235
254
|
Priority determines the order Systems should be executed, this is used for `Scenes` and the `Stage`.
|
236
255
|
The lower the number, the earlier a given System will be executed.
|
237
|
-
E.g priority 1 will go first, priority 2 will go second, etcetera.
|
256
|
+
E.g priority 1 will go first, priority 2 will go second, etcetera.
|
257
|
+
|
258
|
+
Both Scenes and Systems have a priority. System priority will decide the order it will be called inside of a Scene, which the Scene priority will decide the order it will be called inside of the Stage.
|
238
259
|
|
239
260
|
Often we will want to execute some logic on each Component in a given Component Manager so our code might look like this:
|
240
261
|
|
241
262
|
```ruby
|
242
|
-
FelFlame::Systems.new(
|
263
|
+
FelFlame::Systems.new('Render', priority: 2) do
|
243
264
|
FelFlame::Components::Sprites.each do |component|
|
244
265
|
# do something with these components
|
245
266
|
end
|
@@ -337,7 +358,7 @@ end
|
|
337
358
|
Once we have all the core parts of ECS, we will want to organize our Systems. To do this we will use Scenes to group up Systems so they can quickly be enabled or disabled. Note that [Alternative Executions](#alternative-execution) will occur even if they are not part of a Scene. Here is how we make a new Scene:
|
338
359
|
|
339
360
|
```ruby
|
340
|
-
@scene = FelFlame::Scenes.new('ExampleScene')
|
361
|
+
@scene = FelFlame::Scenes.new('ExampleScene', priority: 5)
|
341
362
|
```
|
342
363
|
|
343
364
|
### Accessing
|
@@ -351,14 +372,22 @@ Just like other classes in FelFlame, the name we gave the Scene is how we access
|
|
351
372
|
Adding Systems is simple. We can add as many as we want. In this example we add 3 different systems:
|
352
373
|
|
353
374
|
```ruby
|
354
|
-
FelFlame::Scenes::ExampleScene.add(
|
375
|
+
FelFlame::Scenes::ExampleScene.add(
|
376
|
+
FelFlame::Systems::Render,
|
377
|
+
@system2,
|
378
|
+
@system3
|
379
|
+
)
|
355
380
|
```
|
356
381
|
|
357
382
|
### Removing Systems
|
358
|
-
Removing Systems works
|
383
|
+
Removing Systems works similarly:
|
359
384
|
|
360
385
|
```ruby
|
361
|
-
FelFlame::Scenes::ExampleScene.remove(
|
386
|
+
FelFlame::Scenes::ExampleScene.remove(
|
387
|
+
FelFlame::Systems::Render,
|
388
|
+
@system2,
|
389
|
+
@system3
|
390
|
+
)
|
362
391
|
```
|
363
392
|
|
364
393
|
### Clearing
|
@@ -380,7 +409,7 @@ The Scene will make sure that the systems are executed in the correct order base
|
|
380
409
|
## Stage
|
381
410
|
|
382
411
|
### Adding Scenes
|
383
|
-
Finally we have the Stage. There is only a single Stage and we do not have to create it as it exists by default. By adding a Scene to the Stage we are saying that the Scene is active. To add a Scene we do the following:
|
412
|
+
Finally we have the Stage. There is only a single Stage and we do not have to create it as it exists by default. By adding a Scene to the Stage we are saying that the Scene is 'active'. To add a Scene we do the following:
|
384
413
|
|
385
414
|
```ruby
|
386
415
|
FelFlame::Stage.add FelFlame::Scene::ExampleScene
|
@@ -394,12 +423,36 @@ FelFlame::Stage.remove FelFlame::Scene::ExampleScene
|
|
394
423
|
```
|
395
424
|
|
396
425
|
### Executing
|
397
|
-
On each frame of the game we want to execute the Stage once. When the Stage is executed it is progressing your game 1 frame forward. The Stage will
|
426
|
+
On each frame of the game generally we will want to execute the Stage once. When the Stage is executed it is progressing your game 1 frame forward. The Stage will call all Scenes you added to it in the order of their priority. Here is how we do it:
|
398
427
|
|
399
428
|
```ruby
|
400
429
|
FelFlame::Stage.call
|
401
430
|
```
|
402
431
|
|
432
|
+
## Order
|
433
|
+
|
434
|
+
### Setting the order
|
435
|
+
|
436
|
+
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
|
437
|
+
|
438
|
+
```ruby
|
439
|
+
FelFlame::Order.sort(
|
440
|
+
@system1,
|
441
|
+
@system2,
|
442
|
+
@system3
|
443
|
+
)
|
444
|
+
```
|
445
|
+
|
446
|
+
If you want some Scenes or Systems to have the same priority then just pass them as an array:
|
447
|
+
|
448
|
+
```ruby
|
449
|
+
FelFlame::Order.sort(
|
450
|
+
@scene1,
|
451
|
+
[@scene2_1, @scene2_2],
|
452
|
+
@scene3
|
453
|
+
)
|
454
|
+
```
|
455
|
+
|
403
456
|
## Closing Notes
|
404
457
|
|
405
458
|
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)!
|
data/Rakefile
CHANGED
@@ -1,15 +1,35 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
3
|
require 'rubygems'
|
4
4
|
require 'bundler/setup'
|
5
5
|
require 'rspec/core/rake_task'
|
6
6
|
require 'yard'
|
7
7
|
require_relative './codeclimate/export-coverage'
|
8
|
-
require
|
9
|
-
require
|
8
|
+
require 'bundler/gem_tasks'
|
9
|
+
require 'rubocop/rake_task'
|
10
|
+
|
11
|
+
task default: [:spec, :yard, 'coverage:format']
|
12
|
+
# task default: :rubocop
|
13
|
+
|
14
|
+
desc 'Export to single file'
|
15
|
+
task :buildfile do
|
16
|
+
result = ''
|
17
|
+
main = File.read('lib/felflame.rb')
|
18
|
+
tmp = main.lines(chomp: true).select do |line|
|
19
|
+
line.include? 'require_relative '
|
20
|
+
end
|
21
|
+
tmp.each do |file|
|
22
|
+
file.delete_prefix!('require_relative ')
|
23
|
+
result += "#{File.read("lib/#{file[1, file.length - 2]}.rb")}\n"
|
24
|
+
end
|
10
25
|
|
11
|
-
|
12
|
-
|
26
|
+
result += main.lines.reject do |line|
|
27
|
+
line.include? 'require_relative '
|
28
|
+
end.join
|
29
|
+
|
30
|
+
`mkdir pkg`
|
31
|
+
File.write('pkg/felflame.rb', result)
|
32
|
+
end
|
13
33
|
|
14
34
|
RuboCop::RakeTask.new
|
15
35
|
|
@@ -26,20 +46,20 @@ namespace :coverage do
|
|
26
46
|
end
|
27
47
|
|
28
48
|
YARD::Rake::YardocTask.new do |t|
|
29
|
-
t.files = ['system_manager.rb', 'component_manager.rb', 'entity_manager.rb', 'scene_manager.rb', 'stage_manager.rb', 'felflame.rb']
|
49
|
+
t.files = ['lib/felflame.rb', 'lib/felflame/*'] # ['system_manager.rb', 'component_manager.rb', 'entity_manager.rb', 'scene_manager.rb', 'stage_manager.rb', 'felflame.rb']
|
30
50
|
t.options = ['--output-dir', './docs', 'yardoc --markup=markdown|textile|rdoc(default)']
|
31
51
|
t.stats_options = ['--list-undoc']
|
32
52
|
end
|
33
53
|
|
34
|
-
#Rake::TestTask.new do |t|
|
54
|
+
# Rake::TestTask.new do |t|
|
35
55
|
# t.pattern = "tests/**/*_test.rb"
|
36
|
-
#end
|
56
|
+
# end
|
37
57
|
|
38
58
|
RSpec::Core::RakeTask.new :spec
|
39
59
|
|
40
60
|
# For installing FelPacks
|
41
|
-
#Gem::Specification.find_all.each do |a_gem|
|
61
|
+
# Gem::Specification.find_all.each do |a_gem|
|
42
62
|
# next unless a_gem.name.include? 'felpack-'
|
43
63
|
#
|
44
64
|
# Dir.glob("#{a_gem.gem_dir}/lib/#{a_gem.name.gsub('-', '/')}/tasks/*.rake").each { |r| load r }
|
45
|
-
#end
|
65
|
+
# end
|
data/bin/console
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'felflame'
|
6
6
|
|
7
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
8
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -11,5 +11,5 @@ require "felflame"
|
|
11
11
|
# require "pry"
|
12
12
|
# Pry.start
|
13
13
|
|
14
|
-
require
|
14
|
+
require 'irb'
|
15
15
|
IRB.start(__FILE__)
|