69 lines
3.3 KiB
Python
69 lines
3.3 KiB
Python
"""Add only the Golden Path artwork to an existing quest-arcs pack or menu art cache."""
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
import struct
|
|
|
|
from plugin_wild_update import digest, read_archive, write_archive
|
|
|
|
ASSETS = "assets/dunerealms/"
|
|
ART = "network/resource-pack/golden-path/overlay"
|
|
CATALOG = "JarvisConnector/src/main/resources/leto-item-templates.json"
|
|
BASELINE = "7cb77c3c6dad3d2c0bc3d70d955662abc7840931f2d3ab61c583f7edd0da456e"
|
|
|
|
|
|
def artwork(source):
|
|
overlay = source / ART
|
|
rows = json.loads((source / CATALOG).read_text(encoding="utf-8"))["items"]
|
|
reward_ids = {row["id"] for row in rows}
|
|
if len(rows) != 8 or len(reward_ids) != 8 or not all(item.startswith("leto/") for item in reward_ids):
|
|
raise ValueError("Expected the eight unique Golden Path reward items")
|
|
payload = {}
|
|
for model_key in sorted(reward_ids | {"quests/golden-path"}):
|
|
definition = f"{ASSETS}items/{model_key}.json"
|
|
model = f"{ASSETS}models/item/{model_key}.json"
|
|
texture = f"{ASSETS}textures/item/{model_key}.png"
|
|
definition_bytes = (overlay / definition).read_bytes()
|
|
model_bytes = (overlay / model).read_bytes()
|
|
texture_bytes = (overlay / texture).read_bytes()
|
|
if json.loads(definition_bytes)["model"] != {"type": "minecraft:model", "model": f"dunerealms:item/{model_key}"}:
|
|
raise ValueError(f"Incorrect item model for {model_key}")
|
|
if json.loads(model_bytes)["textures"] != {"layer0": f"dunerealms:item/{model_key}"}:
|
|
raise ValueError(f"Incorrect texture binding for {model_key}")
|
|
if texture_bytes[:16] != b"\x89PNG\r\n\x1a\n\x00\x00\x00\x0dIHDR" or struct.unpack(
|
|
">II", texture_bytes[16:24]
|
|
) != (32, 32):
|
|
raise ValueError(f"Expected a 32px item texture for {model_key}")
|
|
payload.update({definition: definition_bytes, model: model_bytes, texture: texture_bytes})
|
|
existing = {file.relative_to(overlay).as_posix() for file in overlay.rglob("*") if file.is_file()}
|
|
if existing != set(payload):
|
|
raise ValueError("Unexpected Golden Path artwork entries")
|
|
return payload
|
|
|
|
|
|
def assemble(source, baseline, output, baseline_sha, menu):
|
|
previous = baseline.read_bytes()
|
|
if digest(previous) != baseline_sha or not menu and baseline_sha != BASELINE:
|
|
raise ValueError("Unexpected pinned story pack or menu archive")
|
|
base = read_archive(previous)
|
|
assets = artwork(source)
|
|
if menu:
|
|
if "com/dunerealms/menus/MenuArt.class" not in base:
|
|
raise ValueError("DuneMenus artwork cache required")
|
|
assets = {"menu-art/pack/" + path: content for path, content in assets.items()}
|
|
if set(assets) & set(base):
|
|
raise ValueError("Golden Path must add new assets without replacing existing artwork")
|
|
base.update(assets)
|
|
with output.open("xb") as candidate:
|
|
candidate.write(write_archive(base))
|
|
print(f"{len(assets)} artwork entries added, SHA-256 {digest(output.read_bytes())}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("source", type=Path)
|
|
parser.add_argument("baseline", type=Path)
|
|
parser.add_argument("output", type=Path)
|
|
parser.add_argument("baseline_sha")
|
|
parser.add_argument("--menu", action="store_true")
|
|
assemble(**vars(parser.parse_args()))
|

Staff