Class: Dedalus::Elements::ImageGrid
- Inherits:
-
Molecule
- Object
- Dedalus::Element
- Molecule
- Dedalus::Elements::ImageGrid
- Defined in:
- lib/dedalus/elements/image_grid.rb
Instance Attribute Summary collapse
-
#grid ⇒ Object
Returns the value of attribute grid.
-
#redraw_tiles ⇒ Object
Returns the value of attribute redraw_tiles.
-
#scale ⇒ Object
Returns the value of attribute scale.
-
#tile_class ⇒ Object
Returns the value of attribute tile_class.
-
#tile_height ⇒ Object
Returns the value of attribute tile_height.
-
#tile_width ⇒ Object
Returns the value of attribute tile_width.
-
#tiles_path ⇒ Object
Returns the value of attribute tiles_path.
Attributes inherited from Dedalus::Element
#background_color, #color, #height_percent, #margin, #offset, #padding, #position, #shown, #width_percent, #z_order
Class Method Summary collapse
Instance Method Summary collapse
- #height ⇒ Object
- #name ⇒ Object
- #no_image ⇒ Object
- #record? ⇒ Boolean
- #rerecord? ⇒ Boolean
- #show ⇒ Object
- #sprite_for(frame) ⇒ Object
- #width ⇒ Object
Methods inherited from Molecule
Methods inherited from Dedalus::Element
#big_font, #code_font, #draw_bounding_box, #font, #huge_font, #initialize, #tiny_font, #view, #window
Constructor Details
This class inherits a constructor from Dedalus::Element
Instance Attribute Details
#grid ⇒ Object
Returns the value of attribute grid.
4 5 6 |
# File 'lib/dedalus/elements/image_grid.rb', line 4 def grid @grid end |
#redraw_tiles ⇒ Object
Returns the value of attribute redraw_tiles.
5 6 7 |
# File 'lib/dedalus/elements/image_grid.rb', line 5 def redraw_tiles @redraw_tiles end |
#scale ⇒ Object
Returns the value of attribute scale.
5 6 7 |
# File 'lib/dedalus/elements/image_grid.rb', line 5 def scale @scale end |
#tile_class ⇒ Object
Returns the value of attribute tile_class.
4 5 6 |
# File 'lib/dedalus/elements/image_grid.rb', line 4 def tile_class @tile_class end |
#tile_height ⇒ Object
Returns the value of attribute tile_height.
4 5 6 |
# File 'lib/dedalus/elements/image_grid.rb', line 4 def tile_height @tile_height end |
#tile_width ⇒ Object
Returns the value of attribute tile_width.
4 5 6 |
# File 'lib/dedalus/elements/image_grid.rb', line 4 def tile_width @tile_width end |
#tiles_path ⇒ Object
Returns the value of attribute tiles_path.
4 5 6 |
# File 'lib/dedalus/elements/image_grid.rb', line 4 def tiles_path @tiles_path end |
Class Method Details
.description ⇒ Object
69 70 71 |
# File 'lib/dedalus/elements/image_grid.rb', line 69 def self.description "a grid of images" end |
.example_data ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/dedalus/elements/image_grid.rb', line 73 def self.example_data { tiles_path: "media/images/tiles.png", tile_width: 64, tile_height: 64, tile_class: "Dedalus::Elements::MapTile", #Elements::Sprite", scale: 0.2, grid: [ [ nil, 0, 2, 0, 1 ], [ 0, nil, 1, 0, 1 ], [ 0, 0, nil, 0, 1 ], [ 0, 1, 2, nil, 1 ], ] } end |
Instance Method Details
#height ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/dedalus/elements/image_grid.rb', line 47 def height if grid grid.length * tile_height * scale else 0 end end |
#name ⇒ Object
23 24 25 |
# File 'lib/dedalus/elements/image_grid.rb', line 23 def name @name ||= 'an-image-grid' # a uniq id for recording end |
#no_image ⇒ Object
65 66 67 |
# File 'lib/dedalus/elements/image_grid.rb', line 65 def no_image Void.new(height: tile_height * scale, width: tile_width * scale) end |
#record? ⇒ Boolean
31 32 33 |
# File 'lib/dedalus/elements/image_grid.rb', line 31 def record? (grid && !grid.empty?) end |
#rerecord? ⇒ Boolean
35 36 37 |
# File 'lib/dedalus/elements/image_grid.rb', line 35 def rerecord? redraw_tiles end |
#show ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/dedalus/elements/image_grid.rb', line 7 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 |
#sprite_for(frame) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/dedalus/elements/image_grid.rb', line 55 def sprite_for(frame) tile_class.constantize.new( frame: frame, asset_width: tile_width, asset_height: tile_height, path: tiles_path, scale: scale ) end |
#width ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/dedalus/elements/image_grid.rb', line 39 def width if grid && grid.first grid.first.length * tile_width * scale else 0 end end |