From 55f1db30e7a609cebd2fab27c55ece1da45be232 Mon Sep 17 00:00:00 2001 From: realtradam Date: Mon, 3 Jan 2022 07:34:38 -0500 Subject: . --- .rubocop.yml | 4 +- CHANGELOG.mdown | 6 +- Gemfile | 5 +- README.mdown | 155 +++++++++++---------- Rakefile | 26 ++-- bin/console | 6 +- codeclimate/env.rb | 2 + codeclimate/export-coverage.rb | 5 +- deprecated/components/00_renderable.rb | 36 ++--- deprecated/components/01_sprite.rb | 103 +++++++------- deprecated/components/03_player_control.rb | 47 ++++--- deprecated/components/04_map.rb | 3 +- deprecated/components/05_interactable.rb | 4 +- deprecated/components/06_collidable.rb | 10 +- deprecated/components/07_battle.rb | 2 + deprecated/components/07_indoor.rb | 2 + deprecated/components/07_overworld.rb | 4 +- deprecated/components/debug_singleton.rb | 4 +- deprecated/helpers/00_tileset.rb | 28 ++-- deprecated/helpers/01_component.rb | 131 +++++++++--------- deprecated/systems/00_update_levels.rb | 4 +- deprecated/systems/10_player.rb | 44 +++--- deprecated/systems/99_render.rb | 38 ++++-- docs/FelFlame.html | 14 +- docs/FelFlame/ComponentManager.html | 211 ++++++++--------------------- docs/FelFlame/Components.html | 18 +-- docs/FelFlame/Entities.html | 52 ++++--- docs/FelFlame/Order.html | 172 +++++++++++++++++++++++ docs/FelFlame/Scenes.html | 62 ++++----- docs/FelFlame/Stage.html | 44 +++--- docs/FelFlame/Systems.html | 148 ++++++++++---------- docs/Felflame_.html | 4 +- docs/_index.html | 17 ++- docs/class_list.html | 2 +- docs/file.README.html | 106 ++++++++------- docs/index.html | 106 ++++++++------- docs/method_list.html | 80 +++++------ docs/top-level-namespace.html | 2 +- felflame.gemspec | 42 +++--- lib/felflame.rb | 15 +- lib/felflame/component_manager.rb | 46 +++---- lib/felflame/entity_manager.rb | 34 ++--- lib/felflame/order.rb | 6 + lib/felflame/scene_manager.rb | 4 +- lib/felflame/stage_manager.rb | 6 +- lib/felflame/system_manager.rb | 83 ++++++------ lib/felflame/version.rb | 2 +- spec/component_manager_spec.rb | 30 ++-- spec/entity_manager_spec.rb | 35 +++-- spec/scene_manager_spec.rb | 6 +- spec/spec_helper.rb | 114 ++++++++-------- spec/stage_manager_spec.rb | 11 +- spec/system_manager_spec.rb | 15 +- 53 files changed, 1139 insertions(+), 1017 deletions(-) create mode 100644 docs/FelFlame/Order.html create mode 100644 lib/felflame/order.rb diff --git a/.rubocop.yml b/.rubocop.yml index bfef2d0..2cfd5d4 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,9 +1,9 @@ AllCops: - TargetRubyVersion: 2.4 + TargetRubyVersion: 2.7 Style/StringLiterals: Enabled: true - EnforcedStyle: double_quotes + EnforcedStyle: single_quotes Style/StringLiteralsInInterpolation: Enabled: true diff --git a/CHANGELOG.mdown b/CHANGELOG.mdown index 15f2392..e60824f 100644 --- a/CHANGELOG.mdown +++ b/CHANGELOG.mdown @@ -13,6 +13,8 @@ - Removed all ids as they were not used ![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 - Component method `.attrs` was renamed to `.to_h` - Renamed the `data` accessor to `._data` - Various arrays are automatically compacted @@ -22,12 +24,12 @@ - Convenience methods for accessing a single entity in a component(`@component.entity`) and accessing a single entity in a component(`@entity.component[@component_manager]`) ![Fixed](https://img.shields.io/badge/-Fixed-blue) -- Replaced all instances of `sort_by!` with `sort_by` for compatibility with DragonRuby +- 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. +- 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) diff --git a/Gemfile b/Gemfile index 57f3b06..ffcd824 100644 --- a/Gemfile +++ b/Gemfile @@ -1,11 +1,10 @@ # frozen_string_literal: true -source "https://rubygems.org" +source 'https://rubygems.org' # Specify your gem's dependencies in felflame.gemspec gemspec ruby '2.7.3' -gem "rake", "~> 13.0" - +gem 'rake', '~> 13.0' diff --git a/README.mdown b/README.mdown index 45b5b35..e281b7e 100644 --- a/README.mdown +++ b/README.mdown @@ -13,48 +13,46 @@ -+ [What is FelFlame?](#what-is-felflame) -+ [What is ECS?](#what-is-ecs) - - [Components](#components) - - [Entities](#entities) - - [Systems](#systems) - - [Scenes](#scenes) - - [Stage](#stage) -+ [Usage](#usage) +* [What is FelFlame?](#what-is-felflame) +* [What is ECS?](#what-is-ecs) + * [Components](#components) + * [Entities](#entities) + * [Systems](#systems) + * [Scenes](#scenes) + * [Stage](#stage) +* [Usage](#usage) * [Entities](#entities-1) - - [Creation](#creation) - - [Accessing](#accessing) - - [Get ID](#get-id) - - [Adding and Removing Components](#adding-and-removing-components) - - [Accessing Entities' Attached Components](#accessing-entities-attached-components) - - [Deletion](#deletion) + * [Creation](#creation) + * [Accessing](#accessing) + * [Adding and Removing Components](#adding-and-removing-components) + * [Accessing Entities' Attached Components](#accessing-entities-attached-components) + * [Deletion](#deletion) * [Components](#components-1) - - [Creating a Component Manager](#creating-a-component-manager) - - [Creating a Component from a Component Manager](#creating-a-component-from-a-component-manager) - - [Accessing and Getting ID](#accessing-and-getting-id) - - [Accessing Attributes and Changing Them](#accessing-attributes-and-changing-them) - - [Deleting Components](#deleting-components) - - [Iterating over Components](#iterating-over-components) - - [Accessing Components' attached Entities](#accessing-components-attached-entities) + * [Creating a Component Manager](#creating-a-component-manager) + * [Creating a Component from a Component Manager](#creating-a-component-from-a-component-manager) + * [Accessing](#accessing-1) + * [Accessing Attributes and Changing Them](#accessing-attributes-and-changing-them) + * [Deleting Components](#deleting-components) + * [Accessing Components' attached Entities](#accessing-components-attached-entities) * [Systems](#systems-1) - - [Creation](#creation-1) - - [Execution](#execution) - - [Alternative Execution](#alternative-execution) - - [Clearing Alternative Executions](#clearing-alternative-executions) - - [Redefinition](#redefinition) + * [Creation](#creation-1) + * [Execution](#execution) + * [Alternative Execution](#alternative-execution) + * [Clearing Alternative Executions](#clearing-alternative-executions) + * [Redefinition](#redefinition) * [Scenes](#scenes-1) - - [Creation](#creation-2) - - [Accessing](#accessing-1) - - [Adding Systems](#adding-systems) - - [Removing Systems](#removing-systems) - - [Clearing](#clearing) - - [Execution](#execution-1) + * [Creation](#creation-2) + * [Accessing](#accessing-2) + * [Adding Systems](#adding-systems) + * [Removing Systems](#removing-systems) + * [Clearing](#clearing) + * [Execution](#execution-1) * [Stage](#stage-1) - - [Adding Scenes](#adding-scenes) - - [Removing Scenes](#removing-scenes) - - [Executing](#executing) + * [Adding Scenes](#adding-scenes) + * [Removing Scenes](#removing-scenes) + * [Executing](#executing) * [Closing Notes](#closing-notes) -+ [Contribution](#contribution) +* [Contribution](#contribution) @@ -97,11 +95,14 @@ The Stage is Scenes which are activated. This means any Scenes on the Stage are --- -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. # Usage -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 a planned feature in the works. +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. + +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'`. + +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. ## Entities @@ -111,29 +112,24 @@ Entities are essentially "objects" in the game world. To create a new Entity we ```ruby @entity = FelFlame::Entities.new ``` -or if we want to add (any number of)components to it: +or if we want to add (any number of)components to it when creating it: ```ruby @entity = FelFlame::Entites.new( FelFlame::Components::Health.new, @component, - FelFlame::Components::Armour[7] + FelFlame::Components::EnemyTeam.first ) ``` ### Accessing -Once components are created we can access them using their ID like so: +Oftentimes you will not be accessing an Entity this way. Later we will shows you a more common way of accessing entities. +If you need to you can access Entities using the `Entities` module: ```ruby @entity = FelFlame::Entities[2] -``` - -### Get ID -Entity ID's are generated starting from 0 and ascending, unless if there is a missing ID because of a deleted -entity where a new entity will claim that ID. To get the ID of an Entity: - -```ruby -@entity.id +@entity = FelFlame::Entities.first +@entity = FelFlame::Entities.each # you can iterate over all entities this way. Any valid array method can be used ``` ### Adding and Removing Components @@ -145,14 +141,18 @@ We can still add or remove Components from an Entity after it has been created. ``` ### Accessing Entities' Attached Components +This is the most common way of accessing an Entity + 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: ```ruby -@entity.components[@component_manager] # => [@component1, @component2, component3] +@entity.components[@component_manager] # => [@component1, @component2, @component3] ``` ### Deletion -To have all Components from an Entity removed and the Entity deleted we do the following: +To have all Components from an Entity **removed** and the Entity deleted we do the following: + +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. ```ruby @entity.delete @@ -182,20 +182,19 @@ Now that we have a component manager we can make components from it like so: @component = FelFlame::Components::Stats.new ``` -Or we can even change the defaults: +Or we can even override the defaults when creating the component: ```ruby @component = FelFlame::Components::Stats.new(armour: 'steel') ``` -### Accessing and Getting ID -Just like Entities, Components have IDs. -These IDs are only unique within the scope of their respective Component Managers. -Here is how we can get the ID, as well as how to access a Component from its Component Manager. +### Accessing +You can access components using any array method. ```ruby @component = FelFlame::Components::Stats[2] -@component.id # => 2 +@component = FelFlame::Components::Stats.first +@component = FelFlame::Components::Stats.each # you can use iterators this way ``` ### Accessing Attributes and Changing Them @@ -207,30 +206,26 @@ Here are the ways to edit attrubutes, followed by the ways to read them. ``` ```ruby @component.hp # => 95 -@component.attrs # => {armour: 'Leather', hp: 95} +@component.to_h # => {armour: 'Leather', hp: 95} ``` ### Deleting Components -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. +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. ```ruby @component.delete ``` -### Iterating over Components -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: - -```ruby -FelFlame::Components::Sprites.each do |component| - #do something with components -end -``` - ### Accessing Components' attached Entities Components also keep track of what Entities are using it. To access this list we do the following: ```ruby @component.entities # => [@entity1, @entity2, @entity3] + +# get the first entity attached. +# this will throw a warning if there is more or less then +# exactly one entity +@component.entity # => @entity ``` @@ -252,7 +247,9 @@ FelFlame::Systems::Render ``` Priority determines the order Systems should be executed, this is used for `Scenes` and the `Stage`. The lower the number, the earlier a given System will be executed. -E.g priority 1 will go first, priority 2 will go second, etcetera. +E.g priority 1 will go first, priority 2 will go second, etcetera. + +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. Often we will want to execute some logic on each Component in a given Component Manager so our code might look like this: @@ -355,7 +352,7 @@ end 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: ```ruby -@scene = FelFlame::Scenes.new('ExampleScene') +@scene = FelFlame::Scenes.new('ExampleScene', priority: 5) ``` ### Accessing @@ -369,14 +366,22 @@ Just like other classes in FelFlame, the name we gave the Scene is how we access Adding Systems is simple. We can add as many as we want. In this example we add 3 different systems: ```ruby -FelFlame::Scenes::ExampleScene.add(FelFlame::Systems::Render, @system2, @system3) +FelFlame::Scenes::ExampleScene.add( + FelFlame::Systems::Render, + @system2, + @system3 +) ``` ### Removing Systems -Removing Systems works simularly: +Removing Systems works similarly: ```ruby -FelFlame::Scenes::ExampleScene.remove(FelFlame::Systems::Render, @system2, @system3) +FelFlame::Scenes::ExampleScene.remove( + FelFlame::Systems::Render, + @system2, + @system3 +) ``` ### Clearing @@ -398,7 +403,7 @@ The Scene will make sure that the systems are executed in the correct order base ## Stage ### Adding Scenes -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: +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: ```ruby FelFlame::Stage.add FelFlame::Scene::ExampleScene @@ -412,7 +417,7 @@ FelFlame::Stage.remove FelFlame::Scene::ExampleScene ``` ### Executing -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: +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: ```ruby FelFlame::Stage.call diff --git a/Rakefile b/Rakefile index f7d8c6c..b4ba44b 100644 --- a/Rakefile +++ b/Rakefile @@ -1,30 +1,30 @@ # frozen_string_literal: true -# + require 'rubygems' require 'bundler/setup' require 'rspec/core/rake_task' require 'yard' require_relative './codeclimate/export-coverage' -require "bundler/gem_tasks" -require "rubocop/rake_task" +require 'bundler/gem_tasks' +require 'rubocop/rake_task' -task :default => [:spec, :yard, 'coverage:format'] -#task default: :rubocop +task default: [:spec, :yard, 'coverage:format'] +# task default: :rubocop desc 'Export to single file' task :buildfile do result = '' main = File.read('lib/felflame.rb') tmp = main.lines(chomp: true).select do |line| - line.include? "require_relative " + line.include? 'require_relative ' end tmp.each do |file| - file.delete_prefix!("require_relative ") - result += File.read("lib/#{file[1,file.length-2]}.rb") + "\n" + file.delete_prefix!('require_relative ') + result += "#{File.read("lib/#{file[1, file.length - 2]}.rb")}\n" end result += main.lines.reject do |line| - line.include? "require_relative " + line.include? 'require_relative ' end.join `mkdir pkg` @@ -51,15 +51,15 @@ YARD::Rake::YardocTask.new do |t| t.stats_options = ['--list-undoc'] end -#Rake::TestTask.new do |t| +# Rake::TestTask.new do |t| # t.pattern = "tests/**/*_test.rb" -#end +# end RSpec::Core::RakeTask.new :spec # For installing FelPacks -#Gem::Specification.find_all.each do |a_gem| +# Gem::Specification.find_all.each do |a_gem| # next unless a_gem.name.include? 'felpack-' # # Dir.glob("#{a_gem.gem_dir}/lib/#{a_gem.name.gsub('-', '/')}/tasks/*.rake").each { |r| load r } -#end +# end diff --git a/bin/console b/bin/console index c0dca2c..9e87c14 100755 --- a/bin/console +++ b/bin/console @@ -1,8 +1,8 @@ #!/usr/bin/env ruby # frozen_string_literal: true -require "bundler/setup" -require "felflame" +require 'bundler/setup' +require 'felflame' # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. @@ -11,5 +11,5 @@ require "felflame" # require "pry" # Pry.start -require "irb" +require 'irb' IRB.start(__FILE__) diff --git a/codeclimate/env.rb b/codeclimate/env.rb index 0a0ad43..25bae9e 100644 --- a/codeclimate/env.rb +++ b/codeclimate/env.rb @@ -1 +1,3 @@ +# frozen_string_literal: true + ENV['CC_TEST_REPORTER_ID'] = '48d1c389052ea205cb4d72b05f7606fc53a9b5def70c2bfdd957efb73657d32c' diff --git a/codeclimate/export-coverage.rb b/codeclimate/export-coverage.rb index 7a63acd..74b0cbd 100644 --- a/codeclimate/export-coverage.rb +++ b/codeclimate/export-coverage.rb @@ -1,8 +1,9 @@ -require_relative 'env' +# frozen_string_literal: true +require_relative 'env' class ReportCoverage - class < 1 + return {} end - json_tiles = self.get_json_tiles(json_name) - raise Exception.new "Error, json file not a tileset" unless json_tiles['type'] == 'tileset' + json_tiles = get_json_tiles(json_name) + raise StandardError, 'Error, json file not a tileset' unless json_tiles['type'] == 'tileset' return tile_index - json_tiles['tilecount'] if tile_index > json_tiles['tilecount'] - source_height_tiles = (tile_index.to_i / json_tiles['columns'].to_i).to_i# * json_tiles['tileheight'] + + source_height_tiles = (tile_index.to_i / json_tiles['columns'].to_i).to_i # * json_tiles['tileheight'] { w: json_tiles['tilewidth'], h: json_tiles['tileheight'], path: json_tiles['image'].split('mygame/').last.delete('\\'), diff --git a/deprecated/helpers/01_component.rb b/deprecated/helpers/01_component.rb index 2065d0c..12cce09 100644 --- a/deprecated/helpers/01_component.rb +++ b/deprecated/helpers/01_component.rb @@ -1,74 +1,67 @@ +# frozen_string_literal: true + class FelFlame class Helper + # # Unused: + # class Level < FelFlame::Helper::ComponentManager + # class <= Components::Map.data[key].json['tilesets'].count - end - unless tile.empty? - tile[:x] = Components::Map.data[key].x + (Components::Map.data[key].tilewidth * column_index) + chunk['x'] - tile[:y] = Components::Map.data[key].y + (Components::Map.data[key].tileheight * row_index) + chunk['y'] - tile[:w] = Components::Map.data[key].tilewidth - tile[:h] = Components::Map.data[key].tileheight - $gtk.args.outputs.sprites << tile + next if tile.zero? + + iter = 0 + loop do + tile = Helper.get_tile( + json_name: Components::Map.data[key].json['tilesets'][iter]['source'].split('/').last.delete('\\').delete_suffix('.tsx'), tile_index: tile + ) + break if tile.is_a?(Hash) + + if (iter += 1) >= Components::Map.data[key].json['tilesets'].count + raise StandardError, + "#{Components::Map.data[key].json["json_name"]} not valid map, exceeded tile range" end end + next if tile.empty? + + tile[:x] = + Components::Map.data[key].x + (Components::Map.data[key].tilewidth * column_index) + chunk['x'] + tile[:y] = + Components::Map.data[key].y + (Components::Map.data[key].tileheight * row_index) + chunk['y'] + tile[:w] = Components::Map.data[key].tilewidth + tile[:h] = Components::Map.data[key].tileheight + $gtk.args.outputs.sprites << tile end end end diff --git a/docs/FelFlame.html b/docs/FelFlame.html index ef9cb69..1ec7927 100644 --- a/docs/FelFlame.html +++ b/docs/FelFlame.html @@ -79,7 +79,7 @@
Defined in:
lib/felflame.rb,
- lib/felflame/scene_manager.rb,
lib/felflame/stage_manager.rb,
lib/felflame/entity_manager.rb,
lib/felflame/system_manager.rb,
lib/felflame/component_manager.rb
+ lib/felflame/order.rb,
lib/felflame/scene_manager.rb,
lib/felflame/stage_manager.rb,
lib/felflame/entity_manager.rb,
lib/felflame/system_manager.rb,
lib/felflame/component_manager.rb
@@ -100,7 +100,7 @@

- Modules: Components, Stage + Modules: Components, Order, Stage @@ -273,12 +273,12 @@

 
 
-15
-16
-17
+17 +18 +19 -
# File 'lib/felflame.rb', line 15
+      
# File 'lib/felflame.rb', line 17
 
 def call
   FelFlame::Stage.call
@@ -293,7 +293,7 @@
 
 
       
diff --git a/docs/FelFlame/ComponentManager.html b/docs/FelFlame/ComponentManager.html
index 119a7ed..143fd3a 100644
--- a/docs/FelFlame/ComponentManager.html
+++ b/docs/FelFlame/ComponentManager.html
@@ -102,7 +102,7 @@
 

Overview

-

Component Managers are what is used to create individual components which can be attached to entities. 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.

+

Component Managers are what is used to create individual components which can be attached to entities. 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 #to_h and #update_attrs methods instead.

@@ -312,30 +312,6 @@
  • - #attr_changed_trigger_systems(attr) ⇒ Boolean - - - - - - - - - - - - - -
    -

    Execute systems that have been added to execute on variable change.

    -
    - -
  • - - -
  • - - #delete ⇒ Boolean @@ -449,7 +425,7 @@
    -

    A hash, where all the keys are attributes linked to their respective values.

    +

    A hash, where all the keys are attributes storing their respective values.

  • @@ -531,6 +507,8 @@
     
     
    +154
    +155
     156
     157
     158
    @@ -542,12 +520,10 @@
     164
     165
     166
    -167
    -168
    -169
    +167
    -
    # File 'lib/felflame/component_manager.rb', line 156
    +      
    # File 'lib/felflame/component_manager.rb', line 154
     
     def initialize(**attrs)
       # Prepare the object
    @@ -614,12 +590,12 @@
           
     
     
    -206
    -207
    -208
    +202 +203 +204
    -
    # File 'lib/felflame/component_manager.rb', line 206
    +      
    # File 'lib/felflame/component_manager.rb', line 202
     
     def addition_triggers
       @addition_triggers ||= []
    @@ -670,12 +646,12 @@
           
     
     
    -222
    -223
    -224
    +218 +219 +220
    -
    # File 'lib/felflame/component_manager.rb', line 222
    +      
    # File 'lib/felflame/component_manager.rb', line 218
     
     def attr_triggers
       @attr_triggers ||= {}
    @@ -726,12 +702,12 @@
           
     
     
    -214
    -215
    -216
    +210 +211 +212
    -
    # File 'lib/felflame/component_manager.rb', line 214
    +      
    # File 'lib/felflame/component_manager.rb', line 210
     
     def removal_triggers
       @removal_triggers ||= []
    @@ -787,12 +763,12 @@
           
     
     
    -133
    -134
    -135
    +131 +132 +133
    -
    # File 'lib/felflame/component_manager.rb', line 133
    +      
    # File 'lib/felflame/component_manager.rb', line 131
     
     def addition_triggers
       @addition_triggers ||= []
    @@ -843,12 +819,12 @@
           
     
     
    -149
    -150
    -151
    +147 +148 +149
    -
    # File 'lib/felflame/component_manager.rb', line 149
    +      
    # File 'lib/felflame/component_manager.rb', line 147
     
     def attr_triggers
       @attr_triggers ||= {}
    @@ -899,12 +875,12 @@
           
     
     
    -141
    -142
    -143
    +139 +140 +141
    -
    # File 'lib/felflame/component_manager.rb', line 141
    +      
    # File 'lib/felflame/component_manager.rb', line 139
     
     def removal_triggers
       @removal_triggers ||= []
    @@ -922,78 +898,7 @@
     
         
           
    -

    - - #attr_changed_trigger_systems(attr) ⇒ Boolean - - - - - -

    -
    - -

    Execute systems that have been added to execute on variable change

    - - -
    -
    -
    - -

    Returns:

    -
      - -
    • - - - (Boolean) - - - - — -
      -

      true

      -
      - -
    • - -
    - -
    - - - - -
    -
    -
    -
    -260
    -261
    -262
    -263
    -264
    -265
    -266
    -267
    -268
    -
    -
    # File 'lib/felflame/component_manager.rb', line 260
    -
    -def attr_changed_trigger_systems(attr)
    -  systems_to_execute = self.class.attr_triggers[attr]
    -  systems_to_execute = [] if systems_to_execute.nil?
    -
    -  systems_to_execute |= attr_triggers[attr] unless attr_triggers[attr].nil?
    -
    -  systems_to_execute.sort_by(&:priority).reverse_each(&:call)
    -  true
    -end
    -
    -
    - -
    -

    +

    #deleteBoolean @@ -1036,6 +941,8 @@
     
     
    +269
    +270
     271
     272
     273
    @@ -1046,12 +953,10 @@
     278
     279
     280
    -281
    -282
    -283
    +281

    -
    # File 'lib/felflame/component_manager.rb', line 271
    +      
    # File 'lib/felflame/component_manager.rb', line 269
     
     def delete
       addition_triggers.each do |system|
    @@ -1110,12 +1015,12 @@
           
     
     
    -235
    -236
    -237
    +231 +232 +233
    -
    # File 'lib/felflame/component_manager.rb', line 235
    +      
    # File 'lib/felflame/component_manager.rb', line 231
     
     def entities
       @entities ||= []
    @@ -1164,17 +1069,17 @@
           
     
     
    +237
    +238
    +239
    +240
     241
     242
     243
    -244
    -245
    -246
    -247
    -248
    +244
    -
    # File 'lib/felflame/component_manager.rb', line 241
    +      
    # File 'lib/felflame/component_manager.rb', line 237
     
     def entity
       if entities.empty?
    @@ -1201,7 +1106,7 @@
     
    -

    Returns A hash, where all the keys are attributes linked to their respective values.

    +

    Returns A hash, where all the keys are attributes storing their respective values.

    @@ -1220,7 +1125,7 @@ —
    -

    A hash, where all the keys are attributes linked to their respective values.

    +

    A hash, where all the keys are attributes storing their respective values.

    @@ -1233,16 +1138,16 @@
     
     
    +284
    +285
     286
     287
     288
     289
    -290
    -291
    -292
    +290
    -
    # File 'lib/felflame/component_manager.rb', line 286
    +      
    # File 'lib/felflame/component_manager.rb', line 284
     
     def to_h
       return_hash = instance_variables.each_with_object({}) do |key, final|
    @@ -1300,14 +1205,14 @@
           
     
     
    -252
    -253
    -254
    -255
    -256
    +248 +249 +250 +251 +252
    -
    # File 'lib/felflame/component_manager.rb', line 252
    +      
    # File 'lib/felflame/component_manager.rb', line 248
     
     def update_attrs(**opts)
       opts.each do |key, value|
    @@ -1324,7 +1229,7 @@
     
     
           
    diff --git a/docs/FelFlame/Components.html b/docs/FelFlame/Components.html
    index 33d82b3..37c11bf 100644
    --- a/docs/FelFlame/Components.html
    +++ b/docs/FelFlame/Components.html
    @@ -88,7 +88,7 @@
     

    Overview

    -

    Creates component managers and allows accessing them them under the Components namespace as Constants.

    +

    Creates component managers and allows accessing them them under the Components namespace as Constants. You can use array methods directly on this class to access Component Managers.

    To see how component managers are used please look at the ComponentManager documentation.

    @@ -249,8 +249,6 @@
     
     
    -18
    -19
     20
     21
     22
    @@ -278,24 +276,26 @@
     44
     45
     46
    -47
    +47 +48 +49
    -
    # File 'lib/felflame/component_manager.rb', line 18
    +      
    # File 'lib/felflame/component_manager.rb', line 20
     
     def new(component_name, *attrs, **attrs_with_defaults)
       if FelFlame::Components.const_defined?(component_name)
         raise(NameError.new, "Component Manager '#{component_name}' is already defined")
       end
     
    -
       const_set(component_name, Class.new(FelFlame::ComponentManager) {})
       update_const_cache
     
       attrs.each do |attr|
    -    if FelFlame::Components.const_get(component_name).method_defined?("#{attr}") || FelFlame::Components.const_get(component_name).method_defined?("#{attr}=")
    -      raise NameError.new "The attribute name \"#{attr}\" is already a method"
    +    if FelFlame::Components.const_get(component_name).method_defined?(attr.to_s) || FelFlame::Components.const_get(component_name).method_defined?("#{attr}=")
    +      raise NameError, "The attribute name \"#{attr}\" is already a method"
         end
    +
         FelFlame::Components.const_get(component_name).attr_accessor attr
       end
       attrs_with_defaults.each do |attr, _default|
    @@ -323,7 +323,7 @@
     
     
           
    diff --git a/docs/FelFlame/Entities.html b/docs/FelFlame/Entities.html
    index 4308d4b..43d61fa 100644
    --- a/docs/FelFlame/Entities.html
    +++ b/docs/FelFlame/Entities.html
    @@ -104,7 +104,7 @@
     

    Overview

    -

    Creates and manages Entities. Allows iterating or accessing Entities using array methods directly on the class. Entities are just collections of Components.

    +

    Creates and manages Entities. Entities are just collections of Components. You can use array methods directly on this class to access Entities.

    @@ -325,14 +325,14 @@
     
     
    -7
     8
     9
     10
    -11
    +11 +12
    -
    # File 'lib/felflame/entity_manager.rb', line 7
    +      
    # File 'lib/felflame/entity_manager.rb', line 8
     
     def initialize(*components)
       # Add each component
    @@ -415,7 +415,6 @@
           
     
     
    -56
     57
     58
     59
    @@ -428,10 +427,11 @@
     66
     67
     68
    -69
    +69 +70
    -
    # File 'lib/felflame/entity_manager.rb', line 56
    +      
    # File 'lib/felflame/entity_manager.rb', line 57
     
     def add(*components_to_add)
       components_to_add.each do |component|
    @@ -464,7 +464,7 @@
     
    -

    A single component from a component manager. Use this if you expect the component to only belong to one entity and you want to access it. Access the component using either parameter notation or array notation.

    +

    A single component from a component manager. Use this if you expect the component to only belong to one entity and you want to access it. Access the component using either parameter notation or array notation. Array notation is conventional for better readablility.

    @@ -475,7 +475,7 @@

    Examples:

    -
    @entity.component[@component_manager] # array notation
    +      
    @entity.component[@component_manager] # array notation(the standard)
     @entity.component(@component_manager) # method notation
    @@ -522,7 +522,6 @@
     
     
    -25
     26
     27
     28
    @@ -534,10 +533,12 @@
     34
     35
     36
    -37
    +37 +38 +39
    -
    # File 'lib/felflame/entity_manager.rb', line 25
    +      
    # File 'lib/felflame/entity_manager.rb', line 26
     
     def component(manager = nil)
       if manager.nil?
    @@ -549,6 +550,7 @@
         elsif components[manager].length > 1
           Warning.warn("This entity has MANY of this component but you called the method that is intended for having a single of this component type.\nYou may have a bug in your logic.")
         end
    +
         components[manager].first
       end
     end
    @@ -596,12 +598,12 @@
     
     
    -15
     16
    -17
    +17 +18
    -
    # File 'lib/felflame/entity_manager.rb', line 15
    +      
    # File 'lib/felflame/entity_manager.rb', line 16
     
     def components
       @components ||= {}
    @@ -655,7 +657,6 @@
           
     
     
    -42
     43
     44
     45
    @@ -664,13 +665,14 @@
     48
     49
     50
    -51
    +51 +52
    -
    # File 'lib/felflame/entity_manager.rb', line 42
    +      
    # File 'lib/felflame/entity_manager.rb', line 43
     
     def delete
    -  components.each do |component_manager, component_array|
    +  components.each do |_component_manager, component_array|
         component_array.reverse_each do |component|
           component.entities.delete(self)
         end
    @@ -748,7 +750,6 @@
           
     
     
    -86
     87
     88
     89
    @@ -757,20 +758,17 @@
     92
     93
     94
    -95
    -96
    +95
    -
    # File 'lib/felflame/entity_manager.rb', line 86
    +      
    # File 'lib/felflame/entity_manager.rb', line 87
     
     def remove(*components_to_remove)
       components_to_remove.each do |component|
         check_systems component, :removal_triggers if component.entities.include? self
         component.entities.delete self
         components[component.class].delete component
    -    if components[component.class].empty?
    -      components.delete component.class
    -    end
    +    components.delete component.class if components[component.class].empty?
       end
       true
     end
    @@ -784,7 +782,7 @@ diff --git a/docs/FelFlame/Order.html b/docs/FelFlame/Order.html new file mode 100644 index 0000000..b17a786 --- /dev/null +++ b/docs/FelFlame/Order.html @@ -0,0 +1,172 @@ + + + + + + + Module: FelFlame::Order + + — Documentation by YARD 0.9.26 + + + + + + + + + + + + + + + + + + + +
    + + +

    Module: FelFlame::Order + + + +

    +
    + + + + + + + + + + + +
    +
    Defined in:
    +
    lib/felflame/order.rb
    +
    + +
    + + + + + + + + + +

    + Instance Method Summary + collapse +

    + + + + + + +
    +

    Instance Method Details

    + + +
    +

    + + #sort(*sortables) ⇒ Object + + + + + +

    + + + + +
    +
    +
    +
    +3
    +4
    +
    +
    # File 'lib/felflame/order.rb', line 3
    +
    +def sort(*sortables)
    +end
    +
    +
    + +
    + +
    + + + +
    + + \ No newline at end of file diff --git a/docs/FelFlame/Scenes.html b/docs/FelFlame/Scenes.html index 5a73e20..6245fa6 100644 --- a/docs/FelFlame/Scenes.html +++ b/docs/FelFlame/Scenes.html @@ -106,8 +106,6 @@

    Creates and manages Scenes. Scenes are collections of Systems, and execute all the Systems when called upon. Any scenes you create are accessable under the Scenes namespace as Constants.

    -

    TODO: Improve Scenes overview

    - @@ -364,13 +362,13 @@
     
     
    -20
    -21
     22
    -23
    +23 +24 +25
    -
    # File 'lib/felflame/scene_manager.rb', line 20
    +      
    # File 'lib/felflame/scene_manager.rb', line 22
     
     def initialize(name, priority: 0)
       self.priority = priority
    @@ -414,12 +412,12 @@
           
     
     
    -10
    -11
    -12
    +12 +13 +14
    -
    # File 'lib/felflame/scene_manager.rb', line 10
    +      
    # File 'lib/felflame/scene_manager.rb', line 12
     
     def priority
       @priority
    @@ -470,12 +468,12 @@
           
     
     
    -27
    -28
    -29
    +29 +30 +31
    -
    # File 'lib/felflame/scene_manager.rb', line 27
    +      
    # File 'lib/felflame/scene_manager.rb', line 29
     
     def systems
       @systems ||= []
    @@ -536,17 +534,17 @@
           
     
     
    -40
    -41
     42
     43
     44
     45
     46
    -47
    +47 +48 +49
    -
    # File 'lib/felflame/scene_manager.rb', line 40
    +      
    # File 'lib/felflame/scene_manager.rb', line 42
     
     def add(*systems_to_add)
       self.systems |= systems_to_add
    @@ -605,13 +603,13 @@
           
     
     
    -33
    -34
     35
    -36
    +36 +37 +38
    -
    # File 'lib/felflame/scene_manager.rb', line 33
    +      
    # File 'lib/felflame/scene_manager.rb', line 35
     
     def call
       systems.each(&:call)
    @@ -666,24 +664,24 @@
           
     
     
    -58
    -59
     60
     61
     62
     63
     64
    -65
    +65 +66 +67
    -
    # File 'lib/felflame/scene_manager.rb', line 58
    +      
    # File 'lib/felflame/scene_manager.rb', line 60
     
     def clear
       systems.each do |system|
         system.scenes.delete self
       end
       systems.clear
    -  #FelFlame::Stage.update_systems_list if FelFlame::Stage.scenes.include? self
    +  # FelFlame::Stage.update_systems_list if FelFlame::Stage.scenes.include? self
       true
     end
    @@ -735,13 +733,13 @@
     
     
    -51
    -52
     53
    -54
    +54 +55 +56
    -
    # File 'lib/felflame/scene_manager.rb', line 51
    +      
    # File 'lib/felflame/scene_manager.rb', line 53
     
     def remove(*systems_to_remove)
       self.systems -= systems_to_remove
    @@ -757,7 +755,7 @@
     
     
           
    diff --git a/docs/FelFlame/Stage.html b/docs/FelFlame/Stage.html
    index 892810b..e944f44 100644
    --- a/docs/FelFlame/Stage.html
    +++ b/docs/FelFlame/Stage.html
    @@ -289,12 +289,12 @@
           
     
     
    -40
    -41
    -42
    +42 +43 +44
    -
    # File 'lib/felflame/stage_manager.rb', line 40
    +      
    # File 'lib/felflame/stage_manager.rb', line 42
     
     def scenes
       @scenes ||= []
    @@ -355,14 +355,14 @@
           
     
     
    -11
    -12
     13
     14
    -15
    +15 +16 +17
    -
    # File 'lib/felflame/stage_manager.rb', line 11
    +      
    # File 'lib/felflame/stage_manager.rb', line 13
     
     def add(*scenes_to_add)
       self.scenes |= scenes_to_add
    @@ -386,7 +386,7 @@
     
    -

    Executes one frame of the game. This executes all the Systems in the Scenes added to the Stage. Systems that exist in two or more different Scenes will still only get executed once.

    +

    Executes one frame of the game. This executes all the Scenes added to the Stage in order of their priority.

    @@ -418,13 +418,13 @@
     
     
    -33
    -34
     35
    -36
    +36 +37 +38
    -
    # File 'lib/felflame/stage_manager.rb', line 33
    +      
    # File 'lib/felflame/stage_manager.rb', line 35
     
     def call
       self.scenes.each(&:call)
    @@ -479,13 +479,13 @@
           
     
     
    -26
    -27
     28
    -29
    +29 +30 +31
    -
    # File 'lib/felflame/stage_manager.rb', line 26
    +      
    # File 'lib/felflame/stage_manager.rb', line 28
     
     def clear
       self.scenes.clear
    @@ -540,13 +540,13 @@
           
     
     
    -19
    -20
     21
    -22
    +22 +23 +24
    -
    # File 'lib/felflame/stage_manager.rb', line 19
    +      
    # File 'lib/felflame/stage_manager.rb', line 21
     
     def remove(*scenes_to_remove)
       self.scenes -= scenes_to_remove
    @@ -562,7 +562,7 @@
     
     
           
    diff --git a/docs/FelFlame/Systems.html b/docs/FelFlame/Systems.html
    index 7f5d18c..be6a374 100644
    --- a/docs/FelFlame/Systems.html
    +++ b/docs/FelFlame/Systems.html
    @@ -104,9 +104,7 @@
     

    Overview

    -

    Creates an manages Systems. Systems are the logic of the game and do not contain any data within them. Any systems you create are accessable under the Systems namespace as Constants.

    - -

    TODO: Improve Systems overview

    +

    Creates and manages Systems. Systems are the logic of the game and do not contain any data within them. Any systems you create are accessable under the Systems namespace as Constants. You can use array methods directly on this class to access Systems.

    @@ -576,16 +574,16 @@
     
     
    +115
     116
     117
     118
     119
     120
    -121
    -122
    +121
    -
    # File 'lib/felflame/system_manager.rb', line 116
    +      
    # File 'lib/felflame/system_manager.rb', line 115
     
     def initialize(name, priority: 0, &block)
       FelFlame::Systems.const_set(name, self)
    @@ -645,12 +643,12 @@
           
     
     
    -33
    -34
    -35
    +35 +36 +37
    -
    # File 'lib/felflame/system_manager.rb', line 33
    +      
    # File 'lib/felflame/system_manager.rb', line 35
     
     def addition_triggers
       @addition_triggers ||= []
    @@ -701,12 +699,12 @@
           
     
     
    -51
     52
    -53
    +53 +54
    -
    # File 'lib/felflame/system_manager.rb', line 51
    +      
    # File 'lib/felflame/system_manager.rb', line 52
     
     def attr_triggers
       @attr_triggers ||= {}
    @@ -744,12 +742,12 @@
           
     
     
    -4
    -5
    -6
    +6 +7 +8
    -
    # File 'lib/felflame/system_manager.rb', line 4
    +      
    # File 'lib/felflame/system_manager.rb', line 6
     
     def priority
       @priority
    @@ -800,12 +798,12 @@
           
     
     
    -42
    -43
    -44
    +44 +45 +46
    -
    # File 'lib/felflame/system_manager.rb', line 42
    +      
    # File 'lib/felflame/system_manager.rb', line 44
     
     def removal_triggers
       @removal_triggers ||= []
    @@ -832,12 +830,12 @@
           
     
     
    -17
    -18
    -19
    +19 +20 +21
    -
    # File 'lib/felflame/system_manager.rb', line 17
    +      
    # File 'lib/felflame/system_manager.rb', line 19
     
     def scenes
       @scenes ||= []
    @@ -927,12 +925,12 @@
           
     
     
    +124
     125
    -126
    -127
    +126
    -
    # File 'lib/felflame/system_manager.rb', line 125
    +      
    # File 'lib/felflame/system_manager.rb', line 124
     
     def call
       @block.call
    @@ -1110,23 +1108,22 @@
     219
     220
     221
    -222
    -223
    +222
    # File 'lib/felflame/system_manager.rb', line 157
     
     def clear_triggers(*trigger_types, component_or_manager: nil)
    -  trigger_types = [:addition_triggers, :removal_triggers, :attr_triggers] if trigger_types.empty?
    +  trigger_types = %i[addition_triggers removal_triggers attr_triggers] if trigger_types.empty?
     
       if trigger_types.include? :attr_triggers
    -    if (trigger_types - [:addition_triggers,
    -        :removal_triggers,
    -        :attr_triggers]).empty?
    +    if (trigger_types - %i[addition_triggers
    +                           removal_triggers
    +                           attr_triggers]).empty?
     
           if component_or_manager.nil?
    -        #remove all attrs
    -        self.attr_triggers.each do |cmp_or_mgr, attrs|
    +        # remove all attrs
    +        attr_triggers.each do |cmp_or_mgr, attrs|
               attrs.each do |attr|
                 next if cmp_or_mgr.attr_triggers[attr].nil?
     
    @@ -1135,49 +1132,48 @@
               self.attr_triggers = {}
             end
           else
    -        #remove attrs relevant to comp_or_man
    -        unless self.attr_triggers[component_or_manager].nil?
    -          self.attr_triggers[component_or_manager].each do |attr|
    +        # remove attrs relevant to comp_or_man
    +        unless attr_triggers[component_or_manager].nil?
    +          attr_triggers[component_or_manager].each do |attr|
                 component_or_manager.attr_triggers[attr].delete self
               end
    -          self.attr_triggers[component_or_manager] = []
    +          attr_triggers[component_or_manager] = []
             end
           end
     
    -    else
    +    elsif component_or_manager.nil?
     
    -      if component_or_manager.nil?
    -        (trigger_types - [:addition_triggers, :removal_triggers, :attr_triggers]).each do |attr|
    -          #remove attr
    -          self.attr_triggers.each do |cmp_or_mgr, attrs|
    -            cmp_or_mgr.attr_triggers[attr].delete self
    -          end
    +      (trigger_types - %i[addition_triggers removal_triggers attr_triggers]).each do |attr|
    +        # remove attr
    +        attr_triggers.each do |cmp_or_mgr, _attrs|
    +          cmp_or_mgr.attr_triggers[attr].delete self
             end
    -        self.attr_triggers.delete (trigger_types - [:addition_triggers,
    -                                                    :removal_triggers,
    -                                                    :attr_triggers])
    -      else
    -        #remove attr from component_or_manager
    -        (trigger_types - [:addition_triggers, :removal_triggers, :attr_triggers]).each do |attr|
    -          next if component_or_manager.attr_triggers[attr].nil?
    -          component_or_manager.attr_triggers[attr].delete self
    -        end
    -        self.attr_triggers[component_or_manager] -= trigger_types unless self.attr_triggers[component_or_manager].nil?
           end
    +      attr_triggers.delete(trigger_types - %i[addition_triggers
    +                                              removal_triggers
    +                                              attr_triggers])
    +    else
    +      # remove attr from component_or_manager
    +      (trigger_types - %i[addition_triggers removal_triggers attr_triggers]).each do |attr|
    +        next if component_or_manager.attr_triggers[attr].nil?
    +
    +        component_or_manager.attr_triggers[attr].delete self
    +      end
    +      attr_triggers[component_or_manager] -= trigger_types unless attr_triggers[component_or_manager].nil?
     
         end
       end
     
    -  (trigger_types & [:removal_triggers, :addition_triggers] - [:attr_triggers]).each do |trigger_type|
    +  (trigger_types & %i[removal_triggers addition_triggers] - [:attr_triggers]).each do |trigger_type|
         if component_or_manager.nil?
    -      #remove all removal triggers
    -      self.send(trigger_type).each do |trigger|
    +      # remove all removal triggers
    +      send(trigger_type).each do |trigger|
             trigger.send(trigger_type).delete self
           end
    -      self.send("#{trigger_type.to_s}=", [])
    +      send("#{trigger_type}=", [])
         else
    -      #remove removal trigger relevant to comp/man
    -      self.send(trigger_type).delete component_or_manager
    +      # remove removal trigger relevant to comp/man
    +      send(trigger_type).delete component_or_manager
           component_or_manager.send(trigger_type).delete self
         end
       end
    @@ -1313,14 +1309,14 @@
           
     
     
    +227
     228
     229
     230
    -231
    -232
    +231
    -
    # File 'lib/felflame/system_manager.rb', line 228
    +      
    # File 'lib/felflame/system_manager.rb', line 227
     
     def trigger_when_added(component_or_manager)
       self.addition_triggers |= [component_or_manager]
    @@ -1376,6 +1372,7 @@
           
     
     
    +244
     245
     246
     247
    @@ -1387,11 +1384,10 @@
     253
     254
     255
    -256
    -257
    +256
    -
    # File 'lib/felflame/system_manager.rb', line 245
    +      
    # File 'lib/felflame/system_manager.rb', line 244
     
     def trigger_when_is_changed(component_or_manager, attr)
       if component_or_manager.attr_triggers[attr].nil?
    @@ -1399,10 +1395,10 @@
       else
         component_or_manager.attr_triggers[attr] |= [self]
       end
    -  if self.attr_triggers[component_or_manager].nil?
    -    self.attr_triggers[component_or_manager] = [attr]
    +  if attr_triggers[component_or_manager].nil?
    +    attr_triggers[component_or_manager] = [attr]
       else
    -    self.attr_triggers[component_or_manager] |= [attr]
    +    attr_triggers[component_or_manager] |= [attr]
       end
       true
     end
    @@ -1475,14 +1471,14 @@
     
     
    +236
     237
     238
     239
    -240
    -241
    +240
    -
    # File 'lib/felflame/system_manager.rb', line 237
    +      
    # File 'lib/felflame/system_manager.rb', line 236
     
     def trigger_when_removed(component_or_manager)
       self.removal_triggers |= [component_or_manager]
    @@ -1499,7 +1495,7 @@
     
     
           
    diff --git a/docs/Felflame_.html b/docs/Felflame_.html
    index eda8518..ac59bac 100644
    --- a/docs/Felflame_.html
    +++ b/docs/Felflame_.html
    @@ -117,7 +117,7 @@
     
     
             
    -        
    "3.0.0"
    +
    '3.0.0'
    @@ -133,7 +133,7 @@ diff --git a/docs/_index.html b/docs/_index.html index a183a99..d3becf8 100644 --- a/docs/_index.html +++ b/docs/_index.html @@ -131,6 +131,21 @@ +
      +
    • O
    • +
        + +
      • + Order + + (FelFlame) + +
      • + +
      +
    + +

    Adding and Removing Components

    @@ -234,14 +229,18 @@ entity where a new entity will claim that ID. To get the ID of an Entity:

    Accessing Entities' Attached Components

    +

    This is the most common way of accessing an Entity

    +

    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:

    -
    @entity.components[@component_manager] # => [@component1, @component2, component3]
    +
    @entity.components[@component_manager] # => [@component1, @component2, @component3]
     

    Deletion

    -

    To have all Components from an Entity removed and the Entity deleted we do the following:

    +

    To have all Components from an Entity removed and the Entity deleted we do the following:

    + +

    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.

    @entity.delete
     
    @@ -270,19 +269,18 @@ When defining attributes symbols should be used.

    @component = FelFlame::Components::Stats.new
     
    -

    Or we can even change the defaults:

    +

    Or we can even override the defaults when creating the component:

    @component = FelFlame::Components::Stats.new(armour: 'steel')
     
    -

    Accessing and Getting ID

    +

    Accessing

    -

    Just like Entities, Components have IDs. -These IDs are only unique within the scope of their respective Component Managers. -Here is how we can get the ID, as well as how to access a Component from its Component Manager.

    +

    You can access components using any array method.

    @component = FelFlame::Components::Stats[2]
    -@component.id # => 2
    +@component = FelFlame::Components::Stats.first
    +@component = FelFlame::Components::Stats.each # you can use iterators this way
     

    Accessing Attributes and Changing Them

    @@ -295,30 +293,26 @@ Here are the ways to edit attrubutes, followed by the ways to read them.

    @component.hp # => 95
    -@component.attrs # => {armour: 'Leather', hp: 95}
    +@component.to_h # => {armour: 'Leather', hp: 95}
     

    Deleting Components

    -

    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.

    +

    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.

    @component.delete
     
    -

    Iterating over Components

    - -

    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:

    - -
    FelFlame::Components::Sprites.each do |component|
    -  #do something with components
    -end
    -
    -

    Accessing Components' attached Entities

    Components also keep track of what Entities are using it. To access this list we do the following:

    @component.entities # => [@entity1, @entity2, @entity3]
    +
    +# get the first entity attached.
    +# this will throw a warning if there is more or less then
    +# exactly one entity
    +@component.entity # => @entity
     

    Systems

    @@ -339,7 +333,9 @@ Here are the ways to edit attrubutes, followed by the ways to read them.

    Priority determines the order Systems should be executed, this is used for Scenes and the Stage. The lower the number, the earlier a given System will be executed. -E.g priority 1 will go first, priority 2 will go second, etcetera.

    +E.g priority 1 will go first, priority 2 will go second, etcetera.

    + +

    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.

    Often we will want to execute some logic on each Component in a given Component Manager so our code might look like this:

    @@ -437,7 +433,7 @@ E.g priority 1 will go first, priority 2 will go second, etcetera.

    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 will occur even if they are not part of a Scene. Here is how we make a new Scene:

    -
    @scene = FelFlame::Scenes.new('ExampleScene')
    +
    @scene = FelFlame::Scenes.new('ExampleScene', priority: 5)
     

    Accessing

    @@ -451,14 +447,22 @@ E.g priority 1 will go first, priority 2 will go second, etcetera.

    Adding Systems is simple. We can add as many as we want. In this example we add 3 different systems:

    -
    FelFlame::Scenes::ExampleScene.add(FelFlame::Systems::Render, @system2, @system3)
    +
    FelFlame::Scenes::ExampleScene.add(
    +  FelFlame::Systems::Render,
    +  @system2,
    +  @system3
    +)
     

    Removing Systems

    -

    Removing Systems works simularly:

    +

    Removing Systems works similarly:

    -
    FelFlame::Scenes::ExampleScene.remove(FelFlame::Systems::Render, @system2, @system3)
    +
    FelFlame::Scenes::ExampleScene.remove(
    +  FelFlame::Systems::Render,
    +  @system2,
    +  @system3
    +)
     

    Clearing

    @@ -481,7 +485,7 @@ E.g priority 1 will go first, priority 2 will go second, etcetera.

    Adding Scenes

    -

    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:

    +

    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:

    FelFlame::Stage.add FelFlame::Scene::ExampleScene
     
    @@ -495,7 +499,7 @@ E.g priority 1 will go first, priority 2 will go second, etcetera.

    Executing

    -

    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:

    +

    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:

    FelFlame::Stage.call
     
    @@ -514,7 +518,7 @@ E.g priority 1 will go first, priority 2 will go second, etcetera.

    diff --git a/docs/index.html b/docs/index.html index 5333a27..916cce2 100644 --- a/docs/index.html +++ b/docs/index.html @@ -76,11 +76,11 @@

    Adding and Removing Components

    @@ -234,14 +229,18 @@ entity where a new entity will claim that ID. To get the ID of an Entity:

    Accessing Entities' Attached Components

    +

    This is the most common way of accessing an Entity

    +

    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:

    -
    @entity.components[@component_manager] # => [@component1, @component2, component3]
    +
    @entity.components[@component_manager] # => [@component1, @component2, @component3]
     

    Deletion

    -

    To have all Components from an Entity removed and the Entity deleted we do the following:

    +

    To have all Components from an Entity removed and the Entity deleted we do the following:

    + +

    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.

    @entity.delete
     
    @@ -270,19 +269,18 @@ When defining attributes symbols should be used.

    @component = FelFlame::Components::Stats.new
     
    -

    Or we can even change the defaults:

    +

    Or we can even override the defaults when creating the component:

    @component = FelFlame::Components::Stats.new(armour: 'steel')
     
    -

    Accessing and Getting ID

    +

    Accessing

    -

    Just like Entities, Components have IDs. -These IDs are only unique within the scope of their respective Component Managers. -Here is how we can get the ID, as well as how to access a Component from its Component Manager.

    +

    You can access components using any array method.

    @component = FelFlame::Components::Stats[2]
    -@component.id # => 2
    +@component = FelFlame::Components::Stats.first
    +@component = FelFlame::Components::Stats.each # you can use iterators this way
     

    Accessing Attributes and Changing Them

    @@ -295,30 +293,26 @@ Here are the ways to edit attrubutes, followed by the ways to read them.

    @component.hp # => 95
    -@component.attrs # => {armour: 'Leather', hp: 95}
    +@component.to_h # => {armour: 'Leather', hp: 95}
     

    Deleting Components

    -

    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.

    +

    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.

    @component.delete
     
    -

    Iterating over Components

    - -

    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:

    - -
    FelFlame::Components::Sprites.each do |component|
    -  #do something with components
    -end
    -
    -

    Accessing Components' attached Entities

    Components also keep track of what Entities are using it. To access this list we do the following:

    @component.entities # => [@entity1, @entity2, @entity3]
    +
    +# get the first entity attached.
    +# this will throw a warning if there is more or less then
    +# exactly one entity
    +@component.entity # => @entity
     

    Systems

    @@ -339,7 +333,9 @@ Here are the ways to edit attrubutes, followed by the ways to read them.

    Priority determines the order Systems should be executed, this is used for Scenes and the Stage. The lower the number, the earlier a given System will be executed. -E.g priority 1 will go first, priority 2 will go second, etcetera.

    +E.g priority 1 will go first, priority 2 will go second, etcetera.

    + +

    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.

    Often we will want to execute some logic on each Component in a given Component Manager so our code might look like this:

    @@ -437,7 +433,7 @@ E.g priority 1 will go first, priority 2 will go second, etcetera.

    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 will occur even if they are not part of a Scene. Here is how we make a new Scene:

    -
    @scene = FelFlame::Scenes.new('ExampleScene')
    +
    @scene = FelFlame::Scenes.new('ExampleScene', priority: 5)
     

    Accessing

    @@ -451,14 +447,22 @@ E.g priority 1 will go first, priority 2 will go second, etcetera.

    Adding Systems is simple. We can add as many as we want. In this example we add 3 different systems:

    -
    FelFlame::Scenes::ExampleScene.add(FelFlame::Systems::Render, @system2, @system3)
    +
    FelFlame::Scenes::ExampleScene.add(
    +  FelFlame::Systems::Render,
    +  @system2,
    +  @system3
    +)
     

    Removing Systems

    -

    Removing Systems works simularly:

    +

    Removing Systems works similarly:

    -
    FelFlame::Scenes::ExampleScene.remove(FelFlame::Systems::Render, @system2, @system3)
    +
    FelFlame::Scenes::ExampleScene.remove(
    +  FelFlame::Systems::Render,
    +  @system2,
    +  @system3
    +)
     

    Clearing

    @@ -481,7 +485,7 @@ E.g priority 1 will go first, priority 2 will go second, etcetera.

    Adding Scenes

    -

    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:

    +

    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:

    FelFlame::Stage.add FelFlame::Scene::ExampleScene
     
    @@ -495,7 +499,7 @@ E.g priority 1 will go first, priority 2 will go second, etcetera.

    Executing

    -

    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:

    +

    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:

    FelFlame::Stage.call
     
    @@ -514,7 +518,7 @@ E.g priority 1 will go first, priority 2 will go second, etcetera.

    diff --git a/docs/method_list.html b/docs/method_list.html index d8253e9..e0c8da1 100644 --- a/docs/method_list.html +++ b/docs/method_list.html @@ -93,14 +93,6 @@
  • -
    - #attr_changed_trigger_systems - FelFlame::ComponentManager -
    -
  • - - -
  • #attr_triggers FelFlame::Systems @@ -108,7 +100,7 @@
  • -
  • +
  • #attr_triggers FelFlame::ComponentManager @@ -116,7 +108,7 @@
  • -
  • +
  • attr_triggers FelFlame::ComponentManager @@ -124,7 +116,7 @@
  • -
  • +
  • call FelFlame @@ -132,7 +124,7 @@
  • -
  • +
  • #call FelFlame::Scenes @@ -140,7 +132,7 @@
  • -
  • +
  • call FelFlame::Stage @@ -148,7 +140,7 @@
  • -
  • +
  • #call FelFlame::Systems @@ -156,7 +148,7 @@
  • -
  • +
  • #clear FelFlame::Scenes @@ -164,7 +156,7 @@
  • -
  • +
  • clear FelFlame::Stage @@ -172,7 +164,7 @@
  • -
  • +
  • #clear_triggers FelFlame::Systems @@ -180,7 +172,7 @@
  • -
  • +
  • #component FelFlame::Entities @@ -188,7 +180,7 @@
  • -
  • +
  • #components FelFlame::Entities @@ -196,7 +188,7 @@
  • -
  • +
  • const_cache FelFlame::Systems @@ -204,7 +196,7 @@
  • -
  • +
  • #delete FelFlame::Entities @@ -212,7 +204,7 @@
  • -
  • +
  • #delete FelFlame::ComponentManager @@ -220,7 +212,7 @@
  • -
  • +
  • #entities FelFlame::ComponentManager @@ -228,7 +220,7 @@
  • -
  • +
  • #entity FelFlame::ComponentManager @@ -236,7 +228,7 @@
  • -
  • +
  • #initialize FelFlame::Scenes @@ -244,7 +236,7 @@
  • -
  • +
  • #initialize FelFlame::Entities @@ -252,7 +244,7 @@
  • -
  • +
  • #initialize FelFlame::Systems @@ -260,7 +252,7 @@
  • -
  • +
  • #initialize FelFlame::ComponentManager @@ -268,7 +260,7 @@
  • -
  • +
  • new FelFlame::Components @@ -276,7 +268,7 @@
  • -
  • +
  • #priority FelFlame::Scenes @@ -284,7 +276,7 @@
  • -
  • +
  • #priority FelFlame::Systems @@ -292,7 +284,7 @@
  • -
  • +
  • #redefine FelFlame::Systems @@ -300,7 +292,7 @@
  • -
  • +
  • #removal_triggers FelFlame::Systems @@ -308,7 +300,7 @@
  • -
  • +
  • #removal_triggers FelFlame::ComponentManager @@ -316,7 +308,7 @@
  • -
  • +
  • removal_triggers FelFlame::ComponentManager @@ -324,7 +316,7 @@
  • -
  • +
  • #remove FelFlame::Scenes @@ -332,7 +324,7 @@
  • -
  • +
  • remove FelFlame::Stage @@ -340,7 +332,7 @@
  • -
  • +
  • #remove FelFlame::Entities @@ -348,7 +340,7 @@
  • -
  • +
  • scenes FelFlame::Stage @@ -356,7 +348,7 @@
  • -
  • +
  • #scenes FelFlame::Systems @@ -364,6 +356,14 @@
  • +
  • +
    + #sort + FelFlame::Order +
    +
  • + +
  • #systems diff --git a/docs/top-level-namespace.html b/docs/top-level-namespace.html index 9462bb1..78ec112 100644 --- a/docs/top-level-namespace.html +++ b/docs/top-level-namespace.html @@ -127,7 +127,7 @@
    diff --git a/felflame.gemspec b/felflame.gemspec index a0f8c7b..6f26e6f 100644 --- a/felflame.gemspec +++ b/felflame.gemspec @@ -1,44 +1,44 @@ # frozen_string_literal: true -require_relative "lib/felflame/version" +require_relative 'lib/felflame/version' Gem::Specification.new do |spec| - spec.name = "felflame" + spec.name = 'felflame' spec.version = Felflame::VERSION - spec.authors = ["Tradam"] - spec.email = ["felflame@tradam.dev"] + spec.authors = ['Tradam'] + spec.email = ['felflame@tradam.dev'] - spec.summary = "The Engine Agnostic ECS Ruby Framework" - #spec.description = "TODO: Write a longer description or delete this line." - spec.homepage = "https://felflame.tradam.fyi" - spec.license = "MIT" - spec.required_ruby_version = ">= 2.4.0" + spec.summary = 'The Engine Agnostic ECS Ruby Framework' + # spec.description = "TODO: Write a longer description or delete this line." + spec.homepage = 'https://felflame.tradam.fyi' + spec.license = 'MIT' + spec.required_ruby_version = '>= 2.4.0' - #spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'" + # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'" - spec.metadata["homepage_uri"] = spec.homepage - spec.metadata["source_code_uri"] = "https://github.com/realtradam/FelFlame" - #spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here." + spec.metadata['homepage_uri'] = spec.homepage + spec.metadata['source_code_uri'] = 'https://github.com/realtradam/FelFlame' + # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here." # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. spec.files = Dir.chdir(File.expand_path(__dir__)) do `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features|deprecated|codeclimate|logos)/}) } end - spec.bindir = "exe" + spec.bindir = 'exe' spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } - spec.require_paths = ["lib"] + spec.require_paths = ['lib'] # Uncomment to register a new dependency of your gem # spec.add_dependency "example-gem", "~> 1.0" - spec.add_development_dependency 'minitest-reporters', '~> 1.4', '>= 1.4.3'#, require: false + spec.add_development_dependency 'minitest-reporters', '~> 1.4', '>= 1.4.3' # , require: false + spec.add_development_dependency 'redcarpet', '~> 3.5', '>= 3.5.1' # , require: false spec.add_development_dependency 'rspec', '~> 3.10' - spec.add_development_dependency 'simplecov', '~> 0.21.2'#, require: false - spec.add_development_dependency 'simplecov-console', '~> 0.9.1' - spec.add_development_dependency 'simplecov_json_formatter', '~> 0.1.3'#, require: false - spec.add_development_dependency 'redcarpet', '~> 3.5', '>= 3.5.1'#, require: false - spec.add_development_dependency 'yard', '~> 0.9.26'#, require: false spec.add_development_dependency 'rubocop', '~> 1.7' + spec.add_development_dependency 'simplecov', '~> 0.21.2' # , require: false + spec.add_development_dependency 'simplecov-console', '~> 0.9.1' + spec.add_development_dependency 'simplecov_json_formatter', '~> 0.1.3' # , require: false + spec.add_development_dependency 'yard', '~> 0.9.26' # , require: false # For more information and examples about making a new gem, checkout our # guide at: https://bundler.io/guides/creating_gem.html diff --git a/lib/felflame.rb b/lib/felflame.rb index 54084bf..b7a386a 100644 --- a/lib/felflame.rb +++ b/lib/felflame.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'felflame/entity_manager' require_relative 'felflame/component_manager' require_relative 'felflame/system_manager' @@ -8,7 +10,7 @@ require_relative 'felflame/version' # The FelFlame namespace where all its functionality resides under. module FelFlame - class <] A hash, where all the keys are attributes linked to their respective values. + # @return [Hash] A hash, where all the keys are attributes storing their respective values. def to_h return_hash = instance_variables.each_with_object({}) do |key, final| final[key.to_s.delete_prefix('@').to_sym] = instance_variable_get(key) @@ -294,8 +292,8 @@ module FelFlame # Export all data into a JSON String, which could then later be loaded or saved to a file # TODO: This function is not yet complete # @return [String] a JSON formatted String - #def to_json + # def to_json # # should return a json or hash of all data in this component - #end + # end end end diff --git a/lib/felflame/entity_manager.rb b/lib/felflame/entity_manager.rb index 2ae0849..ef70510 100644 --- a/lib/felflame/entity_manager.rb +++ b/lib/felflame/entity_manager.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true + module FelFlame class Entities - # Creating a new Entity # @param components [Components] Can be any number of components, identical duplicates will be automatically purged however different components from the same component manager are allowed. # @return [Entity] @@ -16,9 +17,9 @@ module FelFlame @components ||= {} end - # A single component from a component manager. Use this if you expect the component to only belong to one entity and you want to access it. Access the component using either parameter notation or array notation. + # A single component from a component manager. Use this if you expect the component to only belong to one entity and you want to access it. Access the component using either parameter notation or array notation. Array notation is conventional for better readablility. # @example - # @entity.component[@component_manager] # array notation + # @entity.component[@component_manager] # array notation(the standard) # @entity.component(@component_manager) # method notation # @param manager [ComponentManager] If you pass nil you can then use array notation to access the same value. # @return [Component] @@ -32,15 +33,15 @@ module FelFlame elsif components[manager].length > 1 Warning.warn("This entity has MANY of this component but you called the method that is intended for having a single of this component type.\nYou may have a bug in your logic.") end + components[manager].first end end - # Removes this Entity from the list and purges all references to this Entity from other Components, as well as its data. # @return [Boolean] +true+ def delete - components.each do |component_manager, component_array| + components.each do |_component_manager, component_array| component_array.reverse_each do |component| component.entities.delete(self) end @@ -88,9 +89,7 @@ module FelFlame check_systems component, :removal_triggers if component.entities.include? self component.entities.delete self components[component.class].delete component - if components[component.class].empty? - components.delete component.class - end + components.delete component.class if components[component.class].empty? end true end @@ -98,14 +97,14 @@ module FelFlame # Export all data into a JSON String which can then be saved into a file # TODO: This function is not yet complete # @return [String] A JSON formatted String - #def to_json() end + # def to_json() end - class <] Array of all Entities that exist # @!visibility private def _data @@ -158,7 +154,7 @@ module FelFlame # TODO: This function is not yet complete # @param json_string [String] A string that was exported originally using the {FelFlame::Entities#to_json to_json} function # @param opts [Keywords] What values(its {FelFlame::Entities#id ID} or the {FelFlame::ComponentManager#id component IDs}) should be overwritten TODO: this might change - #def from_json(json_string, **opts) end + # def from_json(json_string, **opts) end end end end diff --git a/lib/felflame/order.rb b/lib/felflame/order.rb new file mode 100644 index 0000000..0bed66b --- /dev/null +++ b/lib/felflame/order.rb @@ -0,0 +1,6 @@ +module FelFlame + module Order + def sort(*sortables) + end + end +end diff --git a/lib/felflame/scene_manager.rb b/lib/felflame/scene_manager.rb index 9ac7924..0024815 100644 --- a/lib/felflame/scene_manager.rb +++ b/lib/felflame/scene_manager.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module FelFlame class Scenes # Allows overwriting the storage of systems, such as for clearing. @@ -60,7 +62,7 @@ module FelFlame system.scenes.delete self end systems.clear - #FelFlame::Stage.update_systems_list if FelFlame::Stage.scenes.include? self + # FelFlame::Stage.update_systems_list if FelFlame::Stage.scenes.include? self true end end diff --git a/lib/felflame/stage_manager.rb b/lib/felflame/stage_manager.rb index 50dad5f..a192b67 100644 --- a/lib/felflame/stage_manager.rb +++ b/lib/felflame/stage_manager.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + module FelFlame module Stage - class < [@cmp0,@cmp1,@cmp2]}) - expect(@cmp0.entities).to eq([@ent0,@ent1]) - expect(@cmp1.entities).to eq([@ent0,@ent1,@ent2]) - expect(@cmp2.entities).to eq([@ent0,@ent2]) + expect(@ent0.components).to eq({ @component_manager => [@cmp0, @cmp1, @cmp2] }) + expect(@cmp0.entities).to eq([@ent0, @ent1]) + expect(@cmp1.entities).to eq([@ent0, @ent1, @ent2]) + expect(@cmp2.entities).to eq([@ent0, @ent2]) @ent1.delete expect(@cmp0.entities).to eq([@ent0]) - expect(@cmp1.entities).to eq([@ent0,@ent2]) - expect(@cmp2.entities).to eq([@ent0,@ent2]) + expect(@cmp1.entities).to eq([@ent0, @ent2]) + expect(@cmp2.entities).to eq([@ent0, @ent2]) @cmp1.delete - expect(@ent0.components).to eq({@component_manager => [@cmp0,@cmp2]}) + expect(@ent0.components).to eq({ @component_manager => [@cmp0, @cmp2] }) @component_manager.reverse_each(&:delete) expect(@component_manager.length).to eq(0) expect(@component_manager.empty?).to be true diff --git a/spec/scene_manager_spec.rb b/spec/scene_manager_spec.rb index 3f305b9..e1984dc 100644 --- a/spec/scene_manager_spec.rb +++ b/spec/scene_manager_spec.rb @@ -1,6 +1,8 @@ -require_relative '../lib/felflame.rb' +# frozen_string_literal: true -#class EntitiesTest < Minitest::Test +require_relative '../lib/felflame' + +# class EntitiesTest < Minitest::Test describe 'Scenes' do before :all do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0d826a1..797ff0f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file was generated by the `rspec --init` command. Conventionally, all # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. # The generated `.rspec` file contains `--require spec_helper` which will cause @@ -20,15 +22,15 @@ RSpec.configure do |config| SimpleCov.start do add_filter 'spec' add_filter 'deprecated' - add_group "Ignored Code" do |src_file| + add_group 'Ignored Code' do |src_file| open(src_file.filename).grep(/:nocov:/).any? end SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([ - SimpleCov::Formatter::Console, - SimpleCov::Formatter::HTMLFormatter, - SimpleCov::Formatter::JSONFormatter - #SimpleCovSmallBadge::Formatter - ]) + SimpleCov::Formatter::Console, + SimpleCov::Formatter::HTMLFormatter, + SimpleCov::Formatter::JSONFormatter + # SimpleCovSmallBadge::Formatter + ]) end # rspec-expectations config goes here. You can use an alternate # assertion/expectation library such as wrong or the stdlib/minitest @@ -62,55 +64,53 @@ RSpec.configure do |config| # The settings below are suggested to provide a good initial experience # with RSpec, but feel free to customize to your heart's content. -=begin - # This allows you to limit a spec run to individual examples or groups - # you care about by tagging them with `:focus` metadata. When nothing - # is tagged with `:focus`, all examples get run. RSpec also provides - # aliases for `it`, `describe`, and `context` that include `:focus` - # metadata: `fit`, `fdescribe` and `fcontext`, respectively. - config.filter_run_when_matching :focus - - # Allows RSpec to persist some state between runs in order to support - # the `--only-failures` and `--next-failure` CLI options. We recommend - # you configure your source control system to ignore this file. - config.example_status_persistence_file_path = "spec/examples.txt" - - # Limits the available syntax to the non-monkey patched syntax that is - # recommended. For more details, see: - # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ - # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ - # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode - config.disable_monkey_patching! - - # This setting enables warnings. It's recommended, but in some cases may - # be too noisy due to issues in dependencies. - config.warnings = true - - # Many RSpec users commonly either run the entire suite or an individual - # file, and it's useful to allow more verbose output when running an - # individual spec file. - if config.files_to_run.one? - # Use the documentation formatter for detailed output, - # unless a formatter has already been configured - # (e.g. via a command-line flag). - config.default_formatter = "doc" - end - - # Print the 10 slowest examples and example groups at the - # end of the spec run, to help surface which specs are running - # particularly slow. - config.profile_examples = 10 - - # Run specs in random order to surface order dependencies. If you find an - # order dependency and want to debug it, you can fix the order by providing - # the seed, which is printed after each run. - # --seed 1234 - config.order = :random - - # Seed global randomization in this process using the `--seed` CLI option. - # Setting this allows you to use `--seed` to deterministically reproduce - # test failures related to randomization by passing the same `--seed` value - # as the one that triggered the failure. - Kernel.srand config.seed -=end + # # This allows you to limit a spec run to individual examples or groups + # # you care about by tagging them with `:focus` metadata. When nothing + # # is tagged with `:focus`, all examples get run. RSpec also provides + # # aliases for `it`, `describe`, and `context` that include `:focus` + # # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + # config.filter_run_when_matching :focus + # + # # Allows RSpec to persist some state between runs in order to support + # # the `--only-failures` and `--next-failure` CLI options. We recommend + # # you configure your source control system to ignore this file. + # config.example_status_persistence_file_path = "spec/examples.txt" + # + # # Limits the available syntax to the non-monkey patched syntax that is + # # recommended. For more details, see: + # # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ + # # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode + # config.disable_monkey_patching! + # + # # This setting enables warnings. It's recommended, but in some cases may + # # be too noisy due to issues in dependencies. + # config.warnings = true + # + # # Many RSpec users commonly either run the entire suite or an individual + # # file, and it's useful to allow more verbose output when running an + # # individual spec file. + # if config.files_to_run.one? + # # Use the documentation formatter for detailed output, + # # unless a formatter has already been configured + # # (e.g. via a command-line flag). + # config.default_formatter = "doc" + # end + # + # # Print the 10 slowest examples and example groups at the + # # end of the spec run, to help surface which specs are running + # # particularly slow. + # config.profile_examples = 10 + # + # # Run specs in random order to surface order dependencies. If you find an + # # order dependency and want to debug it, you can fix the order by providing + # # the seed, which is printed after each run. + # # --seed 1234 + # config.order = :random + # + # # Seed global randomization in this process using the `--seed` CLI option. + # # Setting this allows you to use `--seed` to deterministically reproduce + # # test failures related to randomization by passing the same `--seed` value + # # as the one that triggered the failure. + # Kernel.srand config.seed end diff --git a/spec/stage_manager_spec.rb b/spec/stage_manager_spec.rb index b8fc70c..16f9080 100644 --- a/spec/stage_manager_spec.rb +++ b/spec/stage_manager_spec.rb @@ -1,10 +1,12 @@ -require_relative '../lib/felflame.rb' +# frozen_string_literal: true -#class EntitiesTest < Minitest::Test +require_relative '../lib/felflame' + +# class EntitiesTest < Minitest::Test describe 'Stage' do before :all do - @component_manager ||= FelFlame::Components.new('TestStage', order: Array.new) + @component_manager ||= FelFlame::Components.new('TestStage', order: []) @system2 = FelFlame::Systems.new('StageTest', priority: 1) do @component_manager.first.order.push 2 end @@ -58,7 +60,6 @@ describe 'Stage' do @scene2.add @system2 @scene3.add @system3 FelFlame::Stage.call - expect(@component_manager.first.order).to eq([1,2,3]) + expect(@component_manager.first.order).to eq([1, 2, 3]) end - end diff --git a/spec/system_manager_spec.rb b/spec/system_manager_spec.rb index f15ebaa..b7177af 100644 --- a/spec/system_manager_spec.rb +++ b/spec/system_manager_spec.rb @@ -1,7 +1,8 @@ -require_relative '../lib/felflame.rb' +# frozen_string_literal: true -describe 'Systems' do +require_relative '../lib/felflame' +describe 'Systems' do before :all do @component_manager ||= FelFlame::Components.new('TestSystems', health: 10, whatever: 'imp', mana: 10) @@testitr = 999 @@ -41,7 +42,7 @@ describe 'Systems' do expect(FelFlame::Systems.respond_to?(:[])).to be true expect(FelFlame::Systems.respond_to?(:each)).to be true FelFlame::Systems.each do |system| - expect(system.respond_to? :call).to be true + expect(system.respond_to?(:call)).to be true end expect(FelFlame::Systems.respond_to?(:filter)).to be true expect(FelFlame::Systems.respond_to?(:first)).to be true @@ -231,11 +232,11 @@ describe 'Systems' do @entity1 = FelFlame::Entities.new @system.trigger_when_is_changed @cmp0, :whatever @system.trigger_when_is_changed @cmp0, :mana - #expect(@system.attr_triggers).to eq({@cmp0 => [:name, :mana]}) - #expect(@cmp0.attr_triggers).to eq({:name => [@system], :mana => [@system]}) + # expect(@system.attr_triggers).to eq({@cmp0 => [:name, :mana]}) + # expect(@cmp0.attr_triggers).to eq({:name => [@system], :mana => [@system]}) @system.clear_triggers :attr_triggers, :whatever, component_or_manager: @cmp0 - #expect(@system.attr_triggers).to eq({@cmp0 => [:mana]}) - #expect(@cmp0.attr_triggers).to eq({:name => [], :mana => [@system]}) + # expect(@system.attr_triggers).to eq({@cmp0 => [:mana]}) + # expect(@cmp0.attr_triggers).to eq({:name => [], :mana => [@system]}) expect(@cmp0.health).to eq(10) expect(@cmp1.health).to eq(20) @cmp0.whatever = 'something' -- cgit v1.2.3