felflame 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +7 -0
  2. data/.byebug_history +20 -0
  3. data/.gitignore +17 -0
  4. data/.inch.yml +11 -0
  5. data/.rspec +1 -0
  6. data/.rubocop.yml +13 -0
  7. data/.yardopts +13 -0
  8. data/CHANGELOG.md +5 -0
  9. data/Gemfile +11 -0
  10. data/Gemfile.lock +87 -0
  11. data/LICENSE +21 -0
  12. data/LICENSE.txt +21 -0
  13. data/README.mdown +410 -0
  14. data/Rakefile +45 -0
  15. data/bin/console +15 -0
  16. data/bin/setup +8 -0
  17. data/codeclimate/export-coverage.rb +16 -0
  18. data/deprecated/components/00_renderable.rb +19 -0
  19. data/deprecated/components/01_sprite.rb +57 -0
  20. data/deprecated/components/02_label.rb +32 -0
  21. data/deprecated/components/03_player_control.rb +26 -0
  22. data/deprecated/components/04_map.rb +21 -0
  23. data/deprecated/components/05_interactable.rb +16 -0
  24. data/deprecated/components/06_collidable.rb +22 -0
  25. data/deprecated/components/07_battle.rb +4 -0
  26. data/deprecated/components/07_indoor.rb +4 -0
  27. data/deprecated/components/07_overworld.rb +16 -0
  28. data/deprecated/components/debug_singleton.rb +13 -0
  29. data/deprecated/helpers/00_tileset.rb +56 -0
  30. data/deprecated/helpers/01_component.rb +74 -0
  31. data/deprecated/systems/00_update_levels.rb +34 -0
  32. data/deprecated/systems/10_player.rb +41 -0
  33. data/deprecated/systems/99_render.rb +37 -0
  34. data/docs/CNAME +1 -0
  35. data/docs/FelFlame.html +317 -0
  36. data/docs/FelFlame/ComponentManager.html +1627 -0
  37. data/docs/FelFlame/Components.html +423 -0
  38. data/docs/FelFlame/Entities.html +1054 -0
  39. data/docs/FelFlame/Helper.html +142 -0
  40. data/docs/FelFlame/Helper/ComponentManager.html +1627 -0
  41. data/docs/FelFlame/Scenes.html +761 -0
  42. data/docs/FelFlame/Stage.html +598 -0
  43. data/docs/FelFlame/Systems.html +1541 -0
  44. data/docs/_index.html +173 -0
  45. data/docs/class_list.html +51 -0
  46. data/docs/css/common.css +1 -0
  47. data/docs/css/full_list.css +58 -0
  48. data/docs/css/style.css +497 -0
  49. data/docs/file.README.html +498 -0
  50. data/docs/file_list.html +56 -0
  51. data/docs/frames.html +17 -0
  52. data/docs/index.html +498 -0
  53. data/docs/js/app.js +314 -0
  54. data/docs/js/full_list.js +216 -0
  55. data/docs/js/jquery.js +4 -0
  56. data/docs/method_list.html +475 -0
  57. data/docs/top-level-namespace.html +137 -0
  58. data/felflame.gemspec +45 -0
  59. data/lib/felflame.rb +59 -0
  60. data/lib/felflame/component_manager.rb +245 -0
  61. data/lib/felflame/entity_manager.rb +135 -0
  62. data/lib/felflame/scene_manager.rb +58 -0
  63. data/lib/felflame/stage_manager.rb +70 -0
  64. data/lib/felflame/system_manager.rb +213 -0
  65. data/lib/felflame/version.rb +5 -0
  66. data/logos/felflame-logo-text.png +0 -0
  67. data/logos/felflame-logo-text.svg +172 -0
  68. data/logos/felflame-logo.png +0 -0
  69. data/logos/felflame-logo.svg +97 -0
  70. metadata +239 -0
