Features: - Resized 4513 PNG assets to 40% for optimal Tiled performance - Created comprehensive tileset library (grass, dirt, trees, flowers, ruins, walls) - Generated 3 test maps: travnik_32x32, zapuscena_vas_48x48, travnik_s_objekti - Added 9 different ruined building tilesets for TownRestorationSystem integration Tools Added: - resize_assets_for_tiled.py: Batch resize all assets to 40% - generate_tiled_map.py: Auto-generate maps with placed objects - fix_tiled_map.py: Create proper tile-based maps Structure: - Slike_za_Tiled/: 4513 resized assets ready for Tiled - assets/tilesets/: 16 tileset definitions (.tsx files) - assets/maps/: 3 ready-to-use Tiled maps (.tmx files) Documentation: - docs/TILED_SETUP_GUIDE.md: Complete setup and usage guide Ready for map design in Tiled Map Editor!
83 lines
2.9 KiB
Python
83 lines
2.9 KiB
Python
"""
|
|
Resize all PNG assets to 40% for Tiled Map Editor
|
|
Scans all subfolders in assets/ and resizes images
|
|
"""
|
|
import os
|
|
from PIL import Image
|
|
from pathlib import Path
|
|
|
|
# Configurations
|
|
SOURCE_DIR = r"c:\novafarma\assets"
|
|
OUTPUT_DIR = r"c:\novafarma\Slike_za_Tiled"
|
|
SCALE_FACTOR = 0.4 # 40% of original size
|
|
|
|
def resize_images():
|
|
"""Resize all PNG images to 40% and save to Slike_za_Tiled"""
|
|
|
|
# Create output directory
|
|
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
|
|
|
# Track statistics
|
|
processed = 0
|
|
skipped = 0
|
|
errors = []
|
|
|
|
print(f"🔍 Scanning {SOURCE_DIR} for PNG files...")
|
|
print(f"📁 Output directory: {OUTPUT_DIR}")
|
|
print(f"📏 Scale factor: {SCALE_FACTOR * 100}%\n")
|
|
|
|
# Walk through all subdirectories
|
|
for root, dirs, files in os.walk(SOURCE_DIR):
|
|
for filename in files:
|
|
if filename.lower().endswith('.png'):
|
|
source_path = os.path.join(root, filename)
|
|
|
|
# Create unique output filename (flat structure)
|
|
# Use relative path to create unique name
|
|
rel_path = os.path.relpath(source_path, SOURCE_DIR)
|
|
output_filename = rel_path.replace(os.sep, '_')
|
|
output_path = os.path.join(OUTPUT_DIR, output_filename)
|
|
|
|
try:
|
|
# Open and resize image
|
|
with Image.open(source_path) as img:
|
|
original_size = img.size
|
|
new_size = (
|
|
int(img.width * SCALE_FACTOR),
|
|
int(img.height * SCALE_FACTOR)
|
|
)
|
|
|
|
# Resize with high-quality resampling
|
|
resized_img = img.resize(new_size, Image.Resampling.LANCZOS)
|
|
|
|
# Save resized image
|
|
resized_img.save(output_path, 'PNG', optimize=True)
|
|
|
|
processed += 1
|
|
if processed % 50 == 0:
|
|
print(f"✅ Processed {processed} images...")
|
|
|
|
except Exception as e:
|
|
errors.append(f"{filename}: {str(e)}")
|
|
skipped += 1
|
|
|
|
# Print summary
|
|
print(f"\n{'='*60}")
|
|
print(f"✨ RESIZE COMPLETE!")
|
|
print(f"{'='*60}")
|
|
print(f"✅ Successfully processed: {processed} images")
|
|
print(f"⚠️ Skipped (errors): {skipped} images")
|
|
print(f"📁 Output location: {OUTPUT_DIR}")
|
|
|
|
if errors:
|
|
print(f"\n❌ Errors encountered:")
|
|
for error in errors[:10]: # Show first 10 errors
|
|
print(f" - {error}")
|
|
if len(errors) > 10:
|
|
print(f" ... and {len(errors) - 10} more")
|
|
|
|
print(f"\n🎮 Ready for Tiled Map Editor!")
|
|
|
|
if __name__ == "__main__":
|
|
resize_images()
|