finishing with Phase 2
This commit is contained in:
@@ -4,7 +4,7 @@ from library.vanilla_textures import refresh_vanilla_index
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Rebuild the vanilla entity-texture index (media/vanilla/entity_index.json).'
|
||||
help = 'Rebuild the vanilla entity-texture index (static/vanilla/entity_index.json).'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
index = refresh_vanilla_index()
|
||||
|
||||
@@ -15,7 +15,6 @@ urlpatterns = [
|
||||
path('packs/<slug:slug>/versions/<int:version_id>/download/', views.version_download, name='version_download'),
|
||||
path('packs/<slug:slug>/versions/<int:version_id>/files/<uuid:file_uuid>/download/', views.version_file_download, name='version_file_download'),
|
||||
path('packs/<slug:slug>/versions/<int:version_id>/asset/<path:asset_path>', views.pack_asset, name='pack_asset'),
|
||||
path('vanilla/<path:asset_path>', views.vanilla_asset, name='vanilla_asset'),
|
||||
path('packs/<slug:slug>/guide/<int:version_id>/<uuid:file_uuid>/', views.guide_doc, name='guide_doc'),
|
||||
path('packs/<slug:slug>/gallery/upload/', views.asset_upload, name='asset_upload'),
|
||||
path('packs/<slug:slug>/gallery/<int:asset_id>/thumb/', views.asset_thumbnail, name='asset_thumbnail'),
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -423,19 +423,6 @@ def api_packs_latest(request, namespace, pack_id):
|
||||
})
|
||||
|
||||
|
||||
def vanilla_asset(request, asset_path):
|
||||
"""Serve a bundled Minecraft vanilla resource (e.g. entity textures) — gated."""
|
||||
if not asset_path or asset_path.startswith('/') or '..' in asset_path.split('/'):
|
||||
raise Http404
|
||||
full = Path(settings.MEDIA_ROOT) / 'vanilla' / asset_path
|
||||
if not full.is_file():
|
||||
raise Http404
|
||||
content_type = mimetypes.guess_type(asset_path)[0] or 'application/octet-stream'
|
||||
response = HttpResponse(full.read_bytes(), content_type=content_type)
|
||||
response['Cache-Control'] = 'public, max-age=86400'
|
||||
return response
|
||||
|
||||
|
||||
def guide_doc(request, slug, version_id, file_uuid):
|
||||
"""Render one markdown guide document server-side (used by the switcher)."""
|
||||
version = get_object_or_404(
|
||||
|
||||
Reference in New Issue
Block a user