86 lines
2.9 KiB
Python
86 lines
2.9 KiB
Python
#!/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"""<?xml version="1.0" encoding="UTF-8"?>
|
|
<tileset version="1.10" tiledversion="1.11.2" name="farm_grass" tilewidth="32" tileheight="32" tilecount="256" columns="16">
|
|
<image source="../../../mrtva_dolina/terrain/ground/{grass_file.name}" width="512" height="512"/>
|
|
</tileset>
|
|
"""
|
|
|
|
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"""<?xml version="1.0" encoding="UTF-8"?>
|
|
<tileset version="1.10" tiledversion="1.11.2" name="{name}" tilewidth="128" tileheight="128" tilecount="{len(files)}" columns="0">
|
|
<grid orientation="orthogonal" width="1" height="1"/>
|
|
"""
|
|
|
|
for idx, file in enumerate(files):
|
|
rel_path = f"../../../mrtva_dolina/{category}/{subcategory}/{file.name}"
|
|
tsx_content += f""" <tile id="{idx}">
|
|
<image width="64" height="64" source="{rel_path}"/>
|
|
</tile>
|
|
"""
|
|
|
|
tsx_content += "</tileset>\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/")
|