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.
-
#loop ⇒ Object
readonly
Returns the value of attribute loop.
-
#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.
-
#tiledversion ⇒ Object
readonly
Returns the value of attribute tiledversion.
-
#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.
Instance Method Summary collapse
- #delayed_dispose ⇒ Object
- #dispose ⇒ Object
- #disposed? ⇒ Boolean
-
#initialize(data, data_dir) ⇒ Map
constructor
A new instance of Map.
- #load_image(filename, transparentcolor = nil, data_dir = @data_dir) ⇒ Object
- #load_template(filename, encoding = Encoding::UTF_8, data_dir = @data_dir) ⇒ Object
- #load_tileset(filename, encoding = Encoding::UTF_8, data_dir = @data_dir) ⇒ Object
- #next_object_id ⇒ Object
- #pixel_height ⇒ Object
- #pixel_width ⇒ Object
- #render(x, y, target = DXRuby::Window, z = 0) ⇒ Object (also: #draw)
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 |
# File 'lib/dxruby_tiled/map.rb', line 11 def initialize(data, data_dir) @data_dir = data_dir @version = data[:version] @tiledversion = data[:tiledversion] @orientation = case data[:orientation] when "isometric" then IsometricLayer when "staggered" then StaggeredLayer when "hexagonal" then 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] || {} @loop = !!@properties[:loop] @renderorder_x = !data[:renderorder].to_s.match("left") @renderorder_y = !data[:renderorder].to_s.match("top") @background_color = nil if data[:backgroundcolor] @background_color = data[:backgroundcolor].sub("#", "").scan(/../).map{ |c| c.to_i(16) } end @tilesets = Tilesets.new(data[:tilesets], self) @layers = GroupLayer.new({ layers: data[:layers] }, 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 |
#loop ⇒ Object (readonly)
Returns the value of attribute loop.
4 5 6 |
# File 'lib/dxruby_tiled/map.rb', line 4 def loop @loop 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 |
#tiledversion ⇒ Object (readonly)
Returns the value of attribute tiledversion.
4 5 6 |
# File 'lib/dxruby_tiled/map.rb', line 4 def tiledversion @tiledversion 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 |
Instance Method Details
#delayed_dispose ⇒ Object
69 70 71 |
# File 'lib/dxruby_tiled/map.rb', line 69 def delayed_dispose @tilesets.delayed_dispose end |
#dispose ⇒ Object
65 66 67 |
# File 'lib/dxruby_tiled/map.rb', line 65 def dispose @tilesets.dispose end |
#disposed? ⇒ Boolean
73 74 75 |
# File 'lib/dxruby_tiled/map.rb', line 73 def disposed? @tilesets.disposed? end |
#load_image(filename, transparentcolor = nil, data_dir = @data_dir) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/dxruby_tiled/map.rb', line 77 def load_image(filename, transparentcolor = nil, data_dir = @data_dir) image = DXRuby::Image.load(File.join(data_dir, filename)) if transparentcolor color = transparentcolor.sub("#", "").scan(/../).map { |c| c.to_i(16) } image.set_color_key(color) end image end |
#load_template(filename, encoding = Encoding::UTF_8, data_dir = @data_dir) ⇒ Object
96 97 98 99 100 101 102 103 104 |
# File 'lib/dxruby_tiled/map.rb', line 96 def load_template(filename, encoding = Encoding::UTF_8, data_dir = @data_dir) filepath = File.join(data_dir, filename) case File.extname(filename) when ".tx", ".xml" DXRuby::Tiled::TMXLoader.tx_to_hash(DXRuby::Tiled::TMXLoader.read_xmlfile(filepath, encoding)) else DXRuby::Tiled.read_jsonfile(filepath, encoding) end end |
#load_tileset(filename, encoding = Encoding::UTF_8, data_dir = @data_dir) ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'lib/dxruby_tiled/map.rb', line 86 def load_tileset(filename, encoding = Encoding::UTF_8, data_dir = @data_dir) filepath = File.join(data_dir, filename) case File.extname(filename) when ".tsx", ".xml" DXRuby::Tiled::TMXLoader.tsx_to_hash(DXRuby::Tiled::TMXLoader.read_xmlfile(filepath, encoding)) else DXRuby::Tiled.read_jsonfile(filepath, encoding) end end |
#next_object_id ⇒ Object
60 61 62 63 |
# File 'lib/dxruby_tiled/map.rb', line 60 def next_object_id @next_object_id += 1 return @next_object_id - 1 end |
#pixel_height ⇒ Object
56 57 58 |
# File 'lib/dxruby_tiled/map.rb', line 56 def pixel_height @orientation.pixel_height(self) end |
#pixel_width ⇒ Object
52 53 54 |
# File 'lib/dxruby_tiled/map.rb', line 52 def pixel_width @orientation.pixel_width(self) end |
#render(x, y, target = DXRuby::Window, z = 0) ⇒ Object Also known as: draw
44 45 46 47 48 49 |
# File 'lib/dxruby_tiled/map.rb', line 44 def render(x, y, target = DXRuby::Window, z = 0) raise DXRuby::DXRubyError, "disposed object" if self.disposed? @tilesets.animate target.draw_box_fill(0, 0, target.width, target.height, @background_color, z) if @background_color @layers.render(x, y, target, z) end |