298 lines
8.9 KiB
Python
298 lines
8.9 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Static Asset Gallery Generator
|
|
Generates self-contained HTML galleries for all game assets.
|
|
Works offline (file://) - just double-click to open!
|
|
"""
|
|
|
|
import os
|
|
import json
|
|
from pathlib import Path
|
|
from collections import defaultdict
|
|
|
|
# Categories with their detection patterns
|
|
CATEGORIES = {
|
|
"Ground & Terrain": ["ground", "grass", "dirt", "soil", "water", "teren"],
|
|
"Crops & Farming": ["crop", "wheat", "potato", "corn", "seed", "harvest", "pridelek"],
|
|
"Trees & Nature": ["tree", "apple", "cherry", "dead", "bush", "drevo", "narava"],
|
|
"Props & Objects": ["fence", "chest", "barrel", "scooter", "prop", "objekt"],
|
|
"Buildings": ["house", "barn", "building", "zgradba", "hisa"],
|
|
"Characters & NPCs": ["character", "npc", "kai", "ana", "gronk", "zombie", "lik"],
|
|
"Effects & VFX": ["blood", "fog", "rain", "vfx", "effect", "kri"],
|
|
"UI & Icons": ["icon", "ui", "button", "ikona"],
|
|
"Tools & Items": ["tool", "hoe", "axe", "pickaxe", "orodi", "item"],
|
|
"Other": []
|
|
}
|
|
|
|
def categorize_file(filepath):
|
|
"""Determine category based on file path and name."""
|
|
path_lower = str(filepath).lower()
|
|
filename_lower = filepath.name.lower()
|
|
|
|
for category, patterns in CATEGORIES.items():
|
|
if category == "Other":
|
|
continue
|
|
for pattern in patterns:
|
|
if pattern in path_lower or pattern in filename_lower:
|
|
return category
|
|
|
|
return "Other"
|
|
|
|
def scan_assets(base_dir="assets"):
|
|
"""Scan all PNG files and categorize them."""
|
|
categorized = defaultdict(list)
|
|
base_path = Path(base_dir)
|
|
|
|
for png_file in base_path.rglob("*.png"):
|
|
# Skip backup folders
|
|
if "BACKUP" in str(png_file):
|
|
continue
|
|
|
|
category = categorize_file(png_file)
|
|
relative_path = png_file.relative_to(Path.cwd())
|
|
|
|
categorized[category].append({
|
|
"path": str(relative_path),
|
|
"name": png_file.name,
|
|
"size": png_file.stat().st_size if png_file.exists() else 0
|
|
})
|
|
|
|
# Sort each category by name
|
|
for category in categorized:
|
|
categorized[category].sort(key=lambda x: x["name"])
|
|
|
|
return dict(categorized)
|
|
|
|
def generate_html(categorized_assets, output_file="asset_gallery.html"):
|
|
"""Generate self-contained HTML gallery."""
|
|
|
|
html = f"""<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Mrtva Dolina - Asset Gallery</title>
|
|
<style>
|
|
* {{
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}}
|
|
|
|
body {{
|
|
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
|
background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
|
|
color: #e0e0e0;
|
|
padding: 20px;
|
|
}}
|
|
|
|
.header {{
|
|
text-align: center;
|
|
padding: 40px 20px;
|
|
background: rgba(0,0,0,0.3);
|
|
border-radius: 10px;
|
|
margin-bottom: 30px;
|
|
}}
|
|
|
|
.header h1 {{
|
|
font-size: 3em;
|
|
color: #ff4444;
|
|
text-shadow: 2px 2px 4px rgba(0,0,0,0.8);
|
|
margin-bottom: 10px;
|
|
}}
|
|
|
|
.header p {{
|
|
font-size: 1.2em;
|
|
color: #aaa;
|
|
}}
|
|
|
|
.stats {{
|
|
text-align: center;
|
|
margin: 20px 0;
|
|
font-size: 1.1em;
|
|
color: #888;
|
|
}}
|
|
|
|
.category {{
|
|
margin: 40px 0;
|
|
background: rgba(0,0,0,0.2);
|
|
border-radius: 10px;
|
|
padding: 20px;
|
|
}}
|
|
|
|
.category-header {{
|
|
font-size: 2em;
|
|
color: #ff6666;
|
|
margin-bottom: 20px;
|
|
padding-bottom: 10px;
|
|
border-bottom: 2px solid #444;
|
|
}}
|
|
|
|
.category-header .count {{
|
|
font-size: 0.7em;
|
|
color: #888;
|
|
margin-left: 15px;
|
|
}}
|
|
|
|
.grid {{
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
|
|
gap: 20px;
|
|
margin-top: 20px;
|
|
}}
|
|
|
|
.asset-card {{
|
|
background: rgba(255,255,255,0.05);
|
|
border: 1px solid #444;
|
|
border-radius: 8px;
|
|
padding: 15px;
|
|
text-align: center;
|
|
transition: all 0.3s ease;
|
|
}}
|
|
|
|
.asset-card:hover {{
|
|
transform: translateY(-5px);
|
|
box-shadow: 0 8px 16px rgba(255,68,68,0.3);
|
|
border-color: #ff4444;
|
|
}}
|
|
|
|
.asset-card img {{
|
|
width: 200px;
|
|
height: 200px;
|
|
object-fit: contain;
|
|
background: rgba(0,0,0,0.3);
|
|
border-radius: 4px;
|
|
margin-bottom: 10px;
|
|
image-rendering: pixelated;
|
|
}}
|
|
|
|
.asset-name {{
|
|
font-size: 0.9em;
|
|
color: #ccc;
|
|
margin: 10px 0;
|
|
word-break: break-all;
|
|
font-family: monospace;
|
|
}}
|
|
|
|
.copy-btn {{
|
|
background: #ff4444;
|
|
color: white;
|
|
border: none;
|
|
padding: 8px 16px;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
font-size: 0.9em;
|
|
transition: all 0.2s;
|
|
}}
|
|
|
|
.copy-btn:hover {{
|
|
background: #ff6666;
|
|
transform: scale(1.05);
|
|
}}
|
|
|
|
.copy-btn:active {{
|
|
background: #cc3333;
|
|
}}
|
|
|
|
.copied {{
|
|
background: #44ff44 !important;
|
|
}}
|
|
|
|
.file-size {{
|
|
font-size: 0.8em;
|
|
color: #666;
|
|
margin-top: 5px;
|
|
}}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="header">
|
|
<h1>💀 MRTVA DOLINA 💀</h1>
|
|
<p>Asset Gallery - Static Offline Version</p>
|
|
</div>
|
|
|
|
<div class="stats">
|
|
<strong>Total Assets:</strong> {sum(len(assets) for assets in categorized_assets.values())} |
|
|
<strong>Categories:</strong> {len([c for c in categorized_assets if categorized_assets[c]])}
|
|
</div>
|
|
"""
|
|
|
|
for category, assets in sorted(categorized_assets.items()):
|
|
if not assets:
|
|
continue
|
|
|
|
html += f"""
|
|
<div class="category">
|
|
<div class="category-header">
|
|
{category}
|
|
<span class="count">({len(assets)} assets)</span>
|
|
</div>
|
|
<div class="grid">
|
|
"""
|
|
|
|
for asset in assets:
|
|
size_kb = asset['size'] / 1024
|
|
html += f"""
|
|
<div class="asset-card">
|
|
<img src="{asset['path']}" alt="{asset['name']}"
|
|
onerror="this.src='data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%22200%22 height=%22200%22%3E%3Ctext x=%2250%25%22 y=%2250%25%22 text-anchor=%22middle%22 fill=%22%23666%22%3EERROR%3C/text%3E%3C/svg%3E'">
|
|
<div class="asset-name">{asset['name']}</div>
|
|
<div class="file-size">{size_kb:.1f} KB</div>
|
|
<button class="copy-btn" onclick="copyToClipboard('{asset['name']}', this)">
|
|
📋 Copy Name
|
|
</button>
|
|
</div>
|
|
"""
|
|
|
|
html += """
|
|
</div>
|
|
</div>
|
|
"""
|
|
|
|
html += """
|
|
<script>
|
|
function copyToClipboard(text, btn) {
|
|
navigator.clipboard.writeText(text).then(() => {
|
|
const originalText = btn.textContent;
|
|
btn.textContent = '✅ Copied!';
|
|
btn.classList.add('copied');
|
|
|
|
setTimeout(() => {
|
|
btn.textContent = originalText;
|
|
btn.classList.remove('copied');
|
|
}, 1500);
|
|
}).catch(err => {
|
|
// Fallback for older browsers
|
|
const input = document.createElement('textarea');
|
|
input.value = text;
|
|
document.body.appendChild(input);
|
|
input.select();
|
|
document.execCommand('copy');
|
|
document.body.removeChild(input);
|
|
|
|
btn.textContent = '✅ Copied!';
|
|
setTimeout(() => btn.textContent = '📋 Copy Name', 1500);
|
|
});
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|
|
"""
|
|
|
|
with open(output_file, 'w', encoding='utf-8') as f:
|
|
f.write(html)
|
|
|
|
print(f"✅ Gallery generated: {output_file}")
|
|
print(f" Total assets: {sum(len(assets) for assets in categorized_assets.values())}")
|
|
print(f" Categories: {len([c for c in categorized_assets if categorized_assets[c]])}")
|
|
print(f"\n🎯 Just double-click the HTML file to open it!")
|
|
|
|
if __name__ == "__main__":
|
|
print("🎨 Scanning assets...")
|
|
categorized = scan_assets()
|
|
|
|
print("📝 Generating HTML gallery...")
|
|
generate_html(categorized)
|
|
|
|
print("\n✨ Done! Open 'asset_gallery.html' in your browser.")
|