finishing with Phase 2
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
"""Build the vanilla entity-texture index for the model viewer.
|
||||
|
||||
Scans ``MEDIA_ROOT/vanilla/entity/`` (extracted from a Minecraft client jar)
|
||||
and writes ``MEDIA_ROOT/vanilla/entity_index.json`` mapping each entity name to
|
||||
the best "base skin" relative path, so the renderer can fall back to real
|
||||
vanilla textures for models that have no pack textures of their own.
|
||||
Scans ``static/vanilla/entity/`` (extracted from a Minecraft client jar,
|
||||
tracked in git) and writes ``static/vanilla/entity_index.json`` mapping each
|
||||
entity name to the best "base skin" relative path, so the renderer can fall
|
||||
back to real vanilla textures for models that have no pack textures of their
|
||||
own.
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
@@ -13,6 +14,11 @@ from django.conf import settings
|
||||
ENTITY_ROOT = 'entity'
|
||||
INDEX_NAME = 'entity_index.json'
|
||||
|
||||
|
||||
def vanilla_dir():
|
||||
"""The tracked static directory holding the vanilla texture set."""
|
||||
return os.path.join(settings.BASE_DIR, 'static', 'vanilla')
|
||||
|
||||
# Entity names whose vanilla layout differs from the model-name convention.
|
||||
ALIASES = {
|
||||
'polar_bear': 'bear/polarbear.png',
|
||||
@@ -75,7 +81,7 @@ def _base_candidates(entity):
|
||||
"""Return (entity, [candidate relative paths]) in priority order."""
|
||||
if entity in ALIASES:
|
||||
return entity, [ALIASES[entity]]
|
||||
root = os.path.join(settings.MEDIA_ROOT, 'vanilla', ENTITY_ROOT)
|
||||
root = os.path.join(vanilla_dir(), ENTITY_ROOT)
|
||||
top = os.path.join(root, entity + '.png')
|
||||
if os.path.isfile(top):
|
||||
return entity, [entity + '.png']
|
||||
@@ -98,7 +104,7 @@ def _base_candidates(entity):
|
||||
|
||||
def refresh_vanilla_index():
|
||||
"""Rebuild the entity → {default, variants} skin map from the vanilla set."""
|
||||
root = os.path.join(settings.MEDIA_ROOT, 'vanilla', ENTITY_ROOT)
|
||||
root = os.path.join(vanilla_dir(), ENTITY_ROOT)
|
||||
if not os.path.isdir(root):
|
||||
raise FileNotFoundError(f'{root} missing — extract vanilla entity textures first')
|
||||
|
||||
@@ -125,7 +131,7 @@ def refresh_vanilla_index():
|
||||
index[entity]['default'] = variants[0]
|
||||
index[entity]['variants'] = variants
|
||||
|
||||
out = os.path.join(settings.MEDIA_ROOT, 'vanilla', INDEX_NAME)
|
||||
out = os.path.join(vanilla_dir(), INDEX_NAME)
|
||||
with open(out, 'w') as f:
|
||||
json.dump(index, f, indent=1, sort_keys=True)
|
||||
return index
|
||||
|
||||
Reference in New Issue
Block a user