summaryrefslogtreecommitdiffhomepage
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/ECS/component_manager.rb6
-rw-r--r--app/ECS/components/00_renderable.rb33
-rw-r--r--app/ECS/components/00_test_component.rb16
-rw-r--r--app/ECS/components/01_based.rb16
-rw-r--r--app/ECS/components/01_sprite.rb49
-rw-r--r--app/ECS/components/02_label.rb32
-rw-r--r--app/ECS/components/03_player_control.rb26
-rw-r--r--app/ECS/entity_manager.rb8
-rw-r--r--app/ECS/signatures.rb23
-rw-r--r--app/ECS/system_manager.rb4
-rw-r--r--app/ECS/systems/00_movement.rb25
-rw-r--r--app/ECS/systems/00_player.rb17
-rw-r--r--app/ECS/systems/01_flying.rb19
-rw-r--r--app/ECS/systems/99_render.rb16
-rw-r--r--app/main.rb18
-rw-r--r--app/tick.rb32
16 files changed, 236 insertions, 104 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
diff --git a/app/main.rb b/app/main.rb
index 3255af0..99c10ae 100644
--- a/app/main.rb
+++ b/app/main.rb
@@ -1,4 +1,22 @@
+
+# TODO: when publishing require_all needs to be
+# replaces by require of each individual ruby file
+def require_all dir
+ `ls #{dir}`.each_line do |file|
+ require "app/#{dir}/#{file.strip}"
+ end
+end
+
+require 'app/ECS/signatures.rb'
+
require 'app/ECS/entity_manager.rb'
+
require 'app/ECS/component_manager.rb'
+require 'app/ECS/base_component.rb'
+require_all 'ECS/components'
+
require 'app/ECS/system_manager.rb'
+require_all 'ECS/systems'
+
require 'app/tick.rb'
+
diff --git a/app/tick.rb b/app/tick.rb
index 072bf48..f6de238 100644
--- a/app/tick.rb
+++ b/app/tick.rb
@@ -1,27 +1,17 @@
-=begin
-files = ""
-files = `ls -B1 #{__dir__}`
-
-File.write("#{__dir__}/_", (files.split - ["_"]).map{|file| "require 'lib/#{libname}/#{file}'"}.join("\n"))
-=end
-move = '0001'.to_i(2)
-base = '0010'.to_i(2)
-both = '0011'.to_i(2)
-@thing0 = ECS::Entity.new(move)
-puts @thing0
-ECS::Entity.new(base)
-ECS::Entity.new(both)
+thing0 = ECS::Entity.new(ECS::ID.sprite,
+ ECS::ID.renderable,
+ ECS::ID.player_control)
+ECS::Components::Sprite.data[thing0.id].set(x: 576, y: 280, w: 128, h: 101, path: 'dragonruby.png')
+thing1 = ECS::Entity.new(ECS::ID.label, ECS::ID.renderable)
+ECS::Components::Label.data[thing1.id].set(x: 640, y: 460, text: 'Based ECS', size_enum: 5, alignment_enum: 1)
+thing2 = ECS::Entity.new(ECS::ID.label, ECS::ID.renderable)
+ECS::Components::Label.data[thing2.id].set(x: 640, y: 420, text: 'It Werks', size_enum: 5, alignment_enum: 1)
def tick args
+ puts60 '---'
ECS::Systems.constants.each do |constant|
- ECS::Systems::const_get(constant).run
+ ECS::Systems.const_get(constant).run
end
- args.outputs.labels << [640, 500, ECS::Components::TestComponent.data[@thing0.id].x, 5, 1]
- args.outputs.labels << [640, 460, @thing0, 5, 1]
- args.outputs.labels << [640, 420, 'Join the Discord! http://discord.dragonruby.org', 5, 1]
- args.outputs.sprites << [576, 280, 128, 101, 'dragonruby.png']
- @render = Sprite.objects[1] if args.inputs.keyboard.key_held.a
- @render = Sprite.objects[0] if args.inputs.keyboard.key_held.s
- args.outputs.sprites << @render
+ puts60 '---'
end