retmx 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/retmx.rb +29 -15
- data/lib/retmx_sdl.rb +13 -5
- metadata +3 -3
data/lib/retmx.rb
CHANGED
@@ -12,8 +12,7 @@ module RETMX
|
|
12
12
|
include REXML
|
13
13
|
|
14
14
|
def RETMX.load(file)
|
15
|
-
|
16
|
-
m = Map.new(doc.root)
|
15
|
+
m = Map.new(file)
|
17
16
|
end
|
18
17
|
|
19
18
|
|
@@ -75,10 +74,19 @@ module RETMX
|
|
75
74
|
|
76
75
|
#Properties on map
|
77
76
|
attr_reader :property
|
78
|
-
|
77
|
+
|
78
|
+
#File where get map
|
79
|
+
attr_reader :file
|
80
|
+
|
79
81
|
#REXML internal
|
80
82
|
attr_reader :xml
|
81
|
-
def initialize(
|
83
|
+
def initialize(file)
|
84
|
+
|
85
|
+
raise RuntimeError, "Need a .tmx" unless File.exists? file
|
86
|
+
doc = REXML::Document.new(File.new(file)).root
|
87
|
+
|
88
|
+
|
89
|
+
@file = file
|
82
90
|
@version = doc.attributes['version']
|
83
91
|
@orientation = doc.attributes['orientation']
|
84
92
|
@width = doc.attributes['width'].to_i
|
@@ -223,28 +231,29 @@ When the object has a gid set, then it is represented by the image of the tile w
|
|
223
231
|
#REXML internal
|
224
232
|
attr_reader :xml
|
225
233
|
def initialize(map, xml)
|
226
|
-
|
234
|
+
@map = map
|
227
235
|
@name = xml.attributes['name']
|
228
236
|
@x = xml.attributes['x'].nil? ? 0 : xml.attributes['x']
|
229
237
|
@y = xml.attributes['y'].nil? ? 0 : xml.attributes['y']
|
230
|
-
@width = xml.attributes['width'].nil? ?
|
231
|
-
@height = xml.attributes['height'].nil? ?
|
238
|
+
@width = xml.attributes['width'].nil? ? map.width : xml.attributes['width'].to_i
|
239
|
+
@height = xml.attributes['height'].nil? ? map.height : xml.attributes['height'].to_i
|
232
240
|
@opacity = xml.attributes['opacity'].nil? ? 1 : xml.attributes['opacity'].to_i
|
233
241
|
@visible = xml.attributes['visible'].nil? ? 1 : xml.attributes['visible'].to_i
|
234
242
|
@opacity = xml.attributes['opacity'].nil? ? 1 : xml.attributes['opacity'].to_f
|
235
243
|
@data = nil
|
236
|
-
@map = map
|
237
244
|
build(xml)
|
238
245
|
end
|
239
246
|
|
240
247
|
|
241
248
|
#This function is used for render the layer
|
242
249
|
def render(&block) #:yields: block_y, block_x, tileset, index
|
250
|
+
|
243
251
|
@height.times {|by| #block row
|
244
|
-
@width.times {|bx| #block col
|
245
|
-
cell = @data[(by * @
|
252
|
+
@width.times {|bx| #block col
|
253
|
+
cell = @data[(by * @width) + bx ]
|
246
254
|
@map.tilesets.each {|k, t|
|
247
255
|
if t.firstgid <= cell.gid
|
256
|
+
cell = cell.clone
|
248
257
|
cell.gid -= t.firstgid
|
249
258
|
block.call(self, bx, by, t, cell)
|
250
259
|
break
|
@@ -252,6 +261,7 @@ When the object has a gid set, then it is represented by the image of the tile w
|
|
252
261
|
}
|
253
262
|
}
|
254
263
|
}
|
264
|
+
|
255
265
|
end
|
256
266
|
|
257
267
|
#This function render partial of layer
|
@@ -262,9 +272,11 @@ When the object has a gid set, then it is represented by the image of the tile w
|
|
262
272
|
def render_partial(x, y, w, h, &block)
|
263
273
|
h.times {|by|
|
264
274
|
w.times {|bx|
|
265
|
-
cell = @data[((by + y ) *
|
275
|
+
cell = @data[((by + y ) * w) + (bx + x)]
|
266
276
|
@map.tilesets.each {|k, t|
|
277
|
+
|
267
278
|
if t.firstgid <= cell.gid
|
279
|
+
cell = cell.clone
|
268
280
|
cell.gid -= t.firstgid
|
269
281
|
block.call(self, bx, by, t, cell)
|
270
282
|
break
|
@@ -282,8 +294,8 @@ When the object has a gid set, then it is represented by the image of the tile w
|
|
282
294
|
|
283
295
|
class Data
|
284
296
|
include Enumerable
|
285
|
-
GID_FLIP_X =
|
286
|
-
GID_FLIP_Y =
|
297
|
+
GID_FLIP_X = 0x80000000
|
298
|
+
GID_FLIP_Y = 0x40000000
|
287
299
|
|
288
300
|
#The encoding used to encode the tile layer data. When used, it can be "base64" and "csv" at the moment.
|
289
301
|
attr_reader :encoding
|
@@ -307,7 +319,7 @@ When the object has a gid set, then it is represented by the image of the tile w
|
|
307
319
|
@raw = []
|
308
320
|
@raw_data = xml.text
|
309
321
|
@data = []
|
310
|
-
|
322
|
+
|
311
323
|
#decoding
|
312
324
|
case @encoding
|
313
325
|
when 'base64'
|
@@ -341,9 +353,11 @@ When the object has a gid set, then it is represented by the image of the tile w
|
|
341
353
|
end
|
342
354
|
|
343
355
|
get_data
|
344
|
-
|
345
356
|
end
|
346
357
|
|
358
|
+
def size
|
359
|
+
@data.size
|
360
|
+
end
|
347
361
|
|
348
362
|
def [] (i)
|
349
363
|
@data[i]
|
data/lib/retmx_sdl.rb
CHANGED
@@ -20,7 +20,7 @@
|
|
20
20
|
|
21
21
|
|
22
22
|
require 'sdl'
|
23
|
-
|
23
|
+
|
24
24
|
|
25
25
|
module RETMX
|
26
26
|
|
@@ -39,11 +39,12 @@ module RETMX
|
|
39
39
|
raise RuntimeError, "Need a RETMX::Map or path to .tmx" unless tmx.kind_of? Map
|
40
40
|
end
|
41
41
|
|
42
|
-
|
42
|
+
@data_dir = File.dirname(@tmx.file)
|
43
43
|
@tileset_images = {}
|
44
44
|
@tmx.tilesets.each {|k,t|
|
45
|
-
|
46
|
-
|
45
|
+
fimage = File.join(@data_dir, t.image.source)
|
46
|
+
if File.exists? fimage or !@tileset_images.include? t.name
|
47
|
+
image = SDL::Surface.load(fimage)
|
47
48
|
image.setColorKey(SDL::SRCCOLORKEY, t.image.trans.hex) unless t.image.trans.nil?
|
48
49
|
@tileset_images[t.name] = image
|
49
50
|
end
|
@@ -83,6 +84,12 @@ module RETMX
|
|
83
84
|
}
|
84
85
|
end
|
85
86
|
|
87
|
+
def blit_layers(sx, sy, sw, sh, surface, dx, dy)
|
88
|
+
@tmx.layers.each {|name, layer|
|
89
|
+
blit_layer(name, sx, sy, sw, sh, surface, dx, dy)
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
86
93
|
#Perfoms a blit from layer at (+sx+,+sy+,+sw+,+sh+) to +surface+ at (+dx+, +dy)
|
87
94
|
#:sx: on tiles
|
88
95
|
#:sy: on tiles
|
@@ -123,8 +130,9 @@ if $0 == __FILE__
|
|
123
130
|
|
124
131
|
$screen = SDL.setVideoMode(tmx.width * tmx.tilewidth, tmx.height * tmx.tileheight, 0, 0)
|
125
132
|
|
133
|
+
|
126
134
|
#Blit specific layer
|
127
|
-
#tmxsdl.
|
135
|
+
#tmxsdl.blit_layers(0,0,9,8, $screen, 0, 0)
|
128
136
|
tmxsdl.put_layers($screen, 0, 0)
|
129
137
|
$screen.flip
|
130
138
|
until $quit
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: retmx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,9 +9,9 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-12-
|
12
|
+
date: 2011-12-16 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description:
|
14
|
+
description: Library for work with .tmx of mapeditor.org, generic work, see doc
|
15
15
|
email: info@manadalibre.org
|
16
16
|
executables: []
|
17
17
|
extensions: []
|