plugins/tools/quest_arc_artwork.py
unimatrixgit c35522facd
Some checks failed
DuneRealms Plugin CI / plugins (push) Failing after 10m24s
Quest Arc Presentation Overlay / quest-story-arcs (push) Successful in 1m20s
Package only quest journal classes and artwork for retained builds
2026-12-05 07:31:45 +01:00

104 lines
4.7 KiB
Python

"""Add the reviewed quest arc artwork to the retained network pack or DuneMenus artwork cache."""
import argparse
import json
from pathlib import Path
import struct
from plugin_wild_update import digest, read_archive, write_archive
NETWORK_SHA256 = "8a1bd9c2784be4231ffd2f29e9dbcb43a04eb69a5c14966077084a916769fd84"
ASSETS = "assets/dunerealms/"
CATALOG = "DuneRealmsGUI/src/main/resources/quest-categories.json"
OVERLAY = "network/resource-pack/central/overlay"
GUI_PREFIX = "com/dunerealms/gui/"
GUI_CHANGED = ("QuestMenus.class", "QuestMenus$JournalView.class")
GUI_ADDED = ("QuestCategories.class", "QuestCategories$Category.class", "QuestCategories$Group.class")
GUI_CATALOG = "quest-categories.json"
GUI_BASELINES = {
"e015af5c7f063b4ec2be51ce586376cf3a350be4dfa832032a027e8d9513b429",
"19157b96c1802ece522e0560020a93ec87ca78815c7a823406ac61650c999e5d",
}
MENU_BASELINES = {
"75bf2b32df6f516079c8ef53c49e58db7fc415e7306043073ca378988a7c4838",
"4f5a9f9c4ddb4f0c76e3d7565aa4ba58064b18ee6675ba9400f855a9329e81fd",
}
MENU_PREFIX = "menu-art/pack/"
def artwork(source):
catalog = json.loads((source / CATALOG).read_text(encoding="utf-8"))
ids = {category["id"] for category in catalog["categories"]} | {"other"}
if len(ids) != 14:
raise ValueError("Expected the thirteen story arcs and Other Work")
overlay = source / OVERLAY
paths = {}
for arc in sorted(ids):
model = f"{ASSETS}models/item/quests/{arc}.json"
definition = f"{ASSETS}items/quests/{arc}.json"
image = f"{ASSETS}textures/item/quests/{arc}.png"
definition_data = (overlay / definition).read_bytes()
model_data = (overlay / model).read_bytes()
image_data = (overlay / image).read_bytes()
if json.loads(definition_data)["model"] != {
"type": "minecraft:model",
"model": f"dunerealms:item/quests/{arc}",
}:
raise ValueError(f"Unexpected item definition for {arc}")
if json.loads(model_data)["textures"]["layer0"] != f"dunerealms:item/quests/{arc}":
raise ValueError(f"Unexpected texture reference for {arc}")
if image_data[:16] != b"\x89PNG\r\n\x1a\n\x00\x00\x00\x0dIHDR" or struct.unpack(
">II", image_data[16:24]
) != (32, 32):
raise ValueError(f"Expected a 32px PNG for {arc}")
paths.update({definition: definition_data, model: model_data, image: image_data})
return paths
def gui_entries():
return [*(GUI_PREFIX + name for name in (*GUI_CHANGED, *GUI_ADDED)), GUI_CATALOG]
def assemble(source, baseline, output, target, baseline_sha=None, donor=None, donor_sha=None):
existing = baseline.read_bytes()
accepted = {"network": {NETWORK_SHA256}, "menus": MENU_BASELINES, "gui": GUI_BASELINES}
actual = digest(existing)
if actual not in accepted[target] or baseline_sha is not None and actual != baseline_sha:
raise ValueError("Unexpected retained archive checksum")
base = read_archive(existing)
if target == "gui":
compiled = donor.read_bytes()
if digest(compiled) != donor_sha:
raise ValueError("Unexpected quest journal donor checksum")
payload = read_archive(compiled)
if set(payload) != set(gui_entries()) or payload[GUI_CATALOG] != (source / CATALOG).read_bytes():
raise ValueError("Unexpected quest journal donor entries")
expected_overlap = {GUI_PREFIX + name for name in GUI_CHANGED}
if set(payload) & set(base) != expected_overlap:
raise ValueError("Unexpected existing quest journal entries")
base.update(payload)
count = len(payload)
else:
added = artwork(source)
if target == "menus":
if "com/dunerealms/menus/MenuArt.class" not in base:
raise ValueError("Expected the retained DuneMenus artwork resolver")
added = {MENU_PREFIX + name: contents for name, contents in added.items()}
if set(added) & set(base):
raise ValueError("Quest artwork already exists in the retained archive")
base.update(added)
count = len(added)
with output.open("xb") as candidate:
candidate.write(write_archive(base))
print(f"{target}: applied {count} files, SHA256 {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("target", choices=("network", "menus", "gui"))
parser.add_argument("--baseline-sha")
parser.add_argument("--donor", type=Path)
parser.add_argument("--donor-sha")
assemble(**vars(parser.parse_args()))