#!/usr/bin/env python3
"""
Generate TSX tilesets for Base Farm from mrtva_dolina collection
"""
import os
from pathlib import Path
BASE_DIR = Path("/Users/davidkotnik/Desktop/novafarma")
MRTVA_DOLINA = BASE_DIR / "mrtva_dolina"
OUTPUT_DIR = BASE_DIR / "assets" / "maps" / "farm_tilesets"
# Create output directory
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
def create_ground_tileset():
"""Create grass/ground tileset"""
# Find grass tiles
ground_dir = MRTVA_DOLINA / "terrain" / "ground"
grass_files = [f for f in ground_dir.glob("*grass*.png")]
if not grass_files:
print("⚠️ No grass files found, using first available")
grass_files = list(ground_dir.glob("*.png"))[:1]
if grass_files:
grass_file = grass_files[0]
# Create TSX for grass
tsx_content = f"""
"""
tsx_path = OUTPUT_DIR / "farm_grass.tsx"
with open(tsx_path, 'w') as f:
f.write(tsx_content)
print(f"✓ Created farm_grass.tsx")
return str(tsx_path)
return None
def create_collection_tileset(category, subcategory, name, pattern="*.png", max_tiles=20):
"""Create collection-based tileset"""
source_dir = MRTVA_DOLINA / category / subcategory
files = list(source_dir.glob(pattern))[:max_tiles]
if not files:
print(f"⚠️ No files found for {name}")
return None
tsx_content = f"""
"""
for idx, file in enumerate(files):
rel_path = f"../../../mrtva_dolina/{category}/{subcategory}/{file.name}"
tsx_content += f"""
"""
tsx_content += "\n"
tsx_path = OUTPUT_DIR / f"{name}.tsx"
with open(tsx_path, 'w') as f:
f.write(tsx_content)
print(f"✓ Created {name}.tsx ({len(files)} tiles)")
return str(tsx_path)
# Generate tilesets
print("🎨 Generating Base Farm Tilesets...\n")
create_ground_tileset()
create_collection_tileset("buildings", "houses", "farm_buildings", "*house*.png", 10)
create_collection_tileset("vegetation", "trees", "farm_trees", "*.png", 15)
create_collection_tileset("buildings", "structures", "farm_fences", "*fence*.png", 10)
create_collection_tileset("terrain", "ground", "farm_soil", "*soil*.png", 5)
print("\n✅ Done! Tilesets created in assets/maps/farm_tilesets/")