Class: Dedalus::Elements::ImageGrid

Inherits:
Molecule show all
Defined in:
lib/dedalus/elements/image_grid.rb

Instance Attribute Summary collapse

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

Methods inherited from Molecule

#click, #hover

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

#gridObject

Returns the value of attribute grid.



4
5
6
# File 'lib/dedalus/elements/image_grid.rb', line 4

def grid
  @grid
end

#redraw_tilesObject

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

#scaleObject

Returns the value of attribute scale.



5
6
7
# File 'lib/dedalus/elements/image_grid.rb', line 5

def scale
  @scale
end

#tile_classObject

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_heightObject

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_widthObject

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_pathObject

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

.descriptionObject



69
70
71
# File 'lib/dedalus/elements/image_grid.rb', line 69

def self.description
  "a grid of images"
end

.example_dataObject



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

#heightObject



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

#nameObject



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_imageObject



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

Returns:

  • (Boolean)


31
32
33
# File 'lib/dedalus/elements/image_grid.rb', line 31

def record?
  (grid && !grid.empty?)
end

#rerecord?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/dedalus/elements/image_grid.rb', line 35

def rerecord?
  redraw_tiles
end

#showObject



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

#widthObject



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