From 20bfa95e91b1535956e4fd1c55f6c63a2628f486 Mon Sep 17 00:00:00 2001 From: oldnapalm <38410858+oldnapalm@users.noreply.github.com> Date: Sat, 20 Jan 2024 14:42:01 -0300 Subject: [PATCH] Update get_start_lines.py --- scripts/get_start_lines.py | 54 ++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/scripts/get_start_lines.py b/scripts/get_start_lines.py index 8d62cd99..9109f1af 100644 --- a/scripts/get_start_lines.py +++ b/scripts/get_start_lines.py @@ -1,31 +1,45 @@ -# Get start lines from files Zwift\assets\Worlds\world*\data_1.wad\Worlds\world*\routes\routes*.xml - import os import xml.etree.ElementTree as ET import re import csv +import subprocess -data = [] - -for directory in os.listdir('.'): - if not os.path.isdir(directory): - continue +worlds = 'C:\\Program Files (x86)\\Zwift\\assets\\Worlds' - for file in os.listdir(directory): - if not file.endswith('.xml'): - continue +world_names = { + '1': 'Watopia', + '2': 'Richmond', + '3': 'London', + '4': 'New York', + '5': 'Innsbruck', + '6': 'Bologna', + '7': 'Yorkshire', + '8': 'Crit City', + '9': 'Makuri Islands', + '10': 'France', + '11': 'Paris', + '12': 'Gravel Mountain', + '13': 'Scotland' +} - with open(os.path.join(directory, file)) as f: - xml = f.read() +data = [] - tree = ET.fromstring(re.sub(r"(<\?xml[^>]+\?>)", r"\1", xml) + "") - route = tree.find('route') - name = route.get('name').strip() - nameHash = int.from_bytes(int(route.get('nameHash')).to_bytes(4, 'little'), 'little', signed=True) - checkpoints = list(tree.find('highrescheckpoint').iter('entry')) - startRoad = checkpoints[0].get('road') - startTime = int(float(checkpoints[0].get('time')) * 1000000 + 5000) - data.append([nameHash, startRoad, startTime, directory, name]) +for directory in os.listdir(worlds): + world = directory[5:] + if os.path.isdir(os.path.join(worlds, directory)) and world in world_names: + subprocess.run(['wad_unpack.exe', os.path.join(worlds, directory, 'data_1.wad')]) + routes = os.path.join('Worlds', directory, 'routes') + for file in os.listdir(routes): + with open(os.path.join(routes, file)) as f: + xml = f.read() + tree = ET.fromstring(re.sub(r"(<\?xml[^>]+\?>)", r"\1", xml) + "") + route = tree.find('route') + name = route.get('name').strip() + nameHash = int.from_bytes(int(route.get('nameHash')).to_bytes(4, 'little'), 'little', signed=True) + checkpoints = list(tree.find('highrescheckpoint').iter('entry')) + startRoad = checkpoints[0].get('road') + startTime = int(float(checkpoints[0].get('time')) * 1000000 + 5000) + data.append([nameHash, startRoad, startTime, world_names[world], name]) with open('start_lines.csv', 'w', newline='') as f: writer = csv.writer(f)