Skip to content

Commit

Permalink
Update get_start_lines.py
Browse files Browse the repository at this point in the history
  • Loading branch information
oldnapalm committed Jan 20, 2024
1 parent ccac832 commit 20bfa95
Showing 1 changed file with 34 additions and 20 deletions.
54 changes: 34 additions & 20 deletions scripts/get_start_lines.py
Original file line number Diff line number Diff line change
@@ -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<root>", xml) + "</root>")
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<root>", xml) + "</root>")
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)
Expand Down

0 comments on commit 20bfa95

Please sign in to comment.