felflame 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.byebug_history +20 -0
- data/.gitignore +17 -0
- data/.inch.yml +11 -0
- data/.rspec +1 -0
- data/.rubocop.yml +13 -0
- data/.yardopts +13 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +87 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.mdown +410 -0
- data/Rakefile +45 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/codeclimate/export-coverage.rb +16 -0
- data/deprecated/components/00_renderable.rb +19 -0
- data/deprecated/components/01_sprite.rb +57 -0
- data/deprecated/components/02_label.rb +32 -0
- data/deprecated/components/03_player_control.rb +26 -0
- data/deprecated/components/04_map.rb +21 -0
- data/deprecated/components/05_interactable.rb +16 -0
- data/deprecated/components/06_collidable.rb +22 -0
- data/deprecated/components/07_battle.rb +4 -0
- data/deprecated/components/07_indoor.rb +4 -0
- data/deprecated/components/07_overworld.rb +16 -0
- data/deprecated/components/debug_singleton.rb +13 -0
- data/deprecated/helpers/00_tileset.rb +56 -0
- data/deprecated/helpers/01_component.rb +74 -0
- data/deprecated/systems/00_update_levels.rb +34 -0
- data/deprecated/systems/10_player.rb +41 -0
- data/deprecated/systems/99_render.rb +37 -0
- data/docs/CNAME +1 -0
- data/docs/FelFlame.html +317 -0
- data/docs/FelFlame/ComponentManager.html +1627 -0
- data/docs/FelFlame/Components.html +423 -0
- data/docs/FelFlame/Entities.html +1054 -0
- data/docs/FelFlame/Helper.html +142 -0
- data/docs/FelFlame/Helper/ComponentManager.html +1627 -0
- data/docs/FelFlame/Scenes.html +761 -0
- data/docs/FelFlame/Stage.html +598 -0
- data/docs/FelFlame/Systems.html +1541 -0
- data/docs/_index.html +173 -0
- data/docs/class_list.html +51 -0
- data/docs/css/common.css +1 -0
- data/docs/css/full_list.css +58 -0
- data/docs/css/style.css +497 -0
- data/docs/file.README.html +498 -0
- data/docs/file_list.html +56 -0
- data/docs/frames.html +17 -0
- data/docs/index.html +498 -0
- data/docs/js/app.js +314 -0
- data/docs/js/full_list.js +216 -0
- data/docs/js/jquery.js +4 -0
- data/docs/method_list.html +475 -0
- data/docs/top-level-namespace.html +137 -0
- data/felflame.gemspec +45 -0
- data/lib/felflame.rb +59 -0
- data/lib/felflame/component_manager.rb +245 -0
- data/lib/felflame/entity_manager.rb +135 -0
- data/lib/felflame/scene_manager.rb +58 -0
- data/lib/felflame/stage_manager.rb +70 -0
- data/lib/felflame/system_manager.rb +213 -0
- data/lib/felflame/version.rb +5 -0
- data/logos/felflame-logo-text.png +0 -0
- data/logos/felflame-logo-text.svg +172 -0
- data/logos/felflame-logo.png +0 -0
- data/logos/felflame-logo.svg +97 -0
- metadata +239 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c65245c163dfe596ebdfe551070f90cdbb838f852d0b36d349e26b77890b36ba
|
4
|
+
data.tar.gz: 0e2baf45d48d36a2c8d369f345f0f6b80283ac55f210bd637d84dbb3e288a96d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9aa77caa16ca8ef8110f8a16641f784b4869928b91e40dfdc95d609d92e0ab9b3a4c447de88272f10f480e6560af7d7388410712c2b7522eb85c3b189c02dbd1
|
7
|
+
data.tar.gz: f7ae4a1354deefbff45a00719f3a4ce7f40eda46d4f87408b9cfc872373b96669ecad16832dc0b6f1ab95df3440dc5c8f0d90245cf7c6bb995c619057279cca4
|
data/.byebug_history
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
/.bundle/
|
2
|
+
/pkg/
|
3
|
+
/spec/reports/
|
4
|
+
/tmp/
|
5
|
+
|
6
|
+
# Ignore generated coverage
|
7
|
+
coverage/*
|
8
|
+
coverage
|
9
|
+
|
10
|
+
# Ignore yard metadata
|
11
|
+
.yardoc/*
|
12
|
+
.yardoc
|
13
|
+
/_yardoc/
|
14
|
+
|
15
|
+
# Ignore codeclimate executable and env vars
|
16
|
+
codeclimate/env.rb
|
17
|
+
codeclimate/test-reporter-latest-linux-amd64
|
data/.inch.yml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
files:
|
2
|
+
# define files included in the analysis (defaults to ["{app,lib}/**/*.rb"])
|
3
|
+
included:
|
4
|
+
- felflame.rb
|
5
|
+
- component_manager.rb
|
6
|
+
- entity_manager.rb
|
7
|
+
- system_manager.rb
|
8
|
+
- scene_manager.rb
|
9
|
+
- stage_manager.rb
|
10
|
+
# define files excluded from the analysis (defaults to [])
|
11
|
+
excluded:
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/.rubocop.yml
ADDED
data/.yardopts
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
felflame (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ansi (1.5.0)
|
10
|
+
ast (2.4.2)
|
11
|
+
builder (3.2.4)
|
12
|
+
diff-lcs (1.4.4)
|
13
|
+
docile (1.4.0)
|
14
|
+
minitest (5.14.4)
|
15
|
+
minitest-reporters (1.4.3)
|
16
|
+
ansi
|
17
|
+
builder
|
18
|
+
minitest (>= 5.0)
|
19
|
+
ruby-progressbar
|
20
|
+
parallel (1.20.1)
|
21
|
+
parser (3.0.1.1)
|
22
|
+
ast (~> 2.4.1)
|
23
|
+
rainbow (3.0.0)
|
24
|
+
rake (13.0.3)
|
25
|
+
redcarpet (3.5.1)
|
26
|
+
regexp_parser (2.1.1)
|
27
|
+
rexml (3.2.5)
|
28
|
+
rspec (3.10.0)
|
29
|
+
rspec-core (~> 3.10.0)
|
30
|
+
rspec-expectations (~> 3.10.0)
|
31
|
+
rspec-mocks (~> 3.10.0)
|
32
|
+
rspec-core (3.10.1)
|
33
|
+
rspec-support (~> 3.10.0)
|
34
|
+
rspec-expectations (3.10.1)
|
35
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
+
rspec-support (~> 3.10.0)
|
37
|
+
rspec-mocks (3.10.2)
|
38
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
+
rspec-support (~> 3.10.0)
|
40
|
+
rspec-support (3.10.2)
|
41
|
+
rubocop (1.17.0)
|
42
|
+
parallel (~> 1.10)
|
43
|
+
parser (>= 3.0.0.0)
|
44
|
+
rainbow (>= 2.2.2, < 4.0)
|
45
|
+
regexp_parser (>= 1.8, < 3.0)
|
46
|
+
rexml
|
47
|
+
rubocop-ast (>= 1.7.0, < 2.0)
|
48
|
+
ruby-progressbar (~> 1.7)
|
49
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
50
|
+
rubocop-ast (1.7.0)
|
51
|
+
parser (>= 3.0.1.1)
|
52
|
+
ruby-progressbar (1.11.0)
|
53
|
+
simplecov (0.21.2)
|
54
|
+
docile (~> 1.1)
|
55
|
+
simplecov-html (~> 0.11)
|
56
|
+
simplecov_json_formatter (~> 0.1)
|
57
|
+
simplecov-console (0.9.1)
|
58
|
+
ansi
|
59
|
+
simplecov
|
60
|
+
terminal-table
|
61
|
+
simplecov-html (0.12.3)
|
62
|
+
simplecov_json_formatter (0.1.3)
|
63
|
+
terminal-table (3.0.1)
|
64
|
+
unicode-display_width (>= 1.1.1, < 3)
|
65
|
+
unicode-display_width (2.0.0)
|
66
|
+
yard (0.9.26)
|
67
|
+
|
68
|
+
PLATFORMS
|
69
|
+
ruby
|
70
|
+
|
71
|
+
DEPENDENCIES
|
72
|
+
felflame!
|
73
|
+
minitest-reporters (~> 1.4, >= 1.4.3)
|
74
|
+
rake (~> 13.0)
|
75
|
+
redcarpet (~> 3.5, >= 3.5.1)
|
76
|
+
rspec (~> 3.10)
|
77
|
+
rubocop (~> 1.7)
|
78
|
+
simplecov (~> 0.21.2)
|
79
|
+
simplecov-console (~> 0.9.1)
|
80
|
+
simplecov_json_formatter (~> 0.1.3)
|
81
|
+
yard (~> 0.9.26)
|
82
|
+
|
83
|
+
RUBY VERSION
|
84
|
+
ruby 2.7.3p183
|
85
|
+
|
86
|
+
BUNDLED WITH
|
87
|
+
2.1.4
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2021 _Tradam
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 realtradam
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.mdown
ADDED
@@ -0,0 +1,410 @@
|
|
1
|
+
|
2
|
+
![FelFlame](https://filestorage.catgirls.rodeo/images/felflame-logo-smaller-text.png)
|
3
|
+
|
4
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/56d425d9078e98efb74b/maintainability)](https://codeclimate.com/github/realtradam/FelFlame/maintainability)
|
5
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/56d425d9078e98efb74b/test_coverage)](https://codeclimate.com/github/realtradam/FelFlame/test_coverage)
|
6
|
+
[![Inline docs](http://inch-ci.org/github/realtradam/FelFlame.svg?branch=master)](http://inch-ci.org/github/realtradam/FelFlame)
|
7
|
+
[![MIT License](https://img.shields.io/github/license/realtradam/FelFlame?label=license&style=flat)](https://github.com/realtradam/FelFlame/blob/master/LICENSE)
|
8
|
+
[![Ko-Fi](https://img.shields.io/static/v1?message=Buy%20me%20a%20coffee&logo=kofi&labelColor=ff5e5b&color=434B57&logoColor=white&label=%20)](https://ko-fi.com/tradam)
|
9
|
+
|
10
|
+
**[Check out the comprehensive documentation here!](https://felflame.tradam.fyi/)**
|
11
|
+
|
12
|
+
---
|
13
|
+
|
14
|
+
<!-- vim-markdown-toc GFM -->
|
15
|
+
|
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
|
+
+ [Usage](#usage)
|
24
|
+
* [Entities](#entities-1)
|
25
|
+
- [Creation](#creation)
|
26
|
+
- [Accessing](#accessing)
|
27
|
+
- [Get ID](#get-id)
|
28
|
+
- [Adding and Removing Components](#adding-and-removing-components)
|
29
|
+
- [Deletion](#deletion)
|
30
|
+
* [Components](#components-1)
|
31
|
+
- [Creating a Component Manager](#creating-a-component-manager)
|
32
|
+
- [Creating a Component from a Component Manager](#creating-a-component-from-a-component-manager)
|
33
|
+
- [Accessing and Getting ID](#accessing-and-getting-id)
|
34
|
+
- [Accessing Attributes and Changing Them](#accessing-attributes-and-changing-them)
|
35
|
+
- [Deleting Components](#deleting-components)
|
36
|
+
- [Iterating over Components](#iterating-over-components)
|
37
|
+
* [Systems](#systems-1)
|
38
|
+
- [Creation](#creation-1)
|
39
|
+
- [Execution](#execution)
|
40
|
+
- [Alternative Execution](#alternative-execution)
|
41
|
+
- [Clearing Alternative Executions](#clearing-alternative-executions)
|
42
|
+
- [Redefinition](#redefinition)
|
43
|
+
* [Scenes](#scenes-1)
|
44
|
+
- [Creation](#creation-2)
|
45
|
+
- [Accessing](#accessing-1)
|
46
|
+
- [Adding Systems](#adding-systems)
|
47
|
+
- [Removing Systems](#removing-systems)
|
48
|
+
- [Clearing](#clearing)
|
49
|
+
- [Execution](#execution-1)
|
50
|
+
* [Stage](#stage-1)
|
51
|
+
- [Adding Scenes](#adding-scenes)
|
52
|
+
- [Removing Scenes](#removing-scenes)
|
53
|
+
- [Executing](#executing)
|
54
|
+
* [Closing Notes](#closing-notes)
|
55
|
+
+ [Contribution](#contribution)
|
56
|
+
|
57
|
+
<!-- vim-markdown-toc -->
|
58
|
+
|
59
|
+
# What is FelFlame?
|
60
|
+
|
61
|
+
FelFlame is an ECS framework for developing games in the Ruby language. FelFlame has been designed from the ground up with these three ideas in mind:
|
62
|
+
|
63
|
+
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
|
+
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. **Priciple 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
|
+
|
67
|
+
# What is ECS?
|
68
|
+
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.
|
69
|
+
ECS stands for Entity, Component, and System.
|
70
|
+
|
71
|
+
---
|
72
|
+
|
73
|
+
### Components
|
74
|
+
This is where the data or information of a given "object" is stored. There is no logic or code here.
|
75
|
+
|
76
|
+
### Entities
|
77
|
+
Entities will contain one or more Components, but contains no logic or data otherwise
|
78
|
+
|
79
|
+
### Systems
|
80
|
+
Systems are where all the logic or code is kept. There is no data stored in here.
|
81
|
+
|
82
|
+
---
|
83
|
+
|
84
|
+
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
|
+
|
86
|
+
**"But your framework also has `Scenes` and a `Stage`, what is that about?"**
|
87
|
+
|
88
|
+
---
|
89
|
+
|
90
|
+
### Scenes
|
91
|
+
Scenes are simply a collection or subset of Systems. This allows for an easy way to activate and deactivate Systems.
|
92
|
+
|
93
|
+
### Stage
|
94
|
+
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
|
+
|
96
|
+
---
|
97
|
+
|
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
|
+
|
100
|
+
# Usage
|
101
|
+
|
102
|
+
To use FelFlame simply install the gem using `gem install felflame` or using bundler `bundle add felflame` and then require it in your project like so: `require 'felflame'`. Working outside of the gem for rendering engines that do not support the usage of gems is planned a planned feature in the works.
|
103
|
+
|
104
|
+
## Entities
|
105
|
+
|
106
|
+
### Creation
|
107
|
+
Entities are essentially "objects" in the game world. To create a new Entity we do the following:
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
@entity = FelFlame::Entities.new
|
111
|
+
```
|
112
|
+
or if we want to add (any number of)components to it:
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
@entity = FelFlame::Entites.new(FelFlame::Components::Health.new,
|
116
|
+
@component,
|
117
|
+
FelFlame::Components::Armour[7])
|
118
|
+
```
|
119
|
+
|
120
|
+
### Accessing
|
121
|
+
Once components are created we can access them using their ID like so:
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
@entity = FelFlame::Entities[2]
|
125
|
+
```
|
126
|
+
|
127
|
+
### Get ID
|
128
|
+
Entity ID's are generated starting from 0 and ascending, unless if there is a missing ID because of a deleted
|
129
|
+
entity where a new entity will claim that ID. To get the ID of an Entity:
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
@entity.id
|
133
|
+
```
|
134
|
+
|
135
|
+
### Adding and Removing Components
|
136
|
+
We can still add or remove Components from an Entity after it has been created. Here is how:
|
137
|
+
|
138
|
+
```ruby
|
139
|
+
@entity.add @component
|
140
|
+
@entity.remove @component
|
141
|
+
```
|
142
|
+
|
143
|
+
### Deletion
|
144
|
+
To have all Components from an Entity removed and the Entity deleted we do the following:
|
145
|
+
|
146
|
+
```ruby
|
147
|
+
@entity.delete
|
148
|
+
```
|
149
|
+
|
150
|
+
## Components
|
151
|
+
|
152
|
+
### Creating a Component Manager
|
153
|
+
Components are where all the data is stored. The data is stored in variables or accessors in each component.
|
154
|
+
These accessors and their defaults are configured when a component manager is created, like so:
|
155
|
+
|
156
|
+
```ruby
|
157
|
+
@component_manager = FelFlame::Components.new('Stats', :armour, hp: 100)
|
158
|
+
```
|
159
|
+
|
160
|
+
In this example we created a component manager called "Stats".
|
161
|
+
The name given to component managers must follow the same rules for naming constants in ruby for a reason you will shortly see.
|
162
|
+
The parameters following are all creating the attributes we can set.
|
163
|
+
We can set any number of parameters we wish, in this example we define two.
|
164
|
+
The `:armour` parameter is being created without a default, it will equal to `nil` when a new component is created, while `hp` will be equal to 100 when a component is created.
|
165
|
+
When defining attributes symbols should be used.
|
166
|
+
|
167
|
+
### Creating a Component from a Component Manager
|
168
|
+
Now that we have a component manager we can make components from it like so:
|
169
|
+
|
170
|
+
```ruby
|
171
|
+
@component = FelFlame::Components::Stats.new
|
172
|
+
```
|
173
|
+
|
174
|
+
Or we can even change the defaults:
|
175
|
+
|
176
|
+
```ruby
|
177
|
+
@component = FelFlame::Components::Stats.new(armour: 'steel')
|
178
|
+
```
|
179
|
+
|
180
|
+
### Accessing and Getting ID
|
181
|
+
Just like Entities, Components have IDs.
|
182
|
+
These IDs are only unique within the scope of their respective Component Managers.
|
183
|
+
Here is how we can get the ID, as well as how to access a Component from its Component Manager.
|
184
|
+
|
185
|
+
```ruby
|
186
|
+
@component = FelFlame::Components::Stats[2]
|
187
|
+
@component.id # => 2
|
188
|
+
```
|
189
|
+
|
190
|
+
### Accessing Attributes and Changing Them
|
191
|
+
There are a few different ways we can read or change the attributes of a component depending on what our needs are.
|
192
|
+
Here are the ways to edit attrubutes, followed by the ways to read them.
|
193
|
+
```ruby
|
194
|
+
@component.armour = 'Mythril'
|
195
|
+
@component.update_attrs(armour: 'Leather', hp: 95)
|
196
|
+
```
|
197
|
+
```ruby
|
198
|
+
@component.hp # => 95
|
199
|
+
@component.attrs # => {armour: 'Leather', hp: 95}
|
200
|
+
```
|
201
|
+
|
202
|
+
### Deleting Components
|
203
|
+
Deleting a Component is the same format as deleting an Entity. When a Component is deleted referenced to it such as to entities are automatically cleared.
|
204
|
+
|
205
|
+
```ruby
|
206
|
+
@component.delete
|
207
|
+
```
|
208
|
+
|
209
|
+
### Iterating over Components
|
210
|
+
When you make Systems you will want to be able to iterate over all Components of the same Component Manager(for example iterating over all sprites to render them). Here is how we do that:
|
211
|
+
```ruby
|
212
|
+
FelFlame::Components::Sprites.each do |component|
|
213
|
+
#do something with components
|
214
|
+
end
|
215
|
+
```
|
216
|
+
|
217
|
+
## Systems
|
218
|
+
|
219
|
+
### Creation
|
220
|
+
We can create Systems like so:
|
221
|
+
|
222
|
+
```ruby
|
223
|
+
FelFlame::Systems.new(name: 'Render', priority: 2) do
|
224
|
+
# Code and Logic
|
225
|
+
end
|
226
|
+
```
|
227
|
+
|
228
|
+
The name we assign is how we can access the System, like so:
|
229
|
+
|
230
|
+
```ruby
|
231
|
+
FelFlame::Systems::Render
|
232
|
+
```
|
233
|
+
Priority determines the order Systems should be executed, this is used for `Scenes` and the `Stage`.
|
234
|
+
The lower the number, the earlier a given System will be executed.
|
235
|
+
E.g priority 1 will go first, priority 2 will go second, etcetera.
|
236
|
+
|
237
|
+
Often we will want to execute some logic on each Component in a given Component Manager so our code might look like this:
|
238
|
+
|
239
|
+
```ruby
|
240
|
+
FelFlame::Systems.new(name: 'Render', priority: 2) do
|
241
|
+
FelFlame::Components::Sprites.each do |component|
|
242
|
+
# do something with these components
|
243
|
+
end
|
244
|
+
end
|
245
|
+
```
|
246
|
+
|
247
|
+
### Execution
|
248
|
+
After we create a System, it won't do anything on its own until we tell it to. Here is how:
|
249
|
+
|
250
|
+
```ruby
|
251
|
+
FelFlame::Systems::Render.call
|
252
|
+
```
|
253
|
+
|
254
|
+
Sometimes you might want to manually activate a System, but the more common way to have Systems be triggered is to use Scenes and the Stage or the alternative ways of execution.
|
255
|
+
|
256
|
+
### Alternative Execution
|
257
|
+
Sometimes you want a System to automatically trigger when a special even happens. FelFlame can keep track of when a Component is added, removed, or when an attribute is changed and then execute Systems linked to these events. Here is how to create these links:
|
258
|
+
|
259
|
+
```ruby
|
260
|
+
# When this Component is added to an Entity, this System will be called
|
261
|
+
FelFlame::Systems::PassiveRegen.trigger_when_added(@component)
|
262
|
+
|
263
|
+
# When this Component is removed from an Entity, this System will be called
|
264
|
+
FelFlame::Systems::PassiveRegen.trigger_when_removed(@component)
|
265
|
+
|
266
|
+
# When this Component's health attribute is changed, this System will be called
|
267
|
+
FelFlame::Systems::PassiveRegen.trigger_when_is_set(@component, :health)
|
268
|
+
```
|
269
|
+
|
270
|
+
If we want these triggers to happen for all Components that belong to specific Component Manager then we can do that instead:
|
271
|
+
|
272
|
+
```ruby
|
273
|
+
# When a Component from this Component Manager is added to an Entity, this System will be called
|
274
|
+
FelFlame::Systems::PassiveRegen.trigger_when_added(@component_manager)
|
275
|
+
|
276
|
+
# When a Component from this Component Manager is removed from an Entity, this System will be called
|
277
|
+
FelFlame::Systems::PassiveRegen.trigger_when_removed(@component_manager)
|
278
|
+
|
279
|
+
# When this Component's health attribute from this Component Manager is changed, this System will be called
|
280
|
+
FelFlame::Systems::PassiveRegen.trigger_when_is_set(@component_manager, :health)
|
281
|
+
```
|
282
|
+
|
283
|
+
We can create any number of these links between Systems, Components, and Component Manangers as we like, simply call the method again with our other Components and Component Managers
|
284
|
+
|
285
|
+
### Clearing Alternative Executions
|
286
|
+
|
287
|
+
If we wish to remove these links that we created, we can do that using the follwing function in any of the following ways:
|
288
|
+
|
289
|
+
```ruby
|
290
|
+
# clears ALL triggers with this system
|
291
|
+
FelFlame::Systems::PassiveRegen.clear_triggers
|
292
|
+
|
293
|
+
# clears ALL triggers with this Component Manager
|
294
|
+
FelFlame::Systems::PassiveRegen.clear_triggers(@component)
|
295
|
+
|
296
|
+
# clear the 'trigger_when_added' for this Component
|
297
|
+
FelFlame::Systems::PassiveRegen.clear_triggers(@component, :added)
|
298
|
+
|
299
|
+
# clear the 'trigger_when_removed' for this Component
|
300
|
+
FelFlame::Systems::PassiveRegen.clear_triggers(@component, :removed)
|
301
|
+
|
302
|
+
# clear the 'trigger_when_is_set' for this Component specifically for the health attribute
|
303
|
+
FelFlame::Systems::PassiveRegen.clear_triggers(@component, :is_set, :health)
|
304
|
+
```
|
305
|
+
|
306
|
+
Likewise we can do the same with Component Managers:
|
307
|
+
|
308
|
+
```ruby
|
309
|
+
# clears ALL triggers with this Component
|
310
|
+
FelFlame::Systems::PassiveRegen.clear_triggers(@component_manager)
|
311
|
+
|
312
|
+
# clear the 'trigger_when_added' for this Component Manager
|
313
|
+
FelFlame::Systems::PassiveRegen.clear_triggers(@component_manager, :added)
|
314
|
+
|
315
|
+
# clear the 'trigger_when_removed' for this Component Manager
|
316
|
+
FelFlame::Systems::PassiveRegen.clear_triggers(@component_manager, :removed)
|
317
|
+
|
318
|
+
# clear the 'trigger_when_is_set' for this Component Manager specifically for the health attribute
|
319
|
+
FelFlame::Systems::PassiveRegen.clear_triggers(@component_manager, :is_set, :health)
|
320
|
+
```
|
321
|
+
|
322
|
+
### Redefinition
|
323
|
+
|
324
|
+
If we wanted to change what code or logic a given System executes, we could do that with:
|
325
|
+
|
326
|
+
```ruby
|
327
|
+
FelFlame::Systems::PassiveRegen.redefine do
|
328
|
+
# Some new logic or code
|
329
|
+
end
|
330
|
+
```
|
331
|
+
|
332
|
+
## Scenes
|
333
|
+
|
334
|
+
### Creation
|
335
|
+
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:
|
336
|
+
|
337
|
+
```ruby
|
338
|
+
@scene = FelFlame::Scenes.new('ExampleScene')
|
339
|
+
```
|
340
|
+
|
341
|
+
### Accessing
|
342
|
+
Just like other classes in FelFlame, the name we gave the Scene is how we access it:
|
343
|
+
|
344
|
+
```ruby
|
345
|
+
@scene = FelFlame::Scenes::ExampleScene
|
346
|
+
```
|
347
|
+
|
348
|
+
### Adding Systems
|
349
|
+
Adding Systems is simple. We can add as many as we want. In this example we add 3 different systems:
|
350
|
+
|
351
|
+
```ruby
|
352
|
+
FelFlame::Scenes::ExampleScene.add(FelFlame::Systems::Render, @system2, @system3)
|
353
|
+
```
|
354
|
+
|
355
|
+
### Removing Systems
|
356
|
+
Removing Systems works simularly:
|
357
|
+
|
358
|
+
```ruby
|
359
|
+
FelFlame::Scenes::ExampleScene.remove(FelFlame::Systems::Render, @system2, @system3)
|
360
|
+
```
|
361
|
+
|
362
|
+
### Clearing
|
363
|
+
If you want to remove all Systems from a Scene here is how we do it:
|
364
|
+
|
365
|
+
```ruby
|
366
|
+
@scene.clear
|
367
|
+
```
|
368
|
+
|
369
|
+
### Execution
|
370
|
+
To execute all Systems within a scene once we can just do:
|
371
|
+
|
372
|
+
```ruby
|
373
|
+
@scene.call
|
374
|
+
```
|
375
|
+
|
376
|
+
The Scene will make sure that the systems are executed in the correct order based on their given priorities
|
377
|
+
|
378
|
+
## Stage
|
379
|
+
|
380
|
+
### Adding Scenes
|
381
|
+
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:
|
382
|
+
|
383
|
+
```ruby
|
384
|
+
FelFlame::Stage.add FelFlame::Scene::ExampleScene
|
385
|
+
```
|
386
|
+
|
387
|
+
### Removing Scenes
|
388
|
+
Likewise we can remove Scenes:
|
389
|
+
|
390
|
+
```ruby
|
391
|
+
FelFlame::Stage.remove FelFlame::Scene::ExampleScene
|
392
|
+
```
|
393
|
+
|
394
|
+
### Executing
|
395
|
+
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 make sure for you that all the Systems from all Scenes added will be executed in the correct order according to their priority. Here is how we do it:
|
396
|
+
|
397
|
+
```ruby
|
398
|
+
FelFlame::Stage.call
|
399
|
+
```
|
400
|
+
|
401
|
+
## Closing Notes
|
402
|
+
|
403
|
+
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)!
|
404
|
+
|
405
|
+
# Contribution
|
406
|
+
Contributors are welcome! I am always looking to impove the capabilities of game development in Ruby. Feel free to open an issue to discuss a proposed changed or fix. To code a change or fix first fork the project. Next write your changes or fixes. Make sure all your changes and fixes are properly documented using Yard(I will not merge if it is not 100% documented) and make sure everything has tests written for it with Rspec(I will also not merge if it does not have 100% test coverage). Once you have your changes made then simply make a pull request.
|
407
|
+
|
408
|
+
If you need help writing documentation or tests feel free to ask!
|
409
|
+
|
410
|
+
If you want to contribute to development with a thanks you can always [buy me a coffee ;^)](https://ko-fi.com/tradam)
|