Skip to content

Instantly share code, notes, and snippets.

@crabdancing
Last active August 31, 2023 22:49
Show Gist options
  • Save crabdancing/e8e3d53cffb484876e0f610ad80d1311 to your computer and use it in GitHub Desktop.
Save crabdancing/e8e3d53cffb484876e0f610ad80d1311 to your computer and use it in GitHub Desktop.
Converting JourneyMap waypoints to Xaero waypoints
#!/usr/bin/env python3
# IDK this is GNU GPLv3 or osmething, leave me alone
# --Alexandria 2021
from pathlib import Path
import json
import pydantic
from typing import List
import random
def lb2s(b: bool) -> str:
""" Lowercase string from bool """
return 'true' if b else 'false'
class WayPoint(pydantic.BaseModel):
id: str
name: str
icon: str
x: int
y: int
z: int
r: int
g: int
b: int
enable: bool
type: str
origin: str
dimensions: List[str]
persistent: bool
showDeviation: bool
paths = Path('.').glob('*.json')
xaero_colors = ['black', 'dark blue', 'dark green', 'dark aqua', 'dark red', 'dark purple',
'gold', 'grey', 'dark grey', 'blue', 'green', 'aqua', 'red', 'light purple', 'yellow', 'white']
for path in paths:
# print('PATH', path)
file = path.open('r')
j = json.load(file)
w = WayPoint(**j)
name = w.name
if len(name) > 32: # max name length is 32
name = name[:32]
name = name.strip().replace(':', '_').replace('-', '_') # There are ways of escaping this stuff using the weird dollar sign thing but I don't care to learn how
initial = name[0].upper()
wp_type = 'gui.xaero_default'
rotate_on_tp = False # no equivalent
tp_yaw = 0 # IDK, no equivalent
global_bool = False # Most of them seem to be set to False on my tests of Xaero's output
color = random.choice(xaero_colors) # Color is random on all because I didn't want to bother converting to xaero's weird nonstandard colorspace
color_index = xaero_colors.index(color)
is_set = False # Not sure what this means, but it's always 0 when I look at output
# Example: waypoint:ffff:F:828:25:-492:13:false:0:gui.xaero_default:false:0:false
# #waypoint:name:initials:x:y:z:color:disabled:type:set:rotate_on_tp:tp_yaw:global
xaero_fmt = f'waypoint:{name}:{initial}:{w.x}:{w.y}:{w.z}:{color_index}:{lb2s(not w.enable)}:{wp_type}:{lb2s(is_set)}:{lb2s(rotate_on_tp)}:{tp_yaw}:{lb2s(global_bool)}'
print(xaero_fmt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment