formatting, and fix output
This commit is contained in:
5
CLI.py
5
CLI.py
@@ -17,6 +17,7 @@ class ArgumentDefaultsHelpFormatter(argparse.RawTextHelpFormatter):
|
||||
def _get_help_string(self, action):
|
||||
return textwrap.dedent(action.help)
|
||||
|
||||
|
||||
def parse_cli(argv, no_defaults=False):
|
||||
def defval(value):
|
||||
return value if not no_defaults else None
|
||||
@@ -282,8 +283,10 @@ def parse_settings():
|
||||
|
||||
# Priority fallback is:
|
||||
# 1: CLI
|
||||
# 2: Settings file
|
||||
# 2: Settings file(s)
|
||||
# 3: Canned defaults
|
||||
|
||||
|
||||
def get_args_priority(settings_args, gui_args, cli_args):
|
||||
args = {}
|
||||
args["settings"] = parse_settings() if settings_args is None else settings_args
|
||||
|
||||
46
Utils.py
46
Utils.py
@@ -6,20 +6,25 @@ import sys
|
||||
import xml.etree.ElementTree as ET
|
||||
from collections import defaultdict
|
||||
|
||||
|
||||
def int16_as_bytes(value):
|
||||
value = value & 0xFFFF
|
||||
return [value & 0xFF, (value >> 8) & 0xFF]
|
||||
|
||||
|
||||
def int32_as_bytes(value):
|
||||
value = value & 0xFFFFFFFF
|
||||
return [value & 0xFF, (value >> 8) & 0xFF, (value >> 16) & 0xFF, (value >> 24) & 0xFF]
|
||||
|
||||
|
||||
def pc_to_snes(value):
|
||||
return ((value << 1) & 0x7F0000) | (value & 0x7FFF) | 0x8000
|
||||
|
||||
|
||||
def snes_to_pc(value):
|
||||
return ((value & 0x7F0000) >> 1) | (value & 0x7FFF)
|
||||
|
||||
|
||||
def parse_player_names(names, players, teams):
|
||||
names = [n for n in re.split(r'[, ]', names) if n]
|
||||
ret = []
|
||||
@@ -32,9 +37,11 @@ def parse_player_names(names, players, teams):
|
||||
names = names[players:]
|
||||
return ret
|
||||
|
||||
|
||||
def is_bundled():
|
||||
return getattr(sys, 'frozen', False)
|
||||
|
||||
|
||||
def local_path(path):
|
||||
# just do stuff here and bail
|
||||
return os.path.join(".", path)
|
||||
@@ -51,44 +58,19 @@ def local_path(path):
|
||||
|
||||
return os.path.join(local_path.cached_path, path)
|
||||
|
||||
|
||||
local_path.cached_path = None
|
||||
|
||||
|
||||
def output_path(path):
|
||||
# just do stuff here and bail
|
||||
return os.path.join(".", path)
|
||||
|
||||
if output_path.cached_path is not None:
|
||||
return os.path.join(output_path.cached_path, path)
|
||||
|
||||
if not is_bundled():
|
||||
if output_path.cached_path is None:
|
||||
output_path.cached_path = '.'
|
||||
return os.path.join(output_path.cached_path, path)
|
||||
else:
|
||||
# has been packaged, so cannot use CWD for output.
|
||||
if sys.platform == 'win32':
|
||||
#windows
|
||||
documents = os.path.join(os.path.expanduser("~"),"Documents")
|
||||
elif sys.platform == 'darwin':
|
||||
from AppKit import NSSearchPathForDirectoriesInDomains # pylint: disable=import-error
|
||||
# http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Functions/Reference/reference.html#//apple_ref/c/func/NSSearchPathForDirectoriesInDomains
|
||||
NSDocumentDirectory = 9
|
||||
NSUserDomainMask = 1
|
||||
# True for expanding the tilde into a fully qualified path
|
||||
documents = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, True)[0]
|
||||
elif sys.platform.find("linux") or sys.platform.find("ubuntu") or sys.platform.find("unix"):
|
||||
documents = os.path.join(os.path.expanduser("~"),"Documents")
|
||||
else:
|
||||
raise NotImplementedError('Not supported yet')
|
||||
|
||||
output_path.cached_path = os.path.join(documents, 'ALttPDoorRandomizer')
|
||||
if not os.path.exists(output_path.cached_path):
|
||||
os.makedirs(output_path.cached_path)
|
||||
if not os.path.join(output_path.cached_path, path):
|
||||
os.makedirs(os.path.join(output_path.cached_path, path))
|
||||
return os.path.join(output_path.cached_path, path)
|
||||
|
||||
output_path.cached_path = None
|
||||
|
||||
|
||||
def open_file(filename):
|
||||
if sys.platform == 'win32':
|
||||
os.startfile(filename)
|
||||
@@ -96,6 +78,7 @@ def open_file(filename):
|
||||
open_command = 'open' if sys.platform == 'darwin' else 'xdg-open'
|
||||
subprocess.call([open_command, filename])
|
||||
|
||||
|
||||
def close_console():
|
||||
if sys.platform == 'win32':
|
||||
# windows
|
||||
@@ -105,6 +88,7 @@ def close_console():
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def make_new_base2current(old_rom='Zelda no Densetsu - Kamigami no Triforce (Japan).sfc', new_rom='working.sfc'):
|
||||
from collections import OrderedDict
|
||||
import json
|
||||
@@ -241,7 +225,6 @@ def room_palette_data(old_rom):
|
||||
print(f'{hex(header_offset)}: {[hex(x) for x in rooms]}')
|
||||
|
||||
|
||||
|
||||
# Palette notes:
|
||||
# HC: 0
|
||||
# Sewer/Dungeon: 1
|
||||
@@ -306,6 +289,7 @@ def print_wiki_doors_by_region(d_regions, world, player):
|
||||
with open(os.path.join(".", "resources", "user", "regions-" + d + ".txt"), "w+") as f:
|
||||
f.write(toprint)
|
||||
|
||||
|
||||
def update_deprecated_args(args):
|
||||
if args:
|
||||
argVars = vars(args)
|
||||
@@ -376,6 +360,7 @@ def update_deprecated_args(args):
|
||||
|
||||
return args
|
||||
|
||||
|
||||
def print_wiki_doors_by_room(d_regions, world, player):
|
||||
for d, region_list in d_regions.items():
|
||||
tile_map = {}
|
||||
@@ -415,6 +400,7 @@ def print_wiki_doors_by_room(d_regions, world, player):
|
||||
with open(os.path.join(".", "resources", "user", "rooms-" + d + ".txt"), "w+") as f:
|
||||
f.write(toprint)
|
||||
|
||||
|
||||
def print_xml_doors(d_regions, world, player):
|
||||
root = ET.Element('root')
|
||||
for d, region_list in d_regions.items():
|
||||
|
||||
Reference in New Issue
Block a user