Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is a Python script I used to generate sd .tmx from hd .tmx. You can use it by following shell command.</p> <pre><code>&gt;python change_tmx_numbers.py &lt;directory_which_contains_hd_tmx_files&gt; &lt;output_directory&gt; </code></pre> <p>The script:</p> <pre class="lang-python prettyprint-override"><code>#!/usr/bin/python import os import shutil import sys import xml.etree.cElementTree as ET import re def npath(path): if path[-1] == '/': return path[:-1] return path; def subdir(*paths): return '/'.join(paths) def changeText(text): print text pointm = '\{(?P&lt;x&gt;-?\d+), (?P&lt;y&gt;-?\d+)\}' framem = '\{\{(?P&lt;x&gt;-?\d+), (?P&lt;y&gt;-?\d+)\}, \{(?P&lt;width&gt;\d+), (?P&lt;height&gt;\d+)\}\}' m = re.match(pointm, text) if m != None: rt = '{%d, %d}' % tuple([int(f) / 2 for f in m.groups()]) print 'change %s -&gt; %s' % (text, rt) return rt else: m = re.match(framem, text) if m != None: rt = '{{%d, %d}, {%d, %d}}' % tuple([int(f) / 2 for f in m.groups()]) print 'change %s -&gt; %s' % (text, rt) return rt else: print 'text: \"' + text + '\" is not matched' return text def resizeElement(element): elems = list(element) if(len(elems) == 0 and element.text != None): element.text = changeText(element.text) else: for el in elems: resizeElement(el) def resizeAttToHalf(attrib, keys): for key in keys: if key in attrib: attrib[key] = str(int(attrib[key]) / 2) return attrib def resizeMap(map): map.attrib = resizeAttToHalf(map.attrib, ['tilewidth', 'tileheight']) def resizeImage(im): im.attrib = resizeAttToHalf(im.attrib, ['width', 'height']) im.attrib['source'] = im.attrib['source'].replace('-hd', '') def resizeTileset(ts): ts.attrib = resizeAttToHalf(ts.attrib, ['tilewidth', 'tileheight']) for image in ts.findall('image'): resizeImage(image) def resizeProperty(prop): if 'name' in prop.attrib and prop.attrib['name'] == 'points': points = prop.attrib['value'].split(' ') nps = [','.join([str(int(p.split(',')[0])/2), str(int(p.split(',')[1])/2)]) for p in points] prop.attrib['value'] = ' '.join(nps) def resizePolygon(prop): points = prop.attrib['points'].split(' ') nps = [','.join([str(int(p.split(',')[0])/2), str(int(p.split(',')[1])/2)]) for p in points] prop.attrib['points'] = ' '.join(nps) def resizeObject(obj): obj.attrib = resizeAttToHalf(obj.attrib, ['x', 'y', 'width', 'height']) for props in obj.findall('properties'): for prop in props.findall('property'): resizeProperty(prop) for poly in obj.findall('polygon'): resizePolygon(poly) def resizeplist(plist, dest): doc = ET.parse(plist) map = doc.getroot() resizeMap(map) for tileset in map.findall('tileset'): resizeTileset(tileset) for objectg in map.findall('objectgroup'): for obj in objectg.findall('object'): resizeObject(obj) destf = open(dest, 'w') prologue = '&lt;?xml version="1.0" encoding="UTF-8"?&gt;\n&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;\n' destf.write(prologue) doc.write(destf) destf.close() def walkdir(path, dest): files = [f for f in os.listdir(path) if not os.path.isdir(subdir(path, f))] dirs = [d for d in os.listdir(path) if os.path.isdir(subdir(path, d))] for f in files: if (f.endswith('-hd.tmx')): resizeplist(subdir(path, f), subdir(path, f.replace('-hd', ''))) # for d in dirs: # walkdir(subdir(path, d), subdir(dest, d)) if __name__ == "__main__": path = npath(sys.argv[1]) dest = npath(sys.argv[2]) walkdir(path, dest) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload