forked from unimatrix/web
38 lines
2 KiB
Python
38 lines
2 KiB
Python
"""Add only the original quest-character skins to the exact published fauna packs."""
|
|
import argparse
|
|
import importlib.util
|
|
import json
|
|
import pathlib
|
|
import struct
|
|
|
|
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)
|
|
OLD = json.loads((ROOT / 'DuneRealmsGUI/fauna-pack/manifest.json').read_text())
|
|
SKINS = ROOT / 'DuneRealmsGUI/npc-skins'
|
|
|
|
def build(inputs, output):
|
|
output.mkdir(parents=True, exist_ok=True)
|
|
files = sorted(SKINS.glob('*.png'))
|
|
if len(files) != 18:
|
|
raise ValueError('Expected all 18 original character skins')
|
|
changes = {}
|
|
for skin in files:
|
|
data = skin.read_bytes()
|
|
if data[:8] != b'\x89PNG\r\n\x1a\n' or struct.unpack('>II', data[16:24]) != (64,64):
|
|
raise ValueError('Invalid classic skin UV texture: ' + skin.name)
|
|
changes['assets/dunerealms/textures/entity/npc/' + skin.name] = data
|
|
result = {'resourcePackVersion': OLD['resourcePackVersion'], 'baseId': OLD['baseId'], 'base': {}}
|
|
for scope, old in OLD['base'].items():
|
|
entries = repair.read_pack(inputs / old['filename'], old['sha256'])
|
|
if set(changes) & set(entries):
|
|
raise ValueError('NPC skin addition would overwrite existing artwork')
|
|
entries.update(changes)
|
|
filename = 'DuneRealms-Network-Artwork-' + ('Lobby-' if scope == 'lobby' else '') + 'v6.zip'
|
|
result['base'][scope] = {**repair.write_pack(output, filename, entries), 'previous': {k: old[k] for k in ('url','sha1','sha256')}}
|
|
(output / 'manifest.json').write_text(json.dumps(result, indent=2) + '\n', encoding='utf-8', newline='\n')
|
|
return result
|
|
|
|
if __name__ == '__main__':
|
|
p=argparse.ArgumentParser(description=__doc__);p.add_argument('inputs',type=pathlib.Path);p.add_argument('output',type=pathlib.Path);a=p.parse_args();print(json.dumps(build(a.inputs,a.output),indent=2))
|

Staff