Class: RETMX::Map::Layer::Data
- Inherits:
-
Object
- Object
- RETMX::Map::Layer::Data
- Includes:
- Enumerable
- Defined in:
- lib/retmx.rb
Constant Summary collapse
- GID_FLIP_X =
1.<< 31
- GID_FLIP_Y =
1.<< 30
Instance Attribute Summary collapse
-
#compression ⇒ Object
readonly
The compression used to compress the tile layer data.
-
#encoding ⇒ Object
readonly
The encoding used to encode the tile layer data.
-
#layer ⇒ Object
readonly
Layer belongs.
-
#xml ⇒ Object
readonly
REXML internal.
Instance Method Summary collapse
- #[](i) ⇒ Object
- #each ⇒ Object
-
#initialize(layer, xml) ⇒ Data
constructor
A new instance of Data.
Constructor Details
#initialize(layer, xml) ⇒ Data
Returns a new instance of Data.
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
# File 'lib/retmx.rb', line 301 def initialize(layer, xml) @layer = layer @xml = xml @encoding = xml.attributes['encoding'] @compression = xml.attributes['compression'] @raw = [] @raw_data = xml.text @data = [] #decoding case @encoding when 'base64' @raw_data = Base64.decode64(@raw_data) when 'csv' @raw_data = @raw_data.tr("\n",'') end #inflate compress case @compression when 'zlib' zs = Zlib::Inflate.new @raw_data = zs.inflate(@raw_data) zs.finish zs.close when 'gzip' gz = Zlib::GzipReader.new(StringIO.new(@raw_data)) @raw_data = gz.read gz.close end #Data XML if @encoding.nil? and @compression.nil? xml.elements.each('tile') {|e| @raw << e.attributes['gid'].to_i } elsif @encoding == 'csv' @raw = @raw_data.split(',').collect {|x| x.to_i} else @raw = @raw_data.unpack("V*") end get_data end |
Instance Attribute Details
#compression ⇒ Object (readonly)
The compression used to compress the tile layer data. Tiled Qt supports “gzip” and “zlib”.
292 293 294 |
# File 'lib/retmx.rb', line 292 def compression @compression end |
#encoding ⇒ Object (readonly)
The encoding used to encode the tile layer data. When used, it can be “base64” and “csv” at the moment.
289 290 291 |
# File 'lib/retmx.rb', line 289 def encoding @encoding end |
#layer ⇒ Object (readonly)
Layer belongs
295 296 297 |
# File 'lib/retmx.rb', line 295 def layer @layer end |
#xml ⇒ Object (readonly)
REXML internal
298 299 300 |
# File 'lib/retmx.rb', line 298 def xml @xml end |
Instance Method Details
#[](i) ⇒ Object
348 349 350 |
# File 'lib/retmx.rb', line 348 def [] (i) @data[i] end |
#each ⇒ Object
352 353 354 |
# File 'lib/retmx.rb', line 352 def each @data.each { |i| yield i } end |