Class: DXRuby::Tiled::Layer
- Inherits:
-
Object
- Object
- DXRuby::Tiled::Layer
- Defined in:
- lib/dxruby_tiled/layer.rb
Direct Known Subclasses
HexagonalLayer, IsometricLayer, OrthogonalLayer, StaggeredLayer
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#offset_x ⇒ Object
Returns the value of attribute offset_x.
-
#offset_y ⇒ Object
Returns the value of attribute offset_y.
-
#opacity ⇒ Object
Returns the value of attribute opacity.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#visible ⇒ Object
Returns the value of attribute visible.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #[](x, y) ⇒ Object
- #[]=(x, y, value) ⇒ Object
- #include?(x, y) ⇒ Boolean (also: #member?)
-
#initialize(data, map) ⇒ Layer
constructor
A new instance of Layer.
Constructor Details
#initialize(data, map) ⇒ Layer
Returns a new instance of Layer.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/dxruby_tiled/layer.rb', line 7 def initialize(data, map) @map = map @name = data[:name] @width = data[:width ] || map.width @height = data[:height] || map.height @opacity = data[:opacity] || 1.0 @visible = data[:visible] != false @offset_x = data[:offsetx] || 0 @offset_y = data[:offsety] || 0 @properties = data[:properties] || {} case data[:encoding] when "base64" tmp = Base64.decode64(data[:data]) case data[:compression] when "gzip" # unsupported when "zlib" tmp = Zlib::Inflate.inflate(tmp).unpack("l*") else tmp = tmp.unpack("l*") end else tmp = data[:data] end @data = tmp.each_slice(@width).to_a end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
4 5 6 |
# File 'lib/dxruby_tiled/layer.rb', line 4 def data @data end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
4 5 6 |
# File 'lib/dxruby_tiled/layer.rb', line 4 def height @height end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/dxruby_tiled/layer.rb', line 4 def name @name end |
#offset_x ⇒ Object
Returns the value of attribute offset_x.
5 6 7 |
# File 'lib/dxruby_tiled/layer.rb', line 5 def offset_x @offset_x end |
#offset_y ⇒ Object
Returns the value of attribute offset_y.
5 6 7 |
# File 'lib/dxruby_tiled/layer.rb', line 5 def offset_y @offset_y end |
#opacity ⇒ Object
Returns the value of attribute opacity.
5 6 7 |
# File 'lib/dxruby_tiled/layer.rb', line 5 def opacity @opacity end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
4 5 6 |
# File 'lib/dxruby_tiled/layer.rb', line 4 def properties @properties end |
#visible ⇒ Object
Returns the value of attribute visible.
5 6 7 |
# File 'lib/dxruby_tiled/layer.rb', line 5 def visible @visible end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
4 5 6 |
# File 'lib/dxruby_tiled/layer.rb', line 4 def width @width end |
Instance Method Details
#[](x, y) ⇒ Object
35 36 37 38 39 |
# File 'lib/dxruby_tiled/layer.rb', line 35 def [](x, y) x = @map.x_loop ? x % @width : x < 0 ? @width : x y = @map.y_loop ? y % @height : y < 0 ? @height : y return @data.fetch(y, []).fetch(x, 0) end |
#[]=(x, y, value) ⇒ Object
41 42 43 44 45 |
# File 'lib/dxruby_tiled/layer.rb', line 41 def []=(x, y, value) x = @map.x_loop ? x % @width : x < 0 ? @width : x y = @map.y_loop ? y % @height : y < 0 ? @height : y @data[y][x] = value end |
#include?(x, y) ⇒ Boolean Also known as: member?
47 48 49 50 |
# File 'lib/dxruby_tiled/layer.rb', line 47 def include?(x, y) return (@map.x_loop || (0...@width).include?(x)) && (@map.y_loop || (0...@height).include?(y)) end |