#!/usr/bin/env python3 """Publish the extracted starting-room terrain as a glyph bank and scene bank.""" import hashlib import json import shutil from extract_graphics import ROOT from extract_start_room import RGB, extract, write_json from sync_start_stage import sync TILES_UUID = "54de385e-42b8-40be-8337-cf9b93950ae4" SCENE_UUID = "c4bb08fb-07aa-4cd6-a001-0ac93f4e32ea" def prepare(): data = extract() registry_path = ROOT / "assets/.prometeu/index.json" registry = json.loads(registry_path.read_text()) def register(relative_root, uuid): matches = [a for a in registry["assets"] if a["root"] == relative_root or a["asset_uuid"] == uuid] if matches: if len(matches) != 1 or matches[0]["root"] != relative_root or matches[0]["asset_uuid"] != uuid: raise ValueError("Asset registry identity collision") matches[0]["included_in_build"] = True return matches[0]["asset_id"] asset_id = registry["next_asset_id"] registry["assets"].append({"asset_id": asset_id, "asset_uuid": uuid, "root": relative_root, "included_in_build": True}) registry["next_asset_id"] += 1 return asset_id tiles_id = register("tilesets/overworld", TILES_UUID) register("scenes/overworld_start", SCENE_UUID) # Preserve the empty test bank for reference, but only preload the real room. for asset in registry["assets"]: if asset["asset_uuid"] == "43b397da-4416-488e-85b1-d3bad43abbc0": asset["included_in_build"] = False bank = ROOT / "assets/tilesets/overworld" scene = ROOT / "assets/scenes/overworld_start" bank.mkdir(parents=True, exist_ok=True) scene.mkdir(parents=True, exist_ok=True) artifacts = [] glyphs = {} # The initial room's outer and inner palette are both NES background row 2. # Keep this explicit rather than silently baking other room palettes. if {t["palette_id"] for t in data["used_tiles"]} != {2}: raise ValueError("Starting-room palette assumption no longer holds") for tile in data["used_tiles"]: path = bank / tile["file"] shutil.copyfile(ROOT / "extracted/overworld/start/tiles" / tile["file"], path) index = len(artifacts) glyphs[(tile["tile_id"], tile["palette_id"])] = index artifacts.append({"file": path.name, "index": index, "artifact_id": f"ow-tile-{tile['tile_id']:02x}-p{tile['palette_id']}", "fingerprint": hashlib.sha256(path.read_bytes()).hexdigest()}) palette = [int.from_bytes(bytes((*RGB[code], 255)), "big", signed=True) for code in data["background_nes_palettes"][2]] write_json(bank / "asset.json", { "schema_version": 1, "asset_uuid": TILES_UUID, "name": "Overworld NES terrain", "type": "glyph_bank", "output": {"format": "GLYPH/indexed_v1", "codec": "NONE", "pipeline": {"palettes": [{"index": 0, "palette": {"rgba8888": palette}}]}, "metadata": {"tile_size": "8x8"}}, "preload": {"enabled": True}, "artifacts": artifacts}) write_json(bank / "studio.asset.json", {"schema_version": 1, "glyph_bank_specialization": "tileset"}) write_json(scene / "asset.json", { "schema_version": 1, "asset_uuid": SCENE_UUID, "name": "Overworld starting room 77", "type": "scene_bank", "output": {"format": "SCENE/tilemap_v1", "codec": "NONE", "pipeline": {}}, "preload": {"enabled": True}}) tiles = [] for y in range(30): for x in range(32): active = y >= 8 glyph = glyphs[(data["tilemap"][y][x], data["palette_map"][y][x])] if active else 0 tiles.append({"active": active, "glyph_id": glyph, "palette_id": 0, "flip_x": False, "flip_y": False}) def layer(active, width, height, values): return {"active": active, "glyph_asset_id": tiles_id, "tile_size": 8, "parallax_factor_x": 1.0, "parallax_factor_y": 1.0, "width": width, "height": height, "tiles": values} empty = {"active": False, "glyph_id": 0, "palette_id": 0, "flip_x": False, "flip_y": False} layers = [layer(True, 32, 30, tiles)] + [layer(False, 1, 1, [empty]) for _ in range(3)] write_json(scene / "scene-bank.pack-request.json", { "schema_version": 1, "format": "SCENE/tilemap_v1", "version": 1, "layers": layers}) write_json(registry_path, registry) sync() print(f"Registered {len(artifacts)} terrain glyphs and starting-room scene; glyph asset {tiles_id}") if __name__ == "__main__": prepare()