@@ -0,0 +1,137 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>
7
+ Top Level Namespace
8
+
9
+ &mdash; Documentation by YARD 0.9.26
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" />
14
+
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" />
16
+
17
+ <script type="text/javascript">
18
+ pathId = "";
19
+ relpath = '';
20
+ </script>
21
+
22
+
23
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
24
+
25
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
26
+
27
+
28
+ </head>
29
+ <body>
30
+ <div class="nav_wrap">
31
+ <iframe id="nav" src="class_list.html?1"></iframe>
32
+ <div id="resizer"></div>
33
+ </div>
34
+
35
+ <div id="main" tabindex="-1">
36
+ <div id="header">
37
+ <div id="menu">
38
+
39
+ <a href="_index.html">Index</a> &raquo;
40
+
41
+
42
+ <span class="title">Top Level Namespace</span>
43
+
44
+ </div>
45
+
46
+ <div id="search">
47
+
48
+ <a class="full_list_link" id="class_list_link"
49
+ href="class_list.html">
50
+
51
+ <svg width="24" height="24">
52
+ <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
53
+ <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
54
+ <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
55
+ </svg>
56
+ </a>
57
+
58
+ </div>
59
+ <div class="clear"></div>
60
+ </div>
61
+
62
+ <div id="content"><h1>Top Level Namespace
63
+
64
+
65
+
66
+ </h1>
67
+ <div class="box_info">
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+ </div>
80
+
81
+ <h2>Defined Under Namespace</h2>
82
+ <p class="children">
83
+
84
+
85
+
86
+
87
+ <strong class="classes">Classes:</strong> <span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span>
88
+
89
+
90
+ </p>
91
+
92
+
93
+ <h2>
94
+ Constant Summary
95
+ <small><a href="#" class="constants_summary_toggle">collapse</a></small>
96
+ </h2>
97
+
98
+ <dl class="constants">
99
+
100
+ <dt id="FF-constant" class="">FF =
101
+ <div class="docstring">
102
+ <div class="discussion">
103
+
104
+ <p>An alias for <span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></p>
105
+
106
+
107
+ </div>
108
+ </div>
109
+ <div class="tags">
110
+
111
+
112
+ </div>
113
+ </dt>
114
+ <dd><pre class="code"><span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span></pre></dd>
115
+
116
+ </dl>
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+ </div>
128
+
129
+ <div id="footer">
130
+ Generated on Fri Jul 9 01:56:53 2021 by
131
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
132
+ 0.9.26 (ruby-2.7.3).
133
+ </div>
134
+
135
+ </div>
136
+ </body>
137
+ </html>
data/felflame.gemspec ADDED
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/felflame/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "felflame"
7
+ spec.version = Felflame::VERSION
8
+ spec.authors = ["Tradam"]
9
+ spec.email = ["felflame@tradam.dev"]
10
+
11
+ spec.summary = "The Engine Agnostic ECS Ruby Framework"
12
+ #spec.description = "TODO: Write a longer description or delete this line."
13
+ spec.homepage = "https://felflame.tradam.fyi"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.4.0"
16
+
17
+ #spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/realtradam/FelFlame"
21
+ #spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ # Uncomment to register a new dependency of your gem
33
+ # spec.add_dependency "example-gem", "~> 1.0"
34
+ spec.add_development_dependency 'minitest-reporters', '~> 1.4', '>= 1.4.3'#, require: false
35
+ spec.add_development_dependency 'rspec', '~> 3.10'
36
+ spec.add_development_dependency 'simplecov', '~> 0.21.2'#, require: false
37
+ spec.add_development_dependency 'simplecov-console', '~> 0.9.1'
38
+ spec.add_development_dependency 'simplecov_json_formatter', '~> 0.1.3'#, require: false
39
+ spec.add_development_dependency 'redcarpet', '~> 3.5', '>= 3.5.1'#, require: false
40
+ spec.add_development_dependency 'yard', '~> 0.9.26'#, require: false
41
+ spec.add_development_dependency 'rubocop', '~> 1.7'
42
+
43
+ # For more information and examples about making a new gem, checkout our
44
+ # guide at: https://bundler.io/guides/creating_gem.html
45
+ end
data/lib/felflame.rb ADDED
@@ -0,0 +1,59 @@
1
+ require_relative 'felflame/entity_manager'
2
+ require_relative 'felflame/component_manager'
3
+ require_relative 'felflame/system_manager'
4
+ require_relative 'felflame/scene_manager'
5
+ require_relative 'felflame/stage_manager'
6
+
7
+ require_relative "felflame/version"
8
+
9
+ # The FelFlame namespace where all its functionality resides under.
10
+ class FelFlame
11
+ class <<self
12
+ # :nocov:
13
+
14
+ # An alias for {FelFlame::Stage.call}. It executes a single frame in the game.
15
+ def call
16
+ FelFlame::Stage.call
17
+ end
18
+ # :nocov:
19
+ end
20
+
21
+ # Creates and manages Entities. Allows accessing Entities using their {FelFlame::Entities#id ID}. Entities are just collections of Components.
22
+ class Entities; end
23
+
24
+ # Creates component managers and allows accessing them them under the {FelFlame::Components} namespace as Constants
25
+ #
26
+ # To see how component managers are used please look at the {FelFlame::ComponentManager} documentation.
27
+ class Components; end
28
+
29
+ # Creates an manages Systems. Systems are the logic of the game and do not contain any data within them.
30
+ #
31
+ # TODO: Improve Systems overview
32
+ class Systems; end
33
+
34
+ # Creates and manages Scenes. Scenes are collections of Systems, and execute all the Systems when called upon.
35
+ #
36
+ # TODO: Improve Scenes overview
37
+ class Scenes; end
38
+
39
+ # Stores Scenes 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.
40
+ class Stage; end
41
+ end
42
+
43
+ # An alias for {FelFlame}
44
+ FF = FelFlame
45
+
46
+ # An alias for {FelFlame::Entities}
47
+ FF::Ent = FelFlame::Entities
48
+
49
+ # An alias for {FelFlame::Components}
50
+ FF::Cmp = FelFlame::Components
51
+
52
+ # An alias for {FelFlame::Systems}
53
+ FF::Sys = FelFlame::Systems
54
+
55
+ # An alias for {FelFlame::Scenes}
56
+ FF::Sce = FelFlame::Scenes
57
+
58
+ # An alias for {FelFlame::Stage}
59
+ FF::Stg = FelFlame::Stage
@@ -0,0 +1,245 @@
1
+ class FelFlame
2
+ class Components
3
+ @component_map = []
4
+ class <<self
5
+ include Enumerable
6
+ # Creates a new {FelFlame::ComponentManager component manager}.
7
+ #
8
+ # @example
9
+ # # Here color is set to default to red
10
+ # # while max and current are nil until set.
11
+ # # When you make a new component using this component manager
12
+ # # these are the values and accessors it will have.
13
+ # FelFlame::Component.new('Health', :max, :current, color: 'red')
14
+ #
15
+ # @param component_name [String] Name of your new component manager. Must be stylized in the format of constants in Ruby
16
+ # @param attrs [:Symbols] New components made with this manager will include these symbols as accessors, the values of these accessors will default to nil
17
+ # @param attrs_with_defaults [Keyword: DefaultValue] New components made with this manager will include these keywords as accessors, their defaults set to the values given to the keywords
18
+ # @return [ComponentManager]
19
+ def new(component_name, *attrs, **attrs_with_defaults)
20
+ if FelFlame::Components.const_defined?(component_name)
21
+ raise(NameError.new, "Component Manager '#{component_name}' is already defined")
22
+ end
23
+
24
+
25
+ const_set(component_name, Class.new(FelFlame::ComponentManager) {})
26
+ attrs.each do |attr|
27
+ FelFlame::Components.const_get(component_name).attr_accessor attr
28
+ end
29
+ attrs_with_defaults.each do |attr, _default|
30
+ attrs_with_defaults[attr] = _default.dup
31
+ FelFlame::Components.const_get(component_name).attr_reader attr
32
+ FelFlame::Components.const_get(component_name).define_method("#{attr}=") do |value|
33
+ attr_changed_trigger_systems(attr) unless value.equal? send(attr)
34
+ instance_variable_set("@#{attr}", value)
35
+ end
36
+ end
37
+ FelFlame::Components.const_get(component_name).define_method(:set_defaults) do
38
+ attrs_with_defaults.each do |attr, default|
39
+ instance_variable_set("@#{attr}", default.dup)
40
+ end
41
+ end
42
+ FelFlame::Components.const_get(component_name)
43
+ end
44
+
45
+ # Iterate over all existing component managers. You also call other enumerable methods instead of each, such as +each_with_index+ or +select+
46
+ # @return [Enumerator]
47
+ def each(&block)
48
+ constants.each(&block)
49
+ end
50
+ end
51
+ end
52
+
53
+ # Component Managers are what is used to create individual components which can be attached to entities.
54
+ # When a Component is created from a Component Manager that has accessors given to it, you can set or get the values of those accessors using standard ruby message sending (e.g +@component.var = 5+), or by using the {#attrs} and {#update_attrs} methods instead.
55
+ class ComponentManager
56
+
57
+ # Holds the {id unique ID} of a component. The {id ID} is only unique within the scope of the component manager it was created from.
58
+ # @return [Integer]
59
+ attr_reader :id
60
+
61
+ # A seperate attr_writer was made for documentation readability reasons.
62
+ # Yard will list attr_reader is readonly which is my intention.
63
+ # This value needs to be changable as it is set by other functions.
64
+ # @!visibility private
65
+ attr_writer :id
66
+
67
+ # Allows overwriting the storage of triggers, such as for clearing.
68
+ # This method should generally only need to be used internally and
69
+ # not by a game developer.
70
+ # @!visibility private
71
+ attr_writer :addition_triggers, :removal_triggers, :attr_triggers
72
+
73
+ # Stores references to systems that should be triggered when a
74
+ # component from this manager is added.
75
+ # Do not edit this array as it is managed by FelFlame automatically.
76
+ # @return [Array<System>]
77
+ def addition_triggers
78
+ @addition_triggers ||= []
79
+ end
80
+
81
+ # Stores references to systems that should be triggered when a
82
+ # component from this manager is removed.
83
+ # Do not edit this array as it is managed by FelFlame automatically.
84
+ # @return [Array<System>]
85
+ def removal_triggers
86
+ @removal_triggers ||= []
87
+ end
88
+
89
+ # Stores references to systems that should be triggered when an
90
+ # attribute from this manager is changed.
91
+ # Do not edit this hash as it is managed by FelFlame automatically.
92
+ # @return [Hash<Symbol, Array<System>>]
93
+ def attr_triggers
94
+ @attr_triggers ||= {}
95
+ end
96
+
97
+ # Creates a new component and sets the values of the attributes given to it. If an attritbute is not passed then it will remain as the default.
98
+ # @param attrs [Keyword: Value] You can pass any number of Keyword-Value pairs
99
+ # @return [Component]
100
+ def initialize(**attrs)
101
+ # Prepare the object
102
+ # (this is a function created with metaprogramming
103
+ # in FelFlame::Components
104
+ set_defaults
105
+
106
+ # Generate ID
107
+ new_id = self.class.data.find_index { |i| i.nil? }
108
+ new_id = self.class.data.size if new_id.nil?
109
+ @id = new_id
110
+
111
+ # Fill params
112
+ attrs.each do |key, value|
113
+ send "#{key}=", value
114
+ end
115
+
116
+ # Save Component
117
+ self.class.data[new_id] = self
118
+ end
119
+
120
+ class <<self
121
+
122
+ # Allows overwriting the storage of triggers, such as for clearing.
123
+ # This method should generally only need to be used internally and
124
+ # not by a game developer.
125
+ # @!visibility private
126
+ attr_writer :addition_triggers, :removal_triggers, :attr_triggers
127
+
128
+ # Stores references to systems that should be triggered when this
129
+ # component is added to an enitity.
130
+ # Do not edit this array as it is managed by FelFlame automatically.
131
+ # @return [Array<System>]
132
+ def addition_triggers
133
+ @addition_triggers ||= []
134
+ end
135
+
136
+ # Stores references to systems that should be triggered when this
137
+ # component is removed from an enitity.
138
+ # Do not edit this array as it is managed by FelFlame automatically.
139
+ # @return [Array<System>]
140
+ def removal_triggers
141
+ @removal_triggers ||= []
142
+ end
143
+
144
+ # Stores references to systems that should be triggered when an
145
+ # attribute from this component changed.
146
+ # Do not edit this hash as it is managed by FelFlame automatically.
147
+ # @return [Hash<Symbol, System>]
148
+ def attr_triggers
149
+ @attr_triggers ||= {}
150
+ end
151
+
152
+ # @return [Array<Component>] Array of all Components that belong to a given component manager
153
+ # @!visibility private
154
+ def data
155
+ @data ||= []
156
+ end
157
+
158
+ # Gets a Component from the given {id unique ID}. Usage is simular to how an Array lookup works.
159
+ #
160
+ # @example
161
+ # # this gets the 'Health' Component with ID 7
162
+ # FelFlame::Components::Health[7]
163
+ # @param component_id [Integer]
164
+ # @return [Component] Returns the Component that uses the given unique {id ID}, nil if there is no Component associated with the given {id ID}
165
+ def [](component_id)
166
+ data[component_id]
167
+ end
168
+
169
+ # Iterates over all components within the component manager.
170
+ # Special Enumerable methods like +map+ or +each_with_index+ are not implemented
171
+ # @return [Enumerator]
172
+ def each(&block)
173
+ data.compact.each(&block)
174
+ end
175
+ end
176
+
177
+ # An alias for the {id ID Reader}
178
+ # @return [Integer]
179
+ def to_i
180
+ id
181
+ end
182
+
183
+ # A list of entity ids that are linked to the component
184
+ # @return [Array<Integer>]
185
+ def entities
186
+ @entities ||= []
187
+ end
188
+
189
+ # Update attribute values using a hash or keywords.
190
+ # @return [Hash<Symbol, Value>] Hash of updated attributes
191
+ def update_attrs(**opts)
192
+ opts.each do |key, value|
193
+ send "#{key}=", value
194
+ end
195
+ end
196
+
197
+ # Execute systems that have been added to execute on variable change
198
+ # @return [Boolean] +true+
199
+ def attr_changed_trigger_systems(attr)
200
+ systems_to_execute = self.class.attr_triggers[attr]
201
+ systems_to_execute = [] if systems_to_execute.nil?
202
+
203
+ systems_to_execute |= attr_triggers[attr] unless attr_triggers[attr].nil?
204
+
205
+ systems_to_execute.sort_by(&:priority).reverse.each(&:call)
206
+ true
207
+ end
208
+
209
+ # Removes this component from the list and purges all references to this Component from other Entities, as well as its {id ID} and data.
210
+ # @return [Boolean] +true+.
211
+ def delete
212
+ addition_triggers.each do |system|
213
+ system.clear_triggers component_or_manager: self
214
+ end
215
+ # This needs to be cloned because indices get deleted as
216
+ # the remove command is called, breaking the loop if it
217
+ # wasn't referencing a clone(will get Nil errors)
218
+ iter = entities.map(&:clone)
219
+ iter.each do |entity_id|
220
+ FelFlame::Entities[entity_id].remove self #unless FelFlame::Entities[entity_id].nil?
221
+ end
222
+ self.class.data[id] = nil
223
+ instance_variables.each do |var|
224
+ instance_variable_set(var, nil)
225
+ end
226
+ true
227
+ end
228
+
229
+ # @return [Hash<Symbol, Value>] A hash, where all the keys are attributes linked to their respective values.
230
+ def attrs
231
+ return_hash = instance_variables.each_with_object({}) do |key, final|
232
+ final[key.to_s.delete_prefix('@').to_sym] = instance_variable_get(key)
233
+ end
234
+ return_hash.delete(:attr_triggers)
235
+ return_hash
236
+ end
237
+
238
+ # Export all data into a JSON String, which could then later be loaded or saved to a file
239
+ # TODO: This function is not yet complete
240
+ # @return [String] a JSON formatted String
241
+ #def to_json
242
+ # # should return a json or hash of all data in this component
243
+ #end
244
+ end
245
+ end