sneak/tools/scripts/convert_sprite_json.py

37 lines
753 B
Python
Raw Normal View History

2020-03-03 22:35:57 +00:00
#!/usr/bin/env python3
import glob
import os
import re
import sys
TEMPLATE = r"""<?xml version="1.0" encoding="utf-8" ?>
<XnaContent>
<Asset Type="System.String">
<![CDATA[
%s
]]>
</Asset>
</XnaContent>
"""
def main(args):
this_dir = os.path.dirname(os.path.realpath(__file__))
sneak_root = os.path.join(this_dir, '..', '..', '..')
os.chdir(sneak_root)
json_files = sorted(glob.glob('Content/sprites/**/*.json', recursive=True))
for json_file in json_files:
with open(json_file) as json:
outfile_name = re.sub(r'.json$', '_json.xml', json_file)
result = TEMPLATE % json.read()
with open(outfile_name, 'w') as out:
out.write(result)
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))