diff options
34 files changed, 150 insertions, 574 deletions
diff --git a/.codeclimate.yml b/.codeclimate.yml index 2089409..0237889 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -1,3 +1,5 @@ exclude_patterns: -- "mrbgem/" + - "mrbgem/" - "spec/" +- "bin/" +- "docs/" diff --git a/deprecated/components/00_renderable.rb b/deprecated/components/00_renderable.rb deleted file mode 100644 index 32c93b6..0000000 --- a/deprecated/components/00_renderable.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -FelFlame::Components.new('Renderable', z: 0) -# class Components -# # If an entity can be rendered on screen -# class Renderable < Helper::BaseComponent -# attr_accessor :z -# -# def initialize -# @z = 0 -# end -# -# def set(**opts) -# opts.each do |key, value| -# self.send "#{key}=", value -# end -# end -# end -# end diff --git a/deprecated/components/01_sprite.rb b/deprecated/components/01_sprite.rb deleted file mode 100644 index 4ae6713..0000000 --- a/deprecated/components/01_sprite.rb +++ /dev/null @@ -1,56 +0,0 @@ -# frozen_string_literal: true - -FelFlame::Components.new('Sprite', :x, :y, :w, :h, :path, :angle, :a, :r, :g, :b, - :source_x, :source_y, :source_w, :source_h, - :tile_x, :tile_y, :tile_w, :tile_h, - :flip_horizontally, :flip_vertically, - :angle_anchor_x, :angle_anchor_y, primative_marker: :sprite) - -# Components::Sprite.define_method('primative_marker') do -# :sprite -# end - -# class Components -# # If an entity can be rendered on screen -# class Sprite < Helper::BaseComponent -# -# attr_accessor :x, :y, :w, :h, :path, :angle, :a, :r, :g, :b, -# :source_x, :source_y, :source_w, :source_h, -# :tile_x, :tile_y, :tile_w, :tile_h, -# :flip_horizontally, :flip_vertically, -# :angle_anchor_x, :angle_anchor_y -# -# def set(x: @x, y: @y, w: @w, h: @h, path: @path, angle: @angle, a: @a, r: @r, g: @g, b: @b, -# source_x: @source_x, source_y: @source_y, source_w: @source_w, source_h: @source_h, -# tile_x: @tile_x, tile_y: @tile_y, tile_w: @tile_w, tile_h: @tile_h, -# flip_horizontally: @flip_horizontally, flip_vertically: @flip_vertically, -# angle_anchor_x: @angle_anchor_x, angle_anchor_y: @angle_anchor_y) -# {x: @x = x, -# y: @y = y, -# w: @w = w, -# h: @h = h, -# path: @path = path, -# angle: @angle = angle, -# a: @a = a, -# r: @r = r, -# g: @g = g, -# b: @b = b, -# source_x: @source_x = source_x, -# source_y: @source_y = source_y, -# source_w: @source_w = source_w, -# source_h: @source_h = source_h, -# tile_x: @tile_x = tile_x, -# tile_y: @tile_y = tile_y, -# tile_w: @tile_w = tile_w, -# tile_h: @tile_h = tile_h, -# flip_horizontally: @flip_horizontally = flip_horizontally, -# flip_vertically: @flip_vertically = flip_vertically, -# angle_anchor_x: @angle_anchor_x = angle_anchor_x, -# angle_anchor_y: @angle_anchor_y = angle_anchor_y} -# end -# -# def primative_marker -# :sprite -# end -# end -# end diff --git a/deprecated/components/02_label.rb b/deprecated/components/02_label.rb deleted file mode 100644 index f73b12c..0000000 --- a/deprecated/components/02_label.rb +++ /dev/null @@ -1,32 +0,0 @@ - -FelFlame::Components.new :Label, :x, :y, :text, :size_enum, :alignment_enum, - :a, :r, :g, :b, :font, :vertical_alignment_enum, primative_marker: :label -=begin -class Components - # A dragonruby label wrapper - class Label < Helper::BaseComponent - - attr_accessor :x, :y, :text, :size_enum, :alignment_enum, - :a, :r, :g, :b, :font, :vertical_alignment_enum - - def set(x: @x, y: @y, text: @text, size_enum: @size_enum, alignment_enum: @alignment_enum, - a: @a, r: @r, g: @g, b: @b, font: @font, vertical_alignment_enum: @vertical_alignment_enum) - {x: @x = x, - y: @y = y, - text: @text = text, - size_enum: @size_enum = size_enum, - alignment_enum: @alignment_enum = alignment_enum, - r: @r = r, - g: @g = g, - b: @b = b, - a: @a = a, - font: @font = font, - vertical_alignment_enum: @vertical_alignment_enum = vertical_alignment_enum } - end - - def primative_marker - :label - end - end -end -end diff --git a/deprecated/components/03_player_control.rb b/deprecated/components/03_player_control.rb deleted file mode 100644 index 6414547..0000000 --- a/deprecated/components/03_player_control.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -FelFlame::Components.new :PlayerControl, north: 'up', south: 'down', east: 'right', - west: 'left', interact: 'space', menu: 'enter' -# class Components -# # Gives control(keyboard or otherwise) over an object -# class PlayerControl < Helper::BaseComponent -# attr_accessor :north, :south, :east, :west, :interact, :menu -# -# def initialize -# @north = 'up' -# @south = 'down' -# @east = 'right' -# @west = 'left' -# @interact = 'space' -# @menu = 'enter' -# end -# -# def set(**opts) -# opts.each do |key, value| -# send "#{key}=", value -# end -# end -# end -# end diff --git a/deprecated/components/04_map.rb b/deprecated/components/04_map.rb deleted file mode 100644 index 5d110f0..0000000 --- a/deprecated/components/04_map.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -class Components - # dragonruby label wrapper - class Map < Helper::BaseComponent - attr_accessor :json_name, :json, :x, :y, :tilewidth, :tileheight, :a, :r, :g, :b - - def set(json_name: @json_name, x: @x, y: @y, tilewidth: @tilewidth, - tileheight: @tileheight, a: @a, r: @r, g: @g, b: @b) - { json_name: @json_name = json_name, - json: @json = Helper.get_json_tiles(json_name), - x: @x = x, - y: @y = y, - tilewidth: @tilewidth = tilewidth, - tileheight: @tileheight = tileheight, - r: @r = r, - g: @g = g, - b: @b = b, - a: @a = a } - end - end -end diff --git a/deprecated/components/05_interactable.rb b/deprecated/components/05_interactable.rb deleted file mode 100644 index bee91f6..0000000 --- a/deprecated/components/05_interactable.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -class Components - # If an entity can be rendered on screen - class Interactable < Helper::BaseComponent - attr_accessor :z - - def initialize - @z = z - end - - def set(**opts) - opts.each do |key, value| - send "#{key}=", value - end - end - end -end diff --git a/deprecated/components/06_collidable.rb b/deprecated/components/06_collidable.rb deleted file mode 100644 index 4fde638..0000000 --- a/deprecated/components/06_collidable.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -class Components - # If an entity can be rendered on screen - class Collidable < Helper::BaseComponent - class << self - end - attr_accessor :grid - - def initialize - @grid = [[]] - end - - def set(**opts) - opts.each do |key, value| - send "#{key}=", value - end - end - end -end diff --git a/deprecated/components/07_battle.rb b/deprecated/components/07_battle.rb deleted file mode 100644 index 996c03c..0000000 --- a/deprecated/components/07_battle.rb +++ /dev/null @@ -1,6 +0,0 @@ -# frozen_string_literal: true - -class Components - class Battle < Helper::Level - end -end diff --git a/deprecated/components/07_indoor.rb b/deprecated/components/07_indoor.rb deleted file mode 100644 index 762c239..0000000 --- a/deprecated/components/07_indoor.rb +++ /dev/null @@ -1,6 +0,0 @@ -# frozen_string_literal: true - -class Components - class Indoor < Helper::Level - end -end diff --git a/deprecated/components/07_overworld.rb b/deprecated/components/07_overworld.rb deleted file mode 100644 index cea11f5..0000000 --- a/deprecated/components/07_overworld.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -class Components - class Overworld < Helper::Level - attr_accessor :x, :y - - def initialize - @x = 0 - @y = 0 - end - - def set(**opts) - opts.each do |key, value| - send "#{key}=", value - end - end - end -end diff --git a/deprecated/components/debug_singleton.rb b/deprecated/components/debug_singleton.rb deleted file mode 100644 index e667191..0000000 --- a/deprecated/components/debug_singleton.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -class Components - # If an entity can be rendered on screen - class DebugSingleton - class << self - @data = false - attr_accessor :data - - def id - 0 - end - end - end -end diff --git a/deprecated/helpers/00_tileset.rb b/deprecated/helpers/00_tileset.rb deleted file mode 100644 index 9d727f9..0000000 --- a/deprecated/helpers/00_tileset.rb +++ /dev/null @@ -1,58 +0,0 @@ -# frozen_string_literal: true - -# Coverage Ignored because the functionality of this -# code will not be used for the core of FelFlame. -# It will most likely be released as a seperate package -# The code will most likely be kept here until it -# eventually will be migrated to a new git repo -# :nocov: -class Helper - # Returns a loaded map and its dependecies(images,json) - # If any are missing then it will load them from files - - @json_data = {} - class << self - attr_accessor :json_data - - def get_json_tiles(json_name, hitbox: false) - return nil if !hitbox && (json_name == 'hitbox' && !Components::DebugSingleton.data) - - if json_data[json_name].nil? - json_data[json_name] = $gtk.parse_json_file "assets/json/#{json_name}.json" - raise StandardError, "#{json_name} is null and not loaded. Cannot get json tile" if json_data[json_name].nil? - - if json_data[json_name]['type'] == 'map' # json_name.split("_").first == 'map' - json_data[json_name]['tilesets'].each do |tileset| - tileset = Helper.get_json_tiles(tileset['source'].split('/').last.delete_suffix('.tsx')) - # download tileset here - # $gtk.args.gtk.http_get 'https://mysite.net/#{tileset['name']}.png' - end - end - end - json_data[json_name] - end - - def get_tile(json_name:, tile_index:) - if json_name == 'hitbox' && !Components::DebugSingleton.data - return tile_index - 1 if tile_index > 1 - - return {} - end - - 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'] - { w: json_tiles['tilewidth'], - h: json_tiles['tileheight'], - path: json_tiles['image'].split('mygame/').last.delete('\\'), - source_x: [((tile_index % json_tiles['columns']) - 1) * json_tiles['tilewidth'], 0].max, - # source_y gets special treatment - source_y: [json_tiles['imageheight'] - ((source_height_tiles + 1) * json_tiles['tileheight']), 0].max, - source_w: json_tiles['tilewidth'], - source_h: json_tiles['tileheight'] } - end - end -end -# :nocov: diff --git a/deprecated/helpers/01_component.rb b/deprecated/helpers/01_component.rb deleted file mode 100644 index 12cce09..0000000 --- a/deprecated/helpers/01_component.rb +++ /dev/null @@ -1,67 +0,0 @@ -# frozen_string_literal: true - -class FelFlame - class Helper - # # Unused: - # class Level < FelFlame::Helper::ComponentManager - # class <<self - # def data - # @data ||= { add: [], remove: [], grid: FelFlame::Helper::Array2D.new } - # end - # - # def add(entity_id) - # super - # data[:add].push entity_id - # end - # - # def remove(entity_id) - # data[:remove].push entity_id - # super - # end - # end - # end - # class Array2D < Array - # def [](val) - # unless val.nil? - # return self[val] = [] if super.nil? - # end - # super - # end - # end - # class ArrayOfHashes < Array - # def [](val) - # unless val.nil? - # return self[val] = {} if super.nil? - # end - # super - # end - # end - - # module ComponentHelper - # class <<self - # def up? char - # char == char.upcase - # end - # - # def down? char - # char == char.downcase - # end - # - # def underscore(input) - # output = input[0].downcase - # (1...(input.length - 1)).each do |iter| - # if down?(input[iter]) && up?(input[iter + 1]) - # output += "#{input[iter].downcase}_" - # elsif up?(input[iter - 1]) && up?(input[iter]) && down?(input[iter + 1]) - # output += "_#{input[iter].downcase}" - # else - # output += input[iter].downcase - # end - # end - # output += input[-1].downcase unless input.length == 1 - # output - # end - # end - # end - end -end diff --git a/deprecated/systems/00_update_levels.rb b/deprecated/systems/00_update_levels.rb deleted file mode 100644 index 5805123..0000000 --- a/deprecated/systems/00_update_levels.rb +++ /dev/null @@ -1,36 +0,0 @@ -# frozen_string_literal: true - -class Systems - class UpdateLevels - @co = Components::Overworld - def self.run - @co.data[:add].each do |id| - @co.data[:add].delete(id) - if !(Components::Sprite.id & Entity.signatures[id]).zero? - @co.data[:grid][@co.data[id].x][@co.data[id].y] = {} if @co.data[:grid][@co.data[id].x][@co.data[id].y].nil? - # @co.data[:grid][@co.data[id].x][@co.data[id].y].merge!({ player: true }) - puts @co.data[:grid][@co.data[id].x][@co.data[id].y].inspect - elsif !(Components::Map.id & Entity.signatures[id]).zero? - if Components::Map.data[id].json['tilesets'].last['source'].split('/').last.delete('\\').delete_suffix('.tsx') == 'hitbox' - Components::Map.data[id].json['layers'].each do |layer| - layer['chunks'].each do |chunk| - chunk['data'].each_slice(chunk['width']).with_index do |row, row_index| - row.each_with_index do |tile, column_index| - if tile.to_i == Components::Map.data[id].json['tilesets'].last['firstgid'].to_i - @co.data[:grid][column_index][row_index] = {} if @co.data[:grid][column_index][row_index].nil? - @co.data[:grid][column_index][row_index].merge!({ hitbox: true }) - end - end - end - end - end - end - end - puts @co.data[:grid] - end - Components::Overworld.data[:remove].each do |id| - Components::Overworld.data[:remove].delete(id) - end - end - end -end diff --git a/deprecated/systems/10_player.rb b/deprecated/systems/10_player.rb deleted file mode 100644 index ae8564d..0000000 --- a/deprecated/systems/10_player.rb +++ /dev/null @@ -1,43 +0,0 @@ -# frozen_string_literal: true - -class Systems - class Player - @co = Components::Overworld - def self.run - Components::PlayerControl.data.each do |id, data| - puts6 "Right: #{@co.data[:grid][@co.data[id].x + 1][@co.data[id].y]}" - puts6 "Left #{@co.data[:grid][@co.data[id].x - 1][@co.data[id].y]}" - puts6 "Down #{@co.data[:grid][@co.data[id].x][@co.data[id].y + 1]}" - puts6 "Up #{@co.data[:grid][@co.data[id].x][@co.data[id].y - 1]}" - # puts6 @co.data[:grid][@co.data[id].x + 1][@co.data[id].y][:hitbox].nil? - - unless (Components::Sprite.id & Entity.signatures[id]).zero? - if $gtk.args.inputs.keyboard.key_down.send(data.north) && \ - (@co.data[:grid][@co.data[id].x][@co.data[id].y - 1].nil? || \ - @co.data[:grid][@co.data[id].x][@co.data[id].y - 1][:hitbox].nil?) - Components::Sprite.data[id].y -= 64 - @co.data[id].y -= 1 - elsif $gtk.args.inputs.keyboard.key_down.send(data.south) && \ - (@co.data[:grid][@co.data[id].x][@co.data[id].y + 1].nil? || \ - @co.data[:grid][@co.data[id].x][@co.data[id].y + 1][:hitbox].nil?) - Components::Sprite.data[id].y += 64 - @co.data[id].y += 1 - elsif $gtk.args.inputs.keyboard.key_down.send(data.east) && \ - (@co.data[:grid][@co.data[id].x + 1][@co.data[id].y].nil? || \ - @co.data[:grid][@co.data[id].x + 1][@co.data[id].y][:hitbox].nil?) - Components::Sprite.data[id].x += 64 - @co.data[id].x += 1 - elsif $gtk.args.inputs.keyboard.key_down.send(data.west) && \ - (@co.data[:grid][@co.data[id].x - 1][@co.data[id].y].nil? || @co.data[:grid][@co.data[id].x - 1][@co.data[id].y][:hitbox].nil?) - Components::Sprite.data[id].x -= 64 - @co.data[id].x -= 1 - end - # Components::Sprite.data[id].y -= 64 if $gtk.args.inputs.keyboard.key_down.send(data.north) - # Components::Sprite.data[id].y += 64 if $gtk.args.inputs.keyboard.key_down.send(data.south) - # Components::Sprite.data[id].x += 64 if $gtk.args.inputs.keyboard.key_down.send(data.east) - # Components::Sprite.data[id].x -= 64 if $gtk.args.inputs.keyboard.key_down.send(data.west) - end - end - end - end -end diff --git a/deprecated/systems/99_render.rb b/deprecated/systems/99_render.rb deleted file mode 100644 index dc1092e..0000000 --- a/deprecated/systems/99_render.rb +++ /dev/null @@ -1,47 +0,0 @@ -# frozen_string_literal: true - -class Systems - class Render - def self.run - Components::Renderable.data.sort_by { |v| v[1].z }.each do |key, _data| - if !(Components::Sprite.id & Entity.signatures[key]).zero? - $gtk.args.outputs.sprites << Components::Sprite.data[key].set - elsif !(Components::Label.id & Entity.signatures[key]).zero? - $gtk.args.outputs.labels << Components::Label.data[key].set - elsif !(Components::Map.id & Entity.signatures[key]).zero? - Components::Map.data[key].json['layers'].each do |layer| - layer['chunks'].each do |chunk| - chunk['data'].each_slice(chunk['width']).with_index do |row, row_index| - row.each_with_index do |tile, column_index| - 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 - end - end - end - end - end -end diff --git a/docs/FelECS.html b/docs/FelECS.html index 62efd37..de85749 100644 --- a/docs/FelECS.html +++ b/docs/FelECS.html @@ -227,7 +227,7 @@ </div> </dt> - <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>5.0.0</span><span class='tstring_end'>'</span></span></pre></dd> + <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>5.0.1</span><span class='tstring_end'>'</span></span></pre></dd> </dl> @@ -325,7 +325,7 @@ </div> <div id="footer"> - Generated on Thu Feb 3 03:45:34 2022 by + Generated on Thu Feb 17 07:54:07 2022 by <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> 0.9.26 (ruby-2.7.3). </div> diff --git a/docs/FelECS/ComponentManager.html b/docs/FelECS/ComponentManager.html index fb78748..4519111 100644 --- a/docs/FelECS/ComponentManager.html +++ b/docs/FelECS/ComponentManager.html @@ -1229,7 +1229,7 @@ </div> <div id="footer"> - Generated on Thu Feb 3 03:45:35 2022 by + Generated on Thu Feb 17 07:54:07 2022 by <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> 0.9.26 (ruby-2.7.3). </div> diff --git a/docs/FelECS/Components.html b/docs/FelECS/Components.html index e58decc..368a994 100644 --- a/docs/FelECS/Components.html +++ b/docs/FelECS/Components.html @@ -327,7 +327,7 @@ </div> <div id="footer"> - Generated on Thu Feb 3 03:45:34 2022 by + Generated on Thu Feb 17 07:54:07 2022 by <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> 0.9.26 (ruby-2.7.3). </div> diff --git a/docs/FelECS/Entities.html b/docs/FelECS/Entities.html index 6a5045c..e937df1 100644 --- a/docs/FelECS/Entities.html +++ b/docs/FelECS/Entities.html @@ -450,13 +450,16 @@ 131 132 133 -134</pre> +134 +135 +136</pre> </td> <td> <pre class="code"><span class="info file"># File 'lib/felecs/entity_manager.rb', line 107</span> <span class='kw'>def</span> <span class='id identifier rubyid_group'>group</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_component_managers'>component_managers</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span> <span class='kw'>return</span> <span class='kw'>nil</span> <span class='kw'>if</span> <span class='id identifier rubyid_component_managers'>component_managers</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span> + <span class='kw'>if</span> <span class='id identifier rubyid_component_managers'>component_managers</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'>==</span> <span class='int'>1</span> <span class='id identifier rubyid_component_managers'>component_managers</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_cmp'>cmp</span><span class='op'>|</span> <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span><span class='lparen'>(</span><span class='id identifier rubyid_cmp'>cmp</span><span class='comma'>,</span> <span class='id identifier rubyid_cmp'>cmp</span><span class='period'>.</span><span class='id identifier rubyid_entity'>entity</span><span class='rparen'>)</span> @@ -467,6 +470,7 @@ <span class='id identifier rubyid_keep'>keep</span> <span class='op'>=</span> <span class='kw'>true</span> <span class='id identifier rubyid_component_managers'>component_managers</span><span class='period'>.</span><span class='id identifier rubyid_drop'>drop</span><span class='lparen'>(</span><span class='int'>1</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_mgr'>mgr</span><span class='op'>|</span> <span class='kw'>next</span> <span class='kw'>unless</span> <span class='id identifier rubyid_ent'>ent</span><span class='period'>.</span><span class='id identifier rubyid_components'>components</span><span class='lbracket'>[</span><span class='id identifier rubyid_mgr'>mgr</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span> + <span class='id identifier rubyid_keep'>keep</span> <span class='op'>=</span> <span class='kw'>false</span> <span class='kw'>break</span> <span class='kw'>end</span> @@ -925,7 +929,7 @@ </div> <div id="footer"> - Generated on Thu Feb 3 03:45:34 2022 by + Generated on Thu Feb 17 07:54:07 2022 by <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> 0.9.26 (ruby-2.7.3). </div> diff --git a/docs/FelECS/Order.html b/docs/FelECS/Order.html index 6dd5c97..aa0db42 100644 --- a/docs/FelECS/Order.html +++ b/docs/FelECS/Order.html @@ -241,7 +241,7 @@ </div> <div id="footer"> - Generated on Thu Feb 3 03:45:34 2022 by + Generated on Thu Feb 17 07:54:07 2022 by <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> 0.9.26 (ruby-2.7.3). </div> diff --git a/docs/FelECS/Scenes.html b/docs/FelECS/Scenes.html index d11b129..9e66030 100644 --- a/docs/FelECS/Scenes.html +++ b/docs/FelECS/Scenes.html @@ -755,7 +755,7 @@ </div> <div id="footer"> - Generated on Thu Feb 3 03:45:35 2022 by + Generated on Thu Feb 17 07:54:07 2022 by <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> 0.9.26 (ruby-2.7.3). </div> diff --git a/docs/FelECS/Stage.html b/docs/FelECS/Stage.html index 02b1f70..0ae8a35 100644 --- a/docs/FelECS/Stage.html +++ b/docs/FelECS/Stage.html @@ -562,7 +562,7 @@ </div> <div id="footer"> - Generated on Thu Feb 3 03:45:34 2022 by + Generated on Thu Feb 17 07:54:07 2022 by <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> 0.9.26 (ruby-2.7.3). </div> diff --git a/docs/FelECS/Systems.html b/docs/FelECS/Systems.html index f4ef7ac..18e1442 100644 --- a/docs/FelECS/Systems.html +++ b/docs/FelECS/Systems.html @@ -1118,28 +1118,28 @@ <span class='kw'>if</span> <span class='id identifier rubyid_trigger_types'>trigger_types</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span> <span class='symbol'>:attr_triggers</span> <span class='kw'>if</span> <span class='lparen'>(</span><span class='id identifier rubyid_trigger_types'>trigger_types</span> <span class='op'>-</span> <span class='qsymbols_beg'>%i[</span><span class='tstring_content'>addition_triggers</span><span class='words_sep'> - </span><span class='tstring_content'>removal_triggers</span><span class='words_sep'> - </span><span class='tstring_content'>attr_triggers</span><span class='tstring_end'>]</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span> - - <span class='kw'>if</span> <span class='id identifier rubyid_component_or_manager'>component_or_manager</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span> - <span class='comment'># remove all attrs -</span> <span class='id identifier rubyid_attr_triggers'>attr_triggers</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_cmp_or_mgr'>cmp_or_mgr</span><span class='comma'>,</span> <span class='id identifier rubyid_attrs'>attrs</span><span class='op'>|</span> - <span class='id identifier rubyid_attrs'>attrs</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_attr'>attr</span><span class='op'>|</span> - <span class='kw'>next</span> <span class='kw'>if</span> <span class='id identifier rubyid_cmp_or_mgr'>cmp_or_mgr</span><span class='period'>.</span><span class='id identifier rubyid_attr_triggers'>attr_triggers</span><span class='lbracket'>[</span><span class='id identifier rubyid_attr'>attr</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span> - - <span class='id identifier rubyid_cmp_or_mgr'>cmp_or_mgr</span><span class='period'>.</span><span class='id identifier rubyid_attr_triggers'>attr_triggers</span><span class='lbracket'>[</span><span class='id identifier rubyid_attr'>attr</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span> <span class='kw'>self</span> - <span class='kw'>end</span> - <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_attr_triggers'>attr_triggers</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span> + </span><span class='tstring_content'>removal_triggers</span><span class='words_sep'> + </span><span class='tstring_content'>attr_triggers</span><span class='tstring_end'>]</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span> + + <span class='kw'>if</span> <span class='id identifier rubyid_component_or_manager'>component_or_manager</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span> + <span class='comment'># remove all attrs +</span> <span class='id identifier rubyid_attr_triggers'>attr_triggers</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_cmp_or_mgr'>cmp_or_mgr</span><span class='comma'>,</span> <span class='id identifier rubyid_attrs'>attrs</span><span class='op'>|</span> + <span class='id identifier rubyid_attrs'>attrs</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_attr'>attr</span><span class='op'>|</span> + <span class='kw'>next</span> <span class='kw'>if</span> <span class='id identifier rubyid_cmp_or_mgr'>cmp_or_mgr</span><span class='period'>.</span><span class='id identifier rubyid_attr_triggers'>attr_triggers</span><span class='lbracket'>[</span><span class='id identifier rubyid_attr'>attr</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span> + + <span class='id identifier rubyid_cmp_or_mgr'>cmp_or_mgr</span><span class='period'>.</span><span class='id identifier rubyid_attr_triggers'>attr_triggers</span><span class='lbracket'>[</span><span class='id identifier rubyid_attr'>attr</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span> <span class='kw'>self</span> <span class='kw'>end</span> - <span class='kw'>else</span> - <span class='comment'># remove attrs relevant to comp_or_man -</span> <span class='kw'>unless</span> <span class='id identifier rubyid_attr_triggers'>attr_triggers</span><span class='lbracket'>[</span><span class='id identifier rubyid_component_or_manager'>component_or_manager</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span> - <span class='id identifier rubyid_attr_triggers'>attr_triggers</span><span class='lbracket'>[</span><span class='id identifier rubyid_component_or_manager'>component_or_manager</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_attr'>attr</span><span class='op'>|</span> - <span class='id identifier rubyid_component_or_manager'>component_or_manager</span><span class='period'>.</span><span class='id identifier rubyid_attr_triggers'>attr_triggers</span><span class='lbracket'>[</span><span class='id identifier rubyid_attr'>attr</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span> <span class='kw'>self</span> - <span class='kw'>end</span> - <span class='id identifier rubyid_attr_triggers'>attr_triggers</span><span class='lbracket'>[</span><span class='id identifier rubyid_component_or_manager'>component_or_manager</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span> + <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_attr_triggers'>attr_triggers</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span> + <span class='kw'>end</span> + <span class='kw'>else</span> + <span class='comment'># remove attrs relevant to comp_or_man +</span> <span class='kw'>unless</span> <span class='id identifier rubyid_attr_triggers'>attr_triggers</span><span class='lbracket'>[</span><span class='id identifier rubyid_component_or_manager'>component_or_manager</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span> + <span class='id identifier rubyid_attr_triggers'>attr_triggers</span><span class='lbracket'>[</span><span class='id identifier rubyid_component_or_manager'>component_or_manager</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_attr'>attr</span><span class='op'>|</span> + <span class='id identifier rubyid_component_or_manager'>component_or_manager</span><span class='period'>.</span><span class='id identifier rubyid_attr_triggers'>attr_triggers</span><span class='lbracket'>[</span><span class='id identifier rubyid_attr'>attr</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span> <span class='kw'>self</span> <span class='kw'>end</span> + <span class='id identifier rubyid_attr_triggers'>attr_triggers</span><span class='lbracket'>[</span><span class='id identifier rubyid_component_or_manager'>component_or_manager</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span> <span class='kw'>end</span> + <span class='kw'>end</span> <span class='kw'>elsif</span> <span class='id identifier rubyid_component_or_manager'>component_or_manager</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span> @@ -1150,8 +1150,8 @@ <span class='kw'>end</span> <span class='kw'>end</span> <span class='id identifier rubyid_attr_triggers'>attr_triggers</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='id identifier rubyid_trigger_types'>trigger_types</span> <span class='op'>-</span> <span class='qsymbols_beg'>%i[</span><span class='tstring_content'>addition_triggers</span><span class='words_sep'> - </span><span class='tstring_content'>removal_triggers</span><span class='words_sep'> - </span><span class='tstring_content'>attr_triggers</span><span class='tstring_end'>]</span></span><span class='rparen'>)</span> + </span><span class='tstring_content'>removal_triggers</span><span class='words_sep'> + </span><span class='tstring_content'>attr_triggers</span><span class='tstring_end'>]</span></span><span class='rparen'>)</span> <span class='kw'>else</span> <span class='comment'># remove attr from component_or_manager </span> <span class='lparen'>(</span><span class='id identifier rubyid_trigger_types'>trigger_types</span> <span class='op'>-</span> <span class='qsymbols_beg'>%i[</span><span class='tstring_content'>addition_triggers</span><span class='words_sep'> </span><span class='tstring_content'>removal_triggers</span><span class='words_sep'> </span><span class='tstring_content'>attr_triggers</span><span class='tstring_end'>]</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_attr'>attr</span><span class='op'>|</span> @@ -1495,7 +1495,7 @@ </div> <div id="footer"> - Generated on Thu Feb 3 03:45:35 2022 by + Generated on Thu Feb 17 07:54:07 2022 by <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> 0.9.26 (ruby-2.7.3). </div> diff --git a/docs/_index.html b/docs/_index.html index 8e128ed..8b6dad0 100644 --- a/docs/_index.html +++ b/docs/_index.html @@ -178,7 +178,7 @@ </div> <div id="footer"> - Generated on Thu Feb 3 03:45:34 2022 by + Generated on Thu Feb 17 07:54:07 2022 by <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> 0.9.26 (ruby-2.7.3). </div> diff --git a/docs/file.README.html b/docs/file.README.html index 6da1a7c..4218261 100644 --- a/docs/file.README.html +++ b/docs/file.README.html @@ -63,11 +63,11 @@ <p><a href="https://codeclimate.com/github/realtradam/FelFlame/maintainability"><img src="https://api.codeclimate.com/v1/badges/56d425d9078e98efb74b/maintainability" alt="Maintainability"></a> <a href="https://codeclimate.com/github/realtradam/FelFlame/test_coverage"><img src="https://api.codeclimate.com/v1/badges/56d425d9078e98efb74b/test_coverage" alt="Test Coverage"></a> -<a href="http://inch-ci.org/github/realtradam/FelECS"><img src="http://inch-ci.org/github/realtradam/FelECS.svg?branch=master" alt="Inline docs"></a> <a href="https://github.com/realtradam/FelFlame/blob/master/LICENSE"><img src="https://img.shields.io/github/license/realtradam/FelECS" alt="MIT License"></a> -<a href="https://ko-fi.com/tradam"><img src="https://img.shields.io/static/v1?message=Buy%20me%20a%20coffee&logo=kofi&labelColor=ff5e5b&color=434B57&logoColor=white&label=%20" alt="Ko-Fi"></a></p> +<a href="https://ko-fi.com/tradam"><img src="https://img.shields.io/static/v1?message=Buy%20me%20a%20coffee&logo=kofi&labelColor=ff5e5b&color=434B57&logoColor=white&label=%20" alt="Ko-Fi"></a> +<!--<a href="http://inch-ci.org/github/realtradam/FelECS"><img src="http://inch-ci.org/github/realtradam/FelECS.svg?branch=master" alt="Inline docs"></a>--> <!-- this is busted --></p> -<p><strong><a href="https://felflame.tradam.fyi/">Check out the comprehensive documentation here!</a></strong></p> +<p><strong><a href="https://felecs.tradam.dev">Check out the comprehensive documentation here!</a></strong></p> <hr> @@ -92,6 +92,7 @@ <li><a href="#accessing">Accessing</a></li> <li><a href="#adding-and-removing-components">Adding and Removing Components</a></li> <li><a href="#accessing-entities-attached-components">Accessing Entities' Attached Components</a></li> +<li><a href="#iterating-over-grouped-entities">Iterating Over Grouped Entities</a></li> <li><a href="#deletion">Deletion</a></li> </ul></li> <li><a href="#components-1">Components</a> @@ -246,6 +247,32 @@ If you need to you can access Entities using the <code>Entities</code> module:</ <pre class="code ruby"><code class="ruby"><span class='ivar'>@entity</span><span class='period'>.</span><span class='id identifier rubyid_components'>components</span><span class='lbracket'>[</span><span class='ivar'>@component_manager</span><span class='rbracket'>]</span> <span class='comment'># => [@component1, @component2, @component3] </span></code></pre> +<h3 id="iterating-over-grouped-entities">Iterating Over Grouped Entities</h3> + +<p>You can execute a block for each entity that has all matching component types attached to it like so:</p> + +<pre class="code ruby"><code class="ruby">FelECS::Entities.group(@component_manager_one, @component_manager_two).do |cmp1, cmp2, ent| + # do stuff with the components and entity +end + +# or + +FelECS::Entities.group(@mgr1, @mgr2, @mgr3, @mgr4).do |cmp1, cmp2, cmp3, cmp4, ent| + # do stuff with the components and entity +end + +# or + +FelECS::Entities.group(@component_manager_one).do |cmp1, ent| + # do stuff with the component and entity +end + +# etc +</code></pre> + +<p>You can use any number of component managers and it will only iterate over all entities that have at least all these components from these managers attached to them. The arguments in the block(the arguments surrounded by |pipes|) always correspond to each component manager passed as parameters into the group method and then followed by the entity object.<br> +This means there will be a number of these arguments equal to the number of component managers passed into the group method plus one for the entity.</p> + <h3 id="deletion">Deletion</h3> <p>To have all Components from an Entity <strong>removed</strong> and the Entity deleted we do the following:</p> @@ -550,7 +577,7 @@ E.g priority 1 will go first, priority 2 will go second, etcetera. </p> </div></div> <div id="footer"> - Generated on Thu Feb 3 03:45:34 2022 by + Generated on Thu Feb 17 07:54:07 2022 by <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> 0.9.26 (ruby-2.7.3). </div> diff --git a/docs/index.html b/docs/index.html index 2aeb172..f53468d 100644 --- a/docs/index.html +++ b/docs/index.html @@ -63,11 +63,11 @@ <p><a href="https://codeclimate.com/github/realtradam/FelFlame/maintainability"><img src="https://api.codeclimate.com/v1/badges/56d425d9078e98efb74b/maintainability" alt="Maintainability"></a> <a href="https://codeclimate.com/github/realtradam/FelFlame/test_coverage"><img src="https://api.codeclimate.com/v1/badges/56d425d9078e98efb74b/test_coverage" alt="Test Coverage"></a> -<a href="http://inch-ci.org/github/realtradam/FelECS"><img src="http://inch-ci.org/github/realtradam/FelECS.svg?branch=master" alt="Inline docs"></a> <a href="https://github.com/realtradam/FelFlame/blob/master/LICENSE"><img src="https://img.shields.io/github/license/realtradam/FelECS" alt="MIT License"></a> -<a href="https://ko-fi.com/tradam"><img src="https://img.shields.io/static/v1?message=Buy%20me%20a%20coffee&logo=kofi&labelColor=ff5e5b&color=434B57&logoColor=white&label=%20" alt="Ko-Fi"></a></p> +<a href="https://ko-fi.com/tradam"><img src="https://img.shields.io/static/v1?message=Buy%20me%20a%20coffee&logo=kofi&labelColor=ff5e5b&color=434B57&logoColor=white&label=%20" alt="Ko-Fi"></a> +<!--<a href="http://inch-ci.org/github/realtradam/FelECS"><img src="http://inch-ci.org/github/realtradam/FelECS.svg?branch=master" alt="Inline docs"></a>--> <!-- this is busted --></p> -<p><strong><a href="https://felflame.tradam.fyi/">Check out the comprehensive documentation here!</a></strong></p> +<p><strong><a href="https://felecs.tradam.dev">Check out the comprehensive documentation here!</a></strong></p> <hr> @@ -92,6 +92,7 @@ <li><a href="#accessing">Accessing</a></li> <li><a href="#adding-and-removing-components">Adding and Removing Components</a></li> <li><a href="#accessing-entities-attached-components">Accessing Entities' Attached Components</a></li> +<li><a href="#iterating-over-grouped-entities">Iterating Over Grouped Entities</a></li> <li><a href="#deletion">Deletion</a></li> </ul></li> <li><a href="#components-1">Components</a> @@ -246,6 +247,32 @@ If you need to you can access Entities using the <code>Entities</code> module:</ <pre class="code ruby"><code class="ruby"><span class='ivar'>@entity</span><span class='period'>.</span><span class='id identifier rubyid_components'>components</span><span class='lbracket'>[</span><span class='ivar'>@component_manager</span><span class='rbracket'>]</span> <span class='comment'># => [@component1, @component2, @component3] </span></code></pre> +<h3 id="iterating-over-grouped-entities">Iterating Over Grouped Entities</h3> + +<p>You can execute a block for each entity that has all matching component types attached to it like so:</p> + +<pre class="code ruby"><code class="ruby">FelECS::Entities.group(@component_manager_one, @component_manager_two).do |cmp1, cmp2, ent| + # do stuff with the components and entity +end + +# or + +FelECS::Entities.group(@mgr1, @mgr2, @mgr3, @mgr4).do |cmp1, cmp2, cmp3, cmp4, ent| + # do stuff with the components and entity +end + +# or + +FelECS::Entities.group(@component_manager_one).do |cmp1, ent| + # do stuff with the component and entity +end + +# etc +</code></pre> + +<p>You can use any number of component managers and it will only iterate over all entities that have at least all these components from these managers attached to them. The arguments in the block(the arguments surrounded by |pipes|) always correspond to each component manager passed as parameters into the group method and then followed by the entity object.<br> +This means there will be a number of these arguments equal to the number of component managers passed into the group method plus one for the entity.</p> + <h3 id="deletion">Deletion</h3> <p>To have all Components from an Entity <strong>removed</strong> and the Entity deleted we do the following:</p> @@ -550,7 +577,7 @@ E.g priority 1 will go first, priority 2 will go second, etcetera. </p> </div></div> <div id="footer"> - Generated on Thu Feb 3 03:45:34 2022 by + Generated on Thu Feb 17 07:54:07 2022 by <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> 0.9.26 (ruby-2.7.3). </div> diff --git a/docs/top-level-namespace.html b/docs/top-level-namespace.html index b359611..3515d3c 100644 --- a/docs/top-level-namespace.html +++ b/docs/top-level-namespace.html @@ -127,7 +127,7 @@ </div> <div id="footer"> - Generated on Thu Feb 3 03:45:34 2022 by + Generated on Thu Feb 17 07:54:07 2022 by <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> 0.9.26 (ruby-2.7.3). </div> diff --git a/lib/felecs/entity_manager.rb b/lib/felecs/entity_manager.rb index c1f8cd8..3aab1db 100644 --- a/lib/felecs/entity_manager.rb +++ b/lib/felecs/entity_manager.rb @@ -106,6 +106,7 @@ module FelECS # @return [Nil] def group(*component_managers, &block) return nil if component_managers.empty? + if component_managers.length == 1 component_managers.first.each do |cmp| block.call(cmp, cmp.entity) @@ -116,6 +117,7 @@ module FelECS keep = true component_managers.drop(1).each do |mgr| next unless ent.components[mgr].nil? + keep = false break end diff --git a/lib/felecs/system_manager.rb b/lib/felecs/system_manager.rb index 6cd260b..2d56336 100644 --- a/lib/felecs/system_manager.rb +++ b/lib/felecs/system_manager.rb @@ -159,28 +159,28 @@ module FelECS if trigger_types.include? :attr_triggers if (trigger_types - %i[addition_triggers - removal_triggers - attr_triggers]).empty? + removal_triggers + attr_triggers]).empty? - if component_or_manager.nil? - # remove all attrs - attr_triggers.each do |cmp_or_mgr, attrs| - attrs.each do |attr| - next if cmp_or_mgr.attr_triggers[attr].nil? + if component_or_manager.nil? + # remove all attrs + attr_triggers.each do |cmp_or_mgr, attrs| + attrs.each do |attr| + next if cmp_or_mgr.attr_triggers[attr].nil? - cmp_or_mgr.attr_triggers[attr].delete self - end - self.attr_triggers = {} + cmp_or_mgr.attr_triggers[attr].delete self end - else - # 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 - attr_triggers[component_or_manager] = [] + self.attr_triggers = {} + end + else + # 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 + attr_triggers[component_or_manager] = [] end + end elsif component_or_manager.nil? @@ -191,8 +191,8 @@ module FelECS end end attr_triggers.delete(trigger_types - %i[addition_triggers - removal_triggers - attr_triggers]) + removal_triggers + attr_triggers]) else # remove attr from component_or_manager (trigger_types - %i[addition_triggers removal_triggers attr_triggers]).each do |attr| diff --git a/mrbgem/mrbgem.rake b/mrbgem/mrbgem.rake index e998dd1..31e3ff4 100644 --- a/mrbgem/mrbgem.rake +++ b/mrbgem/mrbgem.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + MRuby::Gem::Specification.new('mruby-felecs') do |spec| spec.license = 'MIT' spec.author = '_Tradam' diff --git a/mrbgem/mrblib/felecs.rb b/mrbgem/mrblib/felecs.rb index 77e70cd..9fa6097 100644 --- a/mrbgem/mrblib/felecs.rb +++ b/mrbgem/mrblib/felecs.rb @@ -106,6 +106,7 @@ module FelECS # @return [Nil] def group(*component_managers, &block) return nil if component_managers.empty? + if component_managers.length == 1 component_managers.first.each do |cmp| block.call(cmp, cmp.entity) @@ -116,6 +117,7 @@ module FelECS keep = true component_managers.drop(1).each do |mgr| next unless ent.components[mgr].nil? + keep = false break end @@ -633,28 +635,28 @@ module FelECS if trigger_types.include? :attr_triggers if (trigger_types - %i[addition_triggers - removal_triggers - attr_triggers]).empty? - - if component_or_manager.nil? - # remove all attrs - attr_triggers.each do |cmp_or_mgr, attrs| - attrs.each do |attr| - next if cmp_or_mgr.attr_triggers[attr].nil? - - cmp_or_mgr.attr_triggers[attr].delete self - end - self.attr_triggers = {} + removal_triggers + attr_triggers]).empty? + + if component_or_manager.nil? + # remove all attrs + attr_triggers.each do |cmp_or_mgr, attrs| + attrs.each do |attr| + next if cmp_or_mgr.attr_triggers[attr].nil? + + cmp_or_mgr.attr_triggers[attr].delete self end - else - # 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 - attr_triggers[component_or_manager] = [] + self.attr_triggers = {} + end + else + # 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 + attr_triggers[component_or_manager] = [] end + end elsif component_or_manager.nil? @@ -665,8 +667,8 @@ module FelECS end end attr_triggers.delete(trigger_types - %i[addition_triggers - removal_triggers - attr_triggers]) + removal_triggers + attr_triggers]) else # remove attr from component_or_manager (trigger_types - %i[addition_triggers removal_triggers attr_triggers]).each do |attr| @@ -886,8 +888,6 @@ end # frozen_string_literal: true - - # The FelECS namespace where all its functionality resides under. module FelECS class << self diff --git a/spec/entity_manager_spec.rb b/spec/entity_manager_spec.rb index 234c424..3e62e28 100644 --- a/spec/entity_manager_spec.rb +++ b/spec/entity_manager_spec.rb @@ -40,7 +40,7 @@ describe 'Entities' do @ent1.add cmp_1_2, @cmp1, cmp_1_2, cmp_remove @ent2.add cmp_1_3, @component_manager2.new @ent1.remove cmp_remove - FelECS::Entities.group(@component_manager1, @component_manager2) do |cmp1, cmp2, ent| + FelECS::Entities.group(@component_manager1, @component_manager2) do |cmp1, _cmp2, _ent| cmp1.param1 += 1 end cmp_1_1.param1 @@ -54,7 +54,7 @@ describe 'Entities' do @ent1.add @cmp1 @ent2.add @cmp2 @cmp0.param1 = @cmp1.param1 = @cmp2.param1 = 1 - FelECS::Entities.group(@component_manager) do |cmp, ent| + FelECS::Entities.group(@component_manager) do |cmp, _ent| cmp.param1 += 1 end expect(@cmp0.param1).to eq(2) |
