67 lines
3.1 KiB
Python
67 lines
3.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Export proven laboratory HUD/PracticeYesNo Canv resources, without changing originals."""
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
|
|
from omt import Database, FormatError, read_canvas, validate_output, write_png
|
|
|
|
|
|
# Neutron.exe 402687..4026E8 registers pad and laboratory objective IDs;
|
|
# 40224F registers PracticeYesNo. These are original identities, not guessed art.
|
|
CANVASES = {120: (256, 29), 121: (256, 29), 122: (256, 29),
|
|
156: (320, 173), 169: (207, 100)}
|
|
ALPHA_CANVASES = {83: (8, 8), 84: (8, 8), 85: (8, 8)}
|
|
|
|
|
|
def export_ui(database: Database, output: Path, alpha: Database | None = None) -> dict:
|
|
validate_output(database, output)
|
|
if alpha is None:
|
|
# The original font database is beside omt/, not within screens.omt.
|
|
alpha = Database(database.path.parent.parent / 'alpha.omt')
|
|
validate_output(alpha, output)
|
|
recovered = []
|
|
for source, identities in ((database, CANVASES), (alpha, ALPHA_CANVASES)):
|
|
for identity, expected in identities.items():
|
|
entry = next((e for e in source.entries if e.type == 'Canv' and e.id == identity), None)
|
|
if entry is None:
|
|
raise FormatError(f'Missing original UI canvas {source.path.name}:{identity}')
|
|
canvas = read_canvas(source.payload(entry))
|
|
if (canvas['width'], canvas['height']) != expected:
|
|
raise FormatError(f'Unexpected original UI canvas dimensions {identity}')
|
|
recovered.append((source, entry, canvas))
|
|
output.mkdir(parents=True, exist_ok=True)
|
|
textures = []
|
|
for source, entry, canvas in recovered:
|
|
name = f'canvas_{entry.id}'
|
|
rgba = canvas['rgba']
|
|
(output / (name + '.rgba')).write_bytes(rgba)
|
|
write_png(output / (name + '.png'), canvas['width'], canvas['height'], rgba)
|
|
textures.append({'id': entry.id, 'name': entry.name, 'width': canvas['width'],
|
|
'height': canvas['height'], 'path': name + '.rgba',
|
|
'source': source.path.name, 'sourceOffset': entry.offset, 'sourceBytes': entry.size,
|
|
'rgbaSha256': hashlib.sha256(rgba).hexdigest()})
|
|
manifest = {'version': 1, 'source': database.path.name,
|
|
'sourceSha256': hashlib.sha256(database.data).hexdigest(),
|
|
'alphaSha256': hashlib.sha256(alpha.data).hexdigest(),
|
|
'referenceWidth': 640, 'referenceHeight': 480, 'textures': textures}
|
|
(output / 'ui.json').write_text(json.dumps(manifest, indent=2) + '\n', encoding='utf-8')
|
|
return manifest
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('database', type=Path)
|
|
parser.add_argument('--output', type=Path, required=True)
|
|
parser.add_argument('--alpha', type=Path, help='Original alpha.omt (default: beside the omt directory)')
|
|
args = parser.parse_args()
|
|
result = export_ui(Database(args.database), args.output, Database(args.alpha) if args.alpha else None)
|
|
print(f"{len(result['textures'])} original UI canvases exported to {args.output}")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|