web/tools/build-shared-network-pack.py

19 lines
1.8 KiB
Python

"""Split the former Guild-only artwork differences out of the network pack without losing bytes."""
import argparse, hashlib, importlib.util, json, pathlib
ROOT=pathlib.Path(__file__).resolve().parents[1]
spec=importlib.util.spec_from_file_location('repair', ROOT/'tools/build-resourcepack-repair.py'); repair=importlib.util.module_from_spec(spec); spec.loader.exec_module(repair)
def build(world, lobby, guild, output):
def read(path,sha):
assert hashlib.sha1(path.read_bytes()).hexdigest()==sha, path
return repair.read_pack(path,hashlib.sha256(path.read_bytes()).hexdigest())
shared=read(world,'f86189d72abc0690a08e01b7707998fabd961b8d'); old_lobby=read(lobby,'dfa8b458f306f61ecae490d5503924a63cea9a75'); old_guild=read(guild,'2e37e41aaeb80f6eac97fb40dc08572708d2644f')
assert set(shared)<=set(old_lobby) and all(shared[k]==old_lobby[k] for k in shared if k!='pack.mcmeta')
extras={k:v for k,v in old_lobby.items() if k not in shared}
assert all(k.startswith('assets/minecraft/textures/') for k in extras)
assert all(old_guild[k]==v for k,v in extras.items() if k in old_guild)
output.mkdir(parents=True,exist_ok=True)
record=repair.write_pack(output,'DuneRealms-Materials-guild-v4.zip',{**old_guild,**extras})
manifest={'common':{'url':'https://www.dunerealms.com/downloads/'+world.name,'sha1':hashlib.sha1(world.read_bytes()).hexdigest()},'guild':record,'preservedLobbyEntries':len(extras),'addedToGuild':len(set(extras)-set(old_guild))}
(output/'manifest.json').write_text(json.dumps(manifest,indent=2)+'\n'); return manifest
if __name__=='__main__':
p=argparse.ArgumentParser(); [p.add_argument(n,type=pathlib.Path) for n in ('world','lobby','guild','output')]; a=p.parse_args(); print(json.dumps(build(a.world,a.lobby,a.guild,a.output),indent=2))