Changing yaml output to show hex numbers as hex and not as decimal
This commit is contained in:
7
Utils.py
7
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])
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user