From 780bdc631d6d9b5d939f8716598cc9a875322d10 Mon Sep 17 00:00:00 2001 From: wushin Date: Sun, 14 Jul 2013 16:39:27 -0500 Subject: Allow specifying warps in terms of tiles instead of pixels This interprets properties dest_tile_[xy] instead of dest_[xy]. Accepts both formats, but errors if there is a combination. --- tmx_converter.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tmx_converter.py b/tmx_converter.py index 009a114..379a4f3 100755 --- a/tmx_converter.py +++ b/tmx_converter.py @@ -92,6 +92,8 @@ class Warp(Object): 'dest_map', 'dest_x', 'dest_y', + 'dest_tile_x', + 'dest_tile_y', ) + other_warp_fields class ContentHandler(xml.sax.ContentHandler): @@ -264,12 +266,22 @@ class ContentHandler(xml.sax.ContentHandler): ]) ) elif isinstance(obj, Warp): + nx = hasattr(obj, 'dest_tile_x') + ny = hasattr(obj, 'dest_tile_y') + ox = hasattr(obj, 'dest_x') + oy = hasattr(obj, 'dest_y') + assert nx == ny != ox == oy, 'Error: mixed coordinate properties exist.' + + if ox: + obj.dest_tile_x = obj.dest_x / 32; + obj.dest_tile_y = obj.dest_y / 32; + self.warps.write( SEPARATOR.join([ '%s.gat,%d,%d' % (self.base, obj.x, obj.y), 'warp', obj.name, - '%d,%d,%s.gat,%d,%d\n' % (obj.w, obj.h, obj.dest_map, obj.dest_x / 32, obj.dest_y / 32), + '%d,%d,%s.gat,%d,%d\n' % (obj.w, obj.h, obj.dest_map, obj.dest_tile_x, obj.dest_tile_y), ]) ) -- cgit v1.2.3-70-g09d2