summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwushin <pasekei@gmail.com>2013-07-14 16:39:27 -0500
committerBen Longbons <b.r.longbons@gmail.com>2013-07-15 12:22:58 -0700
commit780bdc631d6d9b5d939f8716598cc9a875322d10 (patch)
treea4ce2a826dfd7e3225f2ed866d67662124685230
parent338235a4326d35ac4434bec95932a7b4f8e988d9 (diff)
downloadtools-780bdc631d6d9b5d939f8716598cc9a875322d10.tar.gz
tools-780bdc631d6d9b5d939f8716598cc9a875322d10.tar.bz2
tools-780bdc631d6d9b5d939f8716598cc9a875322d10.tar.xz
tools-780bdc631d6d9b5d939f8716598cc9a875322d10.zip
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.
-rwxr-xr-xtmx_converter.py14
1 files changed, 13 insertions, 1 deletions
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),
])
)