From 490b20123c75cf8eb5de7039993cb704e3d7a0c8 Mon Sep 17 00:00:00 2001 From: realtradam Date: Wed, 19 May 2021 02:23:17 -0400 Subject: working json to sprite conversion --- app/ECS/components/00_renderable.rb | 8 +++++++- app/ECS/components/02_label.rb | 22 +++++++++++----------- app/ECS/components/03_player_control.rb | 23 ++++++++++++----------- app/ECS/components/04_map.rb | 21 +++++++++++++++++++++ app/ECS/components/05_map_object.rb | 16 ++++++++++++++++ app/ECS/components/06_grid_singleton.rb | 16 ++++++++++++++++ app/ECS/signatures.rb | 18 +++++++++++------- app/ECS/systems/00_player.rb | 4 ++-- app/ECS/systems/99_render.rb | 19 +++++++++++-------- 9 files changed, 107 insertions(+), 40 deletions(-) create mode 100644 app/ECS/components/04_map.rb create mode 100644 app/ECS/components/05_map_object.rb create mode 100644 app/ECS/components/06_grid_singleton.rb (limited to 'app/ECS') diff --git a/app/ECS/components/00_renderable.rb b/app/ECS/components/00_renderable.rb index 18017cc..270e5f9 100644 --- a/app/ECS/components/00_renderable.rb +++ b/app/ECS/components/00_renderable.rb @@ -3,8 +3,14 @@ class Components class Renderable < BaseComponent attr_accessor :z - def initialize(z: 0) + def initialize @z = z end + + def set(**opts) + opts.each do |key, value| + self.send "#{key}=", value + end + end end end diff --git a/app/ECS/components/02_label.rb b/app/ECS/components/02_label.rb index 2483d57..aed00ed 100644 --- a/app/ECS/components/02_label.rb +++ b/app/ECS/components/02_label.rb @@ -7,17 +7,17 @@ class Components 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] + {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 diff --git a/app/ECS/components/03_player_control.rb b/app/ECS/components/03_player_control.rb index 22bc458..58d0102 100644 --- a/app/ECS/components/03_player_control.rb +++ b/app/ECS/components/03_player_control.rb @@ -1,20 +1,21 @@ class Components # Gives control(keyboard or otherwise) over an object class PlayerControl < BaseComponent - attr_accessor :north, :south, :east, :west + attr_accessor :north, :south, :east, :west, :interact, :menu - def initialize(north: 'w', south: 's', east: 'd', west: 'a') - @north = north - @south = south - @east = east - @west = west + def initialize + @north = 'w' + @south = 's' + @east = 'd' + @west = 'a' + @interact = 'space' + @menu = 'enter' end - def set(north: 'w', south: 's', east: 'd', west: 'a') - @north = north - @south = south - @east = east - @west = west + def set(**opts) + opts.each do |key, value| + send "#{key}=", value + end end end end diff --git a/app/ECS/components/04_map.rb b/app/ECS/components/04_map.rb new file mode 100644 index 0000000..804fc02 --- /dev/null +++ b/app/ECS/components/04_map.rb @@ -0,0 +1,21 @@ +class Components + # dragonruby label wrapper + class Map < 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/app/ECS/components/05_map_object.rb b/app/ECS/components/05_map_object.rb new file mode 100644 index 0000000..270e5f9 --- /dev/null +++ b/app/ECS/components/05_map_object.rb @@ -0,0 +1,16 @@ +class Components + # If an entity can be rendered on screen + class Renderable < BaseComponent + attr_accessor :z + + def initialize + @z = z + end + + def set(**opts) + opts.each do |key, value| + self.send "#{key}=", value + end + end + end +end diff --git a/app/ECS/components/06_grid_singleton.rb b/app/ECS/components/06_grid_singleton.rb new file mode 100644 index 0000000..392d770 --- /dev/null +++ b/app/ECS/components/06_grid_singleton.rb @@ -0,0 +1,16 @@ +class Components + # If an entity can be rendered on screen + class GridSingleton < 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/app/ECS/signatures.rb b/app/ECS/signatures.rb index 844c66d..d3ac390 100644 --- a/app/ECS/signatures.rb +++ b/app/ECS/signatures.rb @@ -1,27 +1,31 @@ class ID class < layer['chunks'].count + end + 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 #puts60 temp.inspect - $gtk.args.outputs.sprites << temp + $gtk.args.outputs.sprites << tile end end end -- cgit v1.2.3