Class: DXRuby::Tiled::Map
- Inherits:
-
Object
- Object
- DXRuby::Tiled::Map
- Defined in:
- lib/dxruby_tiled/map.rb
Instance Attribute Summary collapse
-
#background_color ⇒ Object
Returns the value of attribute background_color.
-
#data_dir ⇒ Object
readonly
Returns the value of attribute data_dir.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#hex_side_length ⇒ Object
readonly
Returns the value of attribute hex_side_length.
-
#layers ⇒ Object
readonly
Returns the value of attribute layers.
-
#next_object_id ⇒ Object
readonly
Returns the value of attribute next_object_id.
-
#orientation ⇒ Object
readonly
Returns the value of attribute orientation.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#renderorder_x ⇒ Object
readonly
Returns the value of attribute renderorder_x.
-
#renderorder_y ⇒ Object
readonly
Returns the value of attribute renderorder_y.
-
#stagger_axis_y ⇒ Object
readonly
Returns the value of attribute stagger_axis_y.
-
#stagger_index_odd ⇒ Object
readonly
Returns the value of attribute stagger_index_odd.
-
#tile_height ⇒ Object
readonly
Returns the value of attribute tile_height.
-
#tile_width ⇒ Object
readonly
Returns the value of attribute tile_width.
-
#tilesets ⇒ Object
readonly
Returns the value of attribute tilesets.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
-
#x_loop ⇒ Object
readonly
Returns the value of attribute x_loop.
-
#y_loop ⇒ Object
readonly
Returns the value of attribute y_loop.
Class Method Summary collapse
Instance Method Summary collapse
- #draw(x, y, target = DXRuby::Window) ⇒ Object
-
#initialize(data, data_dir) ⇒ Map
constructor
A new instance of Map.
- #load_image(filename) ⇒ Object
- #pixel_height ⇒ Object
- #pixel_width ⇒ Object
Constructor Details
#initialize(data, data_dir) ⇒ Map
Returns a new instance of Map.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/dxruby_tiled/map.rb', line 11 def initialize(data, data_dir) @data_dir = data_dir @version = data[:version] @orientation = case data[:orientation] when "isometric" IsometricLayer when "staggered" StaggeredLayer when "hexagonal" HexagonalLayer else OrthogonalLayer end @width = data[:width] || 100 @height = data[:height] || 100 @tile_width = data[:tilewidth] || 32 @tile_height = data[:tileheight] || 32 @hex_side_length = data[:hexsidelength] || 0 @stagger_axis_y = data[:staggeraxis] != "x" @stagger_index_odd = data[:staggerindex] != "even" @next_object_id = data[:nextobjectid] || 1 @properties = data[:properties] || {} @x_loop = !!@properties[:x_loop] @y_loop = !!@properties[:y_loop] @renderorder_x = false @renderorder_y = false case data[:renderorder] when "left-down" @renderorder_x = true when "right-up" @renderorder_y = true when "left-up" @renderorder_x = true @renderorder_y = true end @background_color = nil if data[:backgroundcolor] @background_color = data[:backgroundcolor].sub("#", "").scan(/../).map do |color| color.to_i(16) end end @layers = data[:layers].map do |layer| case layer[:type] when "tilelayer" @orientation.new(layer, self) when "objectgroup" ObjectGroup.new(layer, self) when "imagelayer" ImageLayer.new(layer, self) end end def @layers.name(name) return self.find{|layer| layer.name == name} end @tilesets = Tilesets.new(data[:tilesets], self) end |
Instance Attribute Details
#background_color ⇒ Object
Returns the value of attribute background_color.
9 10 11 |
# File 'lib/dxruby_tiled/map.rb', line 9 def background_color @background_color end |
#data_dir ⇒ Object (readonly)
Returns the value of attribute data_dir.
4 5 6 |
# File 'lib/dxruby_tiled/map.rb', line 4 def data_dir @data_dir end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
4 5 6 |
# File 'lib/dxruby_tiled/map.rb', line 4 def height @height end |
#hex_side_length ⇒ Object (readonly)
Returns the value of attribute hex_side_length.
4 5 6 |
# File 'lib/dxruby_tiled/map.rb', line 4 def hex_side_length @hex_side_length end |
#layers ⇒ Object (readonly)
Returns the value of attribute layers.
4 5 6 |
# File 'lib/dxruby_tiled/map.rb', line 4 def layers @layers end |
#next_object_id ⇒ Object (readonly)
Returns the value of attribute next_object_id.
4 5 6 |
# File 'lib/dxruby_tiled/map.rb', line 4 def next_object_id @next_object_id end |
#orientation ⇒ Object (readonly)
Returns the value of attribute orientation.
4 5 6 |
# File 'lib/dxruby_tiled/map.rb', line 4 def orientation @orientation end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
4 5 6 |
# File 'lib/dxruby_tiled/map.rb', line 4 def properties @properties end |
#renderorder_x ⇒ Object (readonly)
Returns the value of attribute renderorder_x.
4 5 6 |
# File 'lib/dxruby_tiled/map.rb', line 4 def renderorder_x @renderorder_x end |
#renderorder_y ⇒ Object (readonly)
Returns the value of attribute renderorder_y.
4 5 6 |
# File 'lib/dxruby_tiled/map.rb', line 4 def renderorder_y @renderorder_y end |
#stagger_axis_y ⇒ Object (readonly)
Returns the value of attribute stagger_axis_y.
4 5 6 |
# File 'lib/dxruby_tiled/map.rb', line 4 def stagger_axis_y @stagger_axis_y end |
#stagger_index_odd ⇒ Object (readonly)
Returns the value of attribute stagger_index_odd.
4 5 6 |
# File 'lib/dxruby_tiled/map.rb', line 4 def stagger_index_odd @stagger_index_odd end |
#tile_height ⇒ Object (readonly)
Returns the value of attribute tile_height.
4 5 6 |
# File 'lib/dxruby_tiled/map.rb', line 4 def tile_height @tile_height end |
#tile_width ⇒ Object (readonly)
Returns the value of attribute tile_width.
4 5 6 |
# File 'lib/dxruby_tiled/map.rb', line 4 def tile_width @tile_width end |
#tilesets ⇒ Object (readonly)
Returns the value of attribute tilesets.
4 5 6 |
# File 'lib/dxruby_tiled/map.rb', line 4 def tilesets @tilesets end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
4 5 6 |
# File 'lib/dxruby_tiled/map.rb', line 4 def version @version end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
4 5 6 |
# File 'lib/dxruby_tiled/map.rb', line 4 def width @width end |
#x_loop ⇒ Object (readonly)
Returns the value of attribute x_loop.
4 5 6 |
# File 'lib/dxruby_tiled/map.rb', line 4 def x_loop @x_loop end |
#y_loop ⇒ Object (readonly)
Returns the value of attribute y_loop.
4 5 6 |
# File 'lib/dxruby_tiled/map.rb', line 4 def y_loop @y_loop end |
Class Method Details
.name(name) ⇒ Object
64 65 66 |
# File 'lib/dxruby_tiled/map.rb', line 64 def @layers.name(name) return self.find{|layer| layer.name == name} end |
Instance Method Details
#draw(x, y, target = DXRuby::Window) ⇒ Object
71 72 73 74 75 |
# File 'lib/dxruby_tiled/map.rb', line 71 def draw(x, y, target = DXRuby::Window) target.draw_box_fill(0, 0, target.width, target.height, @background_color) if @background_color tilesets.animation() @layers.each{|layer| layer.draw(x, y, target) if layer.visible } end |
#load_image(filename) ⇒ Object
77 78 79 |
# File 'lib/dxruby_tiled/map.rb', line 77 def load_image(filename) return DXRuby::Image.load(File.join(@data_dir, filename)) end |
#pixel_height ⇒ Object
85 86 87 |
# File 'lib/dxruby_tiled/map.rb', line 85 def pixel_height() return @orientation.pixel_height(self) end |
#pixel_width ⇒ Object
81 82 83 |
# File 'lib/dxruby_tiled/map.rb', line 81 def pixel_width() return @orientation.pixel_width(self) end |