From b507dfda71ac6300ea5f3d94ecac8ec3d6d8b6b7 Mon Sep 17 00:00:00 2001 From: Jennifer Taylor Date: Fri, 6 Nov 2020 19:57:13 +0000 Subject: [PATCH] Ignore XML mappings by default. --- bemani/utils/afputils.py | 67 +++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/bemani/utils/afputils.py b/bemani/utils/afputils.py index dd96522..c5def58 100644 --- a/bemani/utils/afputils.py +++ b/bemani/utils/afputils.py @@ -112,6 +112,7 @@ def extract( write: bool = True, verbose: bool = False, raw: bool = False, + xml: bool = False, ) -> None: with open(filename, "rb") as fp: data = fp.read() @@ -307,15 +308,16 @@ def extract( if not img or raw: with open(f"{filename}.raw", "wb") as bfp: bfp.write(raw_data) - with open(f"{filename}.xml", "w") as sfp: - sfp.write(textwrap.dedent(f""" - - {width} - {height} - {hex(fmt)} - {filename}.raw - - """).strip()) + if xml: + with open(f"{filename}.xml", "w") as sfp: + sfp.write(textwrap.dedent(f""" + + {width} + {height} + {hex(fmt)} + {filename}.raw + + """).strip()) vprint(f"Bit 0x000001 - count: {length}, offset: {hex(offset)}") for name in names: @@ -402,19 +404,21 @@ def extract( # Actually place the file down. os.makedirs(path, exist_ok=True) - print(f"Writing {filename}.xml graphic information...") - with open(f"{filename}.xml", "w") as sfp: - sfp.write(textwrap.dedent(f""" - - {region[1][0]} - {region[1][1]} - {region[2][0]} - {region[2][1]} - {texture} - - """).strip()) + if xml: + print(f"Writing {filename}.xml graphic information...") + with open(f"{filename}.xml", "w") as sfp: + sfp.write(textwrap.dedent(f""" + + {region[1][0]} + {region[1][1]} + {region[2][0]} + {region[2][1]} + {texture} + + """).strip()) else: - print(f"Would write {filename}.xml graphic information...") + if xml: + print(f"Would write {filename}.xml graphic information...") vprint(f" {i}: {name}") else: @@ -631,13 +635,14 @@ def extract( if fontdata is not None: filename = os.path.join(path, "fontinfo.xml") - if write: - os.makedirs(path, exist_ok=True) - print(f"Writing {filename} font information...") - with open(filename, "w") as sfp: - sfp.write(str(fontdata)) - else: - print(f"Would write {filename} font information...") + if xml: + if write: + os.makedirs(path, exist_ok=True) + print(f"Writing {filename} font information...") + with open(filename, "w") as sfp: + sfp.write(str(fontdata)) + else: + print(f"Would write {filename} font information...") else: vprint("Bit 0x010000 - NOT PRESENT") @@ -730,6 +735,11 @@ def main() -> int: action="store_true", help="Always write raw texture files.", ) + parser.add_argument( + "--write-mappings", + action="store_true", + help="Write mapping files to disk.", + ) args = parser.parse_args() extract( @@ -738,6 +748,7 @@ def main() -> int: write=not args.pretend, verbose=args.verbose, raw=args.write_raw, + xml=args.write_mappings, ) return 0