lib/dedalus/elements/image_grid.rb in dedalus-0.2.13 vs lib/dedalus/elements/image_grid.rb in dedalus-0.2.15

- old
+ new

@@ -1,66 +1,63 @@ module Dedalus module Elements - # TODO image grid should learn to use window#record http://www.rubydoc.info/github/jlnr/gosu/Gosu%2FWindow%3Arecord class ImageGrid < Dedalus::Molecule attr_accessor :grid, :tiles_path, :tile_width, :tile_height - attr_accessor :recorded_image + attr_accessor :scale + def show + if grid + grid.map do |row_elements| + row_elements.map do |grid_value| + if grid_value + sprite_for(grid_value) + else + no_image + end + end + end + else + [] + end + end + def name - 'an-image-grid' # we record these, so... we need a unique identifier that will persist across invocations -- in general we'll only be using one, but if they're layered you may need to differentiate... + @name ||= 'an-image-grid' # a uniq id for recording end def record? !grid.empty? end def width if grid && grid.first - grid.first.length * tile_width + grid.first.length * tile_height * scale else 0 end end def height if grid - grid.length * tile_height + grid.length * tile_height * scale else 0 end end - def show - if grid - grid.map do |row| - row.map do |grid_value| - if grid_value - sprite_for(grid_value) - else - no_image - end - end - end - else - [] - end - end - - def height - if grid - grid.length * tile_height - else - 0 - end - end - def sprite_for(frame) - Sprite.new(frame: frame, width: tile_width, height: tile_height, path: tiles_path) + Sprite.new( + frame: frame, + asset_width: tile_width, + asset_height: tile_height, + path: tiles_path, + scale: scale + ) end def no_image - Void.new(height: tile_height, width: tile_width) + Void.new(height: tile_height * scale, width: tile_width * scale) end def self.description "a grid of images" end @@ -68,14 +65,15 @@ def self.example_data { tiles_path: "media/images/tiles.png", tile_width: 64, tile_height: 64, + scale: 0.2, grid: [ - [ nil, 0, 2, 0 ], - [ 0, nil, 1, 0 ], - [ 0, 0, nil, 0 ], - [ 0, 1, 2, nil ], + [ nil, 0, 2, 0, 1 ], + [ 0, nil, 1, 0, 1 ], + [ 0, 0, nil, 0, 1 ], + [ 0, 1, 2, nil, 1 ], ] } end end end