Implement original gadget panel and playable shrink ray
This commit is contained in:
1 parent
0272f7bef7
commit
7b5230ceb8
57 files changed
+3545
-48
No files matched your search
@@ -0,0 +1,112 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Export original gadget-screen canvases; resource identity is not gameplay policy."""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
from dataclasses import dataclass
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from omt import Database, FormatError, read_canvas, validate_output, write_png
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class CanvasSpec:
|
||||
id: int
|
||||
name: str
|
||||
width: int
|
||||
height: int
|
||||
role: str
|
||||
|
||||
|
||||
TILE_LABELS = ('BUBBLE', 'ROCKETSHIP', 'INVISIBLE', 'SHRINK RAY',
|
||||
'SCOOTER', 'REMOTE', 'BASEBALL', 'GRAPPLER')
|
||||
TILE_IDS = tuple(range(11, 19))
|
||||
TILE_B_IDS = (52, 46, 47, 48, 49, 50, 51, 45)
|
||||
TILE_C_IDS = (178, 171, 172, 173, 174, 175, 176, 177)
|
||||
|
||||
|
||||
def specifications() -> tuple[CanvasSpec, ...]:
|
||||
specs = [CanvasSpec(20, 'menu', 640, 480, 'background')]
|
||||
for index, (plain, alternate_b, alternate_c) in enumerate(zip(TILE_IDS, TILE_B_IDS, TILE_C_IDS), 1):
|
||||
for identity, suffix in ((plain, ''), (alternate_b, 'b'), (alternate_c, 'c')):
|
||||
specs.append(CanvasSpec(identity, f'item{index:02d}{suffix}', 141, 141, f'tile{suffix}'))
|
||||
for identity, name in ((109, 'Bubble'), (110, 'Grappler'), (111, 'Invisible'),
|
||||
(112, 'JetPack'), (113, 'RayGun'), (114, 'Remote'),
|
||||
(115, 'Rocketship'), (116, 'Scooter'), (118, 'Baseball')):
|
||||
specs.append(CanvasSpec(identity, 'BmenuL'+name, 393, 69, 'controls-left'))
|
||||
for identity, name in ((108, 'BmenuR2'), (117, 'BmenuR1')):
|
||||
specs.append(CanvasSpec(identity, name, 247, 69, 'controls-right'))
|
||||
for identity, name in ((24, 'return'), (181, 'return2'), (182, 'return3'),
|
||||
(170, 'practice'), (179, 'practice2'), (180, 'practice3')):
|
||||
specs.append(CanvasSpec(identity, name, 141, 78, 'button'))
|
||||
for identity, name in ((94, '1bubble'), (87, '2rocket'), (88, '3invisible'),
|
||||
(89, '4raygun'), (90, '5scooter'), (91, '6remote'),
|
||||
(92, '7baseball'), (93, '8grappler'), (119, '9jetpack')):
|
||||
specs.append(CanvasSpec(identity, name, 80, 70, 'hud'))
|
||||
for identity, name in ((84, 'backpack'), (85, 'backpack2')):
|
||||
specs.append(CanvasSpec(identity, name, 141, 141, 'backpack'))
|
||||
specs.append(CanvasSpec(253, 'CrossHairs', 15, 210, 'crosshairs-strip'))
|
||||
return tuple(specs)
|
||||
|
||||
|
||||
CANVASES = specifications()
|
||||
|
||||
|
||||
def export_gadget_resources(database: Database, output: Path) -> dict:
|
||||
"""Copy exact decoded pixels and metadata to a separate generated directory.
|
||||
|
||||
Tile roles preserve original resource suffixes. Which suffix means selected,
|
||||
hovered, unavailable or enabled must come from the original dispatcher.
|
||||
"""
|
||||
validate_output(database, output)
|
||||
# Supplied archives live beneath Original/omt. Protect that entire source
|
||||
# tree, including sibling ASE/png/gam directories, rather than only omt/.
|
||||
source_directory = database.path.parent.resolve()
|
||||
source_root = source_directory.parent if source_directory.name.casefold() == 'omt' else source_directory
|
||||
if output.resolve().is_relative_to(source_root):
|
||||
raise ValueError('Gadget output must be separate from the source asset tree')
|
||||
entries = {entry.id: entry for entry in database.entries if entry.type == 'Canv'}
|
||||
recovered = []
|
||||
for spec in CANVASES:
|
||||
entry = entries.get(spec.id)
|
||||
if entry is None or entry.name != spec.name:
|
||||
raise FormatError(f'Missing or changed gadget canvas {spec.id}:{spec.name}')
|
||||
canvas = read_canvas(database.payload(entry))
|
||||
if (canvas['width'], canvas['height']) != (spec.width, spec.height):
|
||||
raise FormatError(f'Unexpected gadget canvas dimensions {spec.id}')
|
||||
recovered.append((spec, entry, canvas))
|
||||
output.mkdir(parents=True, exist_ok=True)
|
||||
textures = []
|
||||
for spec, entry, canvas in recovered:
|
||||
name = f'canvas_{spec.id}'
|
||||
rgba = canvas['rgba']
|
||||
(output/(name+'.rgba')).write_bytes(rgba)
|
||||
write_png(output/(name+'.png'), spec.width, spec.height, rgba)
|
||||
textures.append(dict(id=spec.id, name=entry.name, role=spec.role,
|
||||
width=spec.width, height=spec.height, path=name+'.rgba', png=name+'.png',
|
||||
sourceOffset=entry.offset, sourceBytes=entry.size,
|
||||
sourceSha256=hashlib.sha256(database.payload(entry)).hexdigest(),
|
||||
rgbaSha256=hashlib.sha256(rgba).hexdigest()))
|
||||
manifest = dict(schema=1, source=database.path.name,
|
||||
sourceSha256=hashlib.sha256(database.data).hexdigest(),
|
||||
referenceWidth=640, referenceHeight=480, textures=textures,
|
||||
tiles=[dict(artItem=index+1, label=TILE_LABELS[index], canvas=plain,
|
||||
alternateB=alternate_b, alternateC=alternate_c)
|
||||
for index, (plain, alternate_b, alternate_c) in enumerate(zip(TILE_IDS, TILE_B_IDS, TILE_C_IDS))])
|
||||
(output/'gadgets.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)
|
||||
args = parser.parse_args()
|
||||
manifest = export_gadget_resources(Database(args.database), args.output)
|
||||
print(f"{len(manifest['textures'])} original gadget canvases exported to {args.output}")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -10,6 +10,7 @@ from png import read_png
|
||||
from entities import prepare_entities
|
||||
from models import prepare_models
|
||||
from ui import export_ui
|
||||
from gadget_resources import export_gadget_resources
|
||||
from sound_bank import export_sound_bank
|
||||
|
||||
|
||||
@@ -48,7 +49,7 @@ def main():
|
||||
parser.add_argument('--scenes', nargs='+', default=['level1b', 'VR01'])
|
||||
parser.add_argument('--all-scenes', action='store_true', help='Prepare every supplied GAM/OMT scene pair')
|
||||
parser.add_argument('--audio', nargs='*', default=['sounds', 'musicjimmyshouse', 'musicneighborhood'])
|
||||
parser.add_argument('--animations', nargs='*', default=['jimstop', 'jimrun', 'jimjump', 'jimscratch', 'jimbackpedal', 'jimfall', 'jimtalk', 'jimfly'])
|
||||
parser.add_argument('--animations', nargs='*', default=['jimstop', 'jimrun', 'jimjump', 'jimscratch', 'jimbackpedal', 'jimfall', 'jimtalk', 'jimfly', 'jimshoot'])
|
||||
args = parser.parse_args()
|
||||
if args.output.resolve().is_relative_to(args.original.resolve()):
|
||||
parser.error('Output must be outside the original installation')
|
||||
@@ -78,6 +79,7 @@ def main():
|
||||
catalog['prepared'].append({'level': name+'.gam', 'archive': source.name, 'scene': source.stem+'/scene.json'})
|
||||
(args.output/'scene-catalog.json').write_text(json.dumps(catalog, indent=2)+'\n')
|
||||
export_ui(Database(find_archive(args.original, 'screens')), args.output / 'ui', Database(args.original / 'alpha.omt'))
|
||||
export_gadget_resources(Database(find_archive(args.original, 'screens')), args.output / 'gadgets')
|
||||
effects = export_sound_bank(args.original, args.output / 'effects')
|
||||
print(f"SoundEffects.omt: {len(effects['resources'])} original sound identities")
|
||||
for name in args.audio:
|
||||
@@ -109,6 +111,10 @@ def main():
|
||||
prepare_actor(args.original, args.output, 'trophy', 'trophy.png', {'STOP': 'trophy'})
|
||||
# C3DJetpackFire421F30..96: DEFAULT fire.ase, HINONE fire2.ase, fire.png.
|
||||
prepare_actor(args.original, args.output, 'jetpack', 'fire.png', {'DEFAULT': 'fire', 'NONE': 'fire2'}, 'fire')
|
||||
#Recovered C3DShrinkRay440000 and3SOL44C0B0 bindings; see docs/gameplay/.
|
||||
prepare_actor(args.original, args.output, 'shrink-ray', 'ray0000.png', {'RAY': 'ray'})
|
||||
prepare_actor(args.original, args.output, 'soldier', 'yoksold.png', {'WALK': 'soldwalk', 'SHRINK': 'soldshrink'}, 'soldatak')
|
||||
prepare_actor(args.original, args.output, 'soldier-vr', 'vryoksoldier.png', {'WALK': 'soldwalk', 'SHRINK': 'soldshrink'}, 'soldatak')
|
||||
|
||||
|
||||
if __name__ == '__main__': main()
|
||||
Reference in new issue
Block a user