mirror of
https://github.com/OMGeeky/andors-trail.git
synced 2026-02-23 15:38:29 +01:00
Create worlds scripts
This commit is contained in:
7
AndorsTrail/create_worlds.bat
Normal file
7
AndorsTrail/create_worlds.bat
Normal file
@@ -0,0 +1,7 @@
|
||||
@echo off
|
||||
echo Creating folder for worlds
|
||||
mkdir %~dp0\res\xml\worlds
|
||||
echo Creating worlds
|
||||
python %~dp0\tools\create_worlds.py %~dp0\res\xml\
|
||||
echo Done!
|
||||
# pause
|
||||
52
AndorsTrail/tools/create_worlds.py
Normal file
52
AndorsTrail/tools/create_worlds.py
Normal file
@@ -0,0 +1,52 @@
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from xml.etree import ElementTree as etree
|
||||
|
||||
|
||||
def convert(xml_path: Path, world_folder: Path):
|
||||
with open(xml_path, 'r') as xml_f:
|
||||
xml = etree.fromstring(xml_f.read())
|
||||
|
||||
maps_folder = world_folder.parent
|
||||
|
||||
for segment in xml.findall('segment'):
|
||||
segment_id = segment.get('id')
|
||||
world = {}
|
||||
|
||||
maps = []
|
||||
for xml_map in segment.findall('map'):
|
||||
x = int(xml_map.get('x'))
|
||||
y = int(xml_map.get('y'))
|
||||
id = xml_map.get('id')
|
||||
with open(Path(maps_folder, f'{id}.tmx'), 'r') as map_f:
|
||||
map_tmx = etree.fromstring(map_f.read())
|
||||
|
||||
tilewidth = int(map_tmx.get('tilewidth'))
|
||||
tileheight = int(map_tmx.get('tileheight'))
|
||||
width = int(map_tmx.get('width'))
|
||||
height = int(map_tmx.get('height'))
|
||||
|
||||
map = {
|
||||
'fileName': f'../{id}.tmx',
|
||||
"height": width * tilewidth,
|
||||
"width": height * tileheight,
|
||||
'x': x * tilewidth,
|
||||
'y': y * tileheight,
|
||||
}
|
||||
maps.append(map)
|
||||
|
||||
world['maps'] = maps
|
||||
world["onlyShowAdjacentMaps"] = False
|
||||
world["type"] = "world"
|
||||
with open(Path(world_folder, f'{segment_id}.world'), 'w') as f:
|
||||
json.dump(world, f, indent=4)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if sys.argv:
|
||||
folder = Path(sys.argv[1])
|
||||
else:
|
||||
folder = Path('./res\\xml\\')
|
||||
convert(Path(folder, 'worldmap.xml'),
|
||||
Path(folder, 'worlds'))
|
||||
Reference in New Issue
Block a user