# -*- coding: utf-8 -*-
from xml.dom import minidom
from commands import getstatusoutput
import codecs
vedname_in = 'mygame.ved' # your game file
vedname_out = 'mygame_out.ved' # result file
print 'Read %s...' % vedname_in
xmldoc = minidom.parse(vedname_in)
# update sprite positions
for setup in ['SpriteSprite', 'InterfaceSprite', 'SceneSprite', 'sprite']:
objects = xmldoc.getElementsByTagName(setup)
print 'CHECK %ss (%d)...' % (setup, len(objects))
for sid in objects:
picpath = sid.attributes['path'].value
if not '#' in picpath: continue # skip all not #-marked files
posfeld = sid.getElementsByTagName('position')
ox = int(posfeld[0].attributes['x'].value)
oy = int(posfeld[0].attributes['y'].value)
status, output = getstatusoutput('convert %s -format "%%X %%Y" info:' % (picpath))
px, py = map(int, output.split())
if ox != px or oy != py:
posfeld[0].attributes['x'].value = str(px)
posfeld[0].attributes['y'].value = str(py)
print '** --> image %s moved to (%d, %d)' % (picpath, px, py)
print 'Save %s...' % vedname_out
file_handle = codecs.open(vedname_out, 'w', 'utf-8')
xmldoc.writexml(file_handle, encoding='UTF-8')
file_handle.close()