diff options
Diffstat (limited to 'app/ECS')
| -rw-r--r-- | app/ECS/component_manager.rb | 6 | ||||
| -rw-r--r-- | app/ECS/components/00_renderable.rb | 33 | ||||
| -rw-r--r-- | app/ECS/components/00_test_component.rb | 16 | ||||
| -rw-r--r-- | app/ECS/components/01_based.rb | 16 | ||||
| -rw-r--r-- | app/ECS/components/01_sprite.rb | 49 | ||||
| -rw-r--r-- | app/ECS/components/02_label.rb | 32 | ||||
| -rw-r--r-- | app/ECS/components/03_player_control.rb | 26 | ||||
| -rw-r--r-- | app/ECS/entity_manager.rb | 8 | ||||
| -rw-r--r-- | app/ECS/signatures.rb | 23 | ||||
| -rw-r--r-- | app/ECS/system_manager.rb | 4 | ||||
| -rw-r--r-- | app/ECS/systems/00_movement.rb | 25 | ||||
| -rw-r--r-- | app/ECS/systems/00_player.rb | 17 | ||||
| -rw-r--r-- | app/ECS/systems/01_flying.rb | 19 | ||||
| -rw-r--r-- | app/ECS/systems/99_render.rb | 16 |
14 files changed, 207 insertions, 83 deletions
diff --git a/app/ECS/component_manager.rb b/app/ECS/component_manager.rb index b07cf79..7c05bd5 100644 --- a/app/ECS/component_manager.rb +++ b/app/ECS/component_manager.rb @@ -1,7 +1,7 @@ -require 'app/ECS/base_component.rb' +#require 'app/ECS/base_component.rb' -require 'app/ECS/components/00_test_component.rb' -require 'app/ECS/components/01_based.rb' +#require 'app/ECS/components/00_test_component.rb' +#require 'app/ECS/components/01_based.rb' class ECS class Components diff --git a/app/ECS/components/00_renderable.rb b/app/ECS/components/00_renderable.rb new file mode 100644 index 0000000..bf944d0 --- /dev/null +++ b/app/ECS/components/00_renderable.rb @@ -0,0 +1,33 @@ +class ECS + class Components + # If an entity can be rendered on screen + class Renderable < ECS::BaseComponent + def self.id + @id ||= ECS::ID.renderable + end + + attr_accessor :z + + def initialize(z: 0) + @z = z + end +=begin + # 1. Create a serialize method that returns a hash with all of + # the values you care about. + def serialize + { z: z } + end + + # 2. Override the inspect method and return ~serialize.to_s~. + def inspect + serialize.to_s + end + + # 3. Override to_s and return ~serialize.to_s~. + def to_s + serialize.to_s + end +=end + end + end +end diff --git a/app/ECS/components/00_test_component.rb b/app/ECS/components/00_test_component.rb deleted file mode 100644 index 0906fc8..0000000 --- a/app/ECS/components/00_test_component.rb +++ /dev/null @@ -1,16 +0,0 @@ -class ECS - class Components - class TestComponent < ECS::BaseComponent - def self.id - @id = '0001'.to_i(2) - end - - attr_accessor :x, :y - - def initialize(x: 0, y: 0) - @x = x - @y = y - end - end - end -end diff --git a/app/ECS/components/01_based.rb b/app/ECS/components/01_based.rb deleted file mode 100644 index fe564ca..0000000 --- a/app/ECS/components/01_based.rb +++ /dev/null @@ -1,16 +0,0 @@ -class ECS - class Components - class Based < ECS::BaseComponent - def self.id - @id = '0010'.to_i(2) - end - - attr_accessor :x, :y - - def initialize(x: 0, y:0) - @x = x - @y = y - end - end - end -end diff --git a/app/ECS/components/01_sprite.rb b/app/ECS/components/01_sprite.rb new file mode 100644 index 0000000..8172ce5 --- /dev/null +++ b/app/ECS/components/01_sprite.rb @@ -0,0 +1,49 @@ +class ECS + class Components + # If an entity can be rendered on screen + class Sprite < ECS::BaseComponent + def self.id + @id ||= ECS::ID.sprite + end + + 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, + @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] + end + + def primative_marker + :sprite + end + end + end +end diff --git a/app/ECS/components/02_label.rb b/app/ECS/components/02_label.rb new file mode 100644 index 0000000..c6b8b0b --- /dev/null +++ b/app/ECS/components/02_label.rb @@ -0,0 +1,32 @@ +class ECS + class Components + # If an entity can be rendered on screen + class Label < ECS::BaseComponent + def self.id + @id ||= ECS::ID.label + end + + 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, + @y = y, + @text = text, + @size_enum = size_enum, + @alignment_enum = alignment_enum, + @r = r, + @g = g, + @b = b, + @a = a, + @font = font, + @vertical_alignment_enum = vertical_alignment_enum] + end + + def primative_marker + :label + end + end + end +end diff --git a/app/ECS/components/03_player_control.rb b/app/ECS/components/03_player_control.rb new file mode 100644 index 0000000..1e4a348 --- /dev/null +++ b/app/ECS/components/03_player_control.rb @@ -0,0 +1,26 @@ +class ECS + class Components + # If an entity can be rendered on screen + class PlayerControl < ECS::BaseComponent + def self.id + @id ||= ECS::ID.player_control + end + + attr_accessor :north, :south, :east, :west + + def initialize(north: 'w', south: 's', east: 'd', west: 'a') + @north = north + @south = south + @east = east + @west = west + end + + def set(north: 'w', south: 's', east: 'd', west: 'a') + @north = north + @south = south + @east = east + @west = west + end + end + end +end diff --git a/app/ECS/entity_manager.rb b/app/ECS/entity_manager.rb index 06f73cd..ba3561f 100644 --- a/app/ECS/entity_manager.rb +++ b/app/ECS/entity_manager.rb @@ -2,10 +2,14 @@ class ECS class Entity attr_accessor :id - def initialize(signature = 0) + def initialize(*signature) + final_signature = 0 + signature.each do |sig| + final_signature += sig + end @id = ECS::Entity.generate_new_id self.class.all.push self - self.class.signatures.push signature + self.class.signatures.push final_signature ECS::Components.entity_created(@id) end diff --git a/app/ECS/signatures.rb b/app/ECS/signatures.rb new file mode 100644 index 0000000..67464ad --- /dev/null +++ b/app/ECS/signatures.rb @@ -0,0 +1,23 @@ +class ECS + class ID + class <<self + def renderable + @renderable ||= '0_001'.to_i(2) + end + + def sprite + @sprite ||= '0_010'.to_i(2) + end + + def label + @label ||= '0_100'.to_i(2) + end + + def player_control + @player_control ||= '1_000'.to_i(2) + end + end + end +end + + diff --git a/app/ECS/system_manager.rb b/app/ECS/system_manager.rb index dda8ed7..e0e41da 100644 --- a/app/ECS/system_manager.rb +++ b/app/ECS/system_manager.rb @@ -1,5 +1,5 @@ -require 'app/ECS/systems/00_movement.rb' -require 'app/ECS/systems/01_flying.rb' +#require 'app/ECS/systems/00_movement.rb' +#require 'app/ECS/systems/01_flying.rb' class ECS class Systems diff --git a/app/ECS/systems/00_movement.rb b/app/ECS/systems/00_movement.rb deleted file mode 100644 index 9d8029a..0000000 --- a/app/ECS/systems/00_movement.rb +++ /dev/null @@ -1,25 +0,0 @@ -class ECS - class Systems - class Movement - def self.run - ECS::Components::TestComponent.data.each do |key, data| - unless (ECS::Components::Based.id - ECS::Entity.signatures[key]).zero? - unless (ECS::Components::Based.id & ECS::Entity.signatures[key]).zero? - #puts "Based Data: " - #puts "eks: #{ECS::Components::Based.data[key].x += 2}" - #puts "why: #{ECS::Components::Based.data[key].y += 2}" - ECS::Components::Based.data[key].x += 2 - ECS::Components::Based.data[key].y += 2 - end - end - #puts "Movement:" - #puts "x: #{data.x += 1}" - #puts "y: #{data.y += 1}" - data.x += 1 - data.y += 1 - #puts "---" - end - end - end - end -end diff --git a/app/ECS/systems/00_player.rb b/app/ECS/systems/00_player.rb new file mode 100644 index 0000000..a78137a --- /dev/null +++ b/app/ECS/systems/00_player.rb @@ -0,0 +1,17 @@ +class ECS + class Systems + class Player + def self.run + ECS::Components::PlayerControl.data.each do |id, data| + if !(ECS::Components::Renderable.id & ECS::Entity.signatures[id]).zero? + ECS::Components::Sprite.data[id].y += 10 if $gtk.args.inputs.keyboard.key_held.send(data.north) + ECS::Components::Sprite.data[id].y -= 10 if $gtk.args.inputs.keyboard.key_held.send(data.south) + ECS::Components::Sprite.data[id].x += 10 if $gtk.args.inputs.keyboard.key_held.send(data.east) + ECS::Components::Sprite.data[id].x -= 10 if $gtk.args.inputs.keyboard.key_held.send(data.west) + #$gtk.args.outputs.labels << ECS::Components::Label.data[id].vars + end + end + end + end + end +end diff --git a/app/ECS/systems/01_flying.rb b/app/ECS/systems/01_flying.rb deleted file mode 100644 index 799398b..0000000 --- a/app/ECS/systems/01_flying.rb +++ /dev/null @@ -1,19 +0,0 @@ -class ECS - class Systems - class Based - def self.run - ECS::Components::Based.data.each do |key, data| - if ECS::Components::Based.id == ECS::Entity.signatures[key] - #puts "Entity ID: #{key}" - #puts "ONLY Based Data: " - #puts "eks: #{ECS::Components::Based.data[key].x += 3}" - #puts "why: #{ECS::Components::Based.data[key].y += 3}" - #puts "---" - data.x += 3 - data.y += 3 - end - end - end - end - end -end diff --git a/app/ECS/systems/99_render.rb b/app/ECS/systems/99_render.rb new file mode 100644 index 0000000..0751bc2 --- /dev/null +++ b/app/ECS/systems/99_render.rb @@ -0,0 +1,16 @@ +class ECS + class Systems + class Render + def self.run + ECS::Components::Renderable.data.sort_by { |v| v[1].z }.each do |key, data| + if !(ECS::Components::Sprite.id & ECS::Entity.signatures[key]).zero? + #ECS::Components::Based.data[key].x += 2 + $gtk.args.outputs.sprites << ECS::Components::Sprite.data[key].set + elsif !(ECS::Components::Label.id & ECS::Entity.signatures[key]).zero? + $gtk.args.outputs.labels << ECS::Components::Label.data[key].set + end + end + end + end + end +end |
