Files
novafarma/create_atlas.py

41 lines
1.1 KiB
Python

from PIL import Image
import os
# Paths
ROOT = "/Users/davidkotnik/repos/novafarma"
SOURCES = {
"grass": os.path.join(ROOT, "godot/world/GROUND/grass.png"),
"dirt": os.path.join(ROOT, "godot/world/GROUND/dirt.png"),
"water": os.path.join(ROOT, "godot/world/GROUND/water.png"),
"farm": os.path.join(ROOT, "godot/world/GROUND/farmland.png")
}
OUTPUT = os.path.join(ROOT, "godot/phases/FAZA_1_FARMA/tilesets/TerrainAtlas.png")
# Create 512x512 Atlas (Assuming source images are 256x256 or can be resized)
# Actually sources are 512x512 currently.
# To fit 4 textures into 512x512 atlas, each needs to be 256x256.
ATLAS_SIZE = (512, 512)
CELL_SIZE = (256, 256)
atlas = Image.new("RGBA", ATLAS_SIZE)
# Process
positions = [
("grass", (0, 0)),
("dirt", (256, 0)),
("water", (0, 256)),
("farm", (256, 256))
]
for name, pos in positions:
path = SOURCES[name]
if os.path.exists(path):
img = Image.open(path).resize(CELL_SIZE, Image.Resampling.LANCZOS)
atlas.paste(img, pos)
print(f"Adding {name} at {pos}")
else:
print(f"Missing: {path}")
atlas.save(OUTPUT)
print(f"Atlas saved to {OUTPUT}")