From 1566813f81a51743df987b762c4bcc6352d0ccb2 Mon Sep 17 00:00:00 2001 From: codemann8 Date: Wed, 2 Aug 2023 15:01:37 -0500 Subject: [PATCH] Changing yaml output to show hex numbers as hex and not as decimal --- Utils.py | 7 +++++++ source/classes/CustomSettings.py | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Utils.py b/Utils.py index a208efe1..1a2a1c1c 100644 --- a/Utils.py +++ b/Utils.py @@ -737,6 +737,13 @@ class bidict(dict): super(bidict, self).__delitem__(key) +class HexInt(int): pass + +def hex_representer(dumper, data): + import yaml + return yaml.ScalarNode('tag:yaml.org,2002:int', f"{data:#0{4}x}") + + if __name__ == '__main__': # make_new_base2current() # read_entrance_data(old_rom=sys.argv[1]) diff --git a/source/classes/CustomSettings.py b/source/classes/CustomSettings.py index 99972d7f..7dc86366 100644 --- a/source/classes/CustomSettings.py +++ b/source/classes/CustomSettings.py @@ -4,6 +4,7 @@ import urllib.parse import yaml from typing import Any from yaml.representer import Representer +from Utils import HexInt, hex_representer from collections import defaultdict from pathlib import Path @@ -350,7 +351,7 @@ class CustomSettings(object): for p in self.player_range: if p in world.owswaps and len(world.owswaps[p][0]) > 0: flips[p] = {} - flips[p]['force_flip'] = list(f for f in world.owswaps[p][0] if f < 0x40 or f >= 0x80) + flips[p]['force_flip'] = list(HexInt(f) for f in world.owswaps[p][0] if f < 0x40 or f >= 0x80) flips[p]['force_flip'].sort() flips[p]['undefined_chance'] = 0 @@ -416,6 +417,7 @@ class CustomSettings(object): def write_to_file(self, destination): yaml.add_representer(defaultdict, Representer.represent_dict) + yaml.add_representer(HexInt, hex_representer) with open(destination, 'w') as file: yaml.dump(self.world_rep, file)