Files
novafarma/scripts/generate_town_map.py

115 lines
2.8 KiB
Python

import json
import os
# Configuration
WIDTH = 100
HEIGHT = 100
TILE_SIZE = 48 # Using 48px for alignment with technical standards
# Create the data array (100x100 filled with 1s for 'Ground' tile)
# 1 = Grass tile from firstgid:1
ground_data = [1] * (WIDTH * HEIGHT)
objects_data = [0] * (WIDTH * HEIGHT)
player_data = [0] * (WIDTH * HEIGHT)
# Center coordinates
cx, cy = WIDTH // 2, HEIGHT // 2
# Helper to set tile at x,y
def set_tile(layer_data, x, y, gid):
index = y * WIDTH + x
if 0 <= index < len(layer_data):
layer_data[index] = gid
# Place Player (Kai) at Town Center
set_tile(player_data, cx, cy, 1541)
map_structure = {
"compressionlevel": -1,
"height": HEIGHT,
"infinite": False,
"layers": [
{
"data": ground_data,
"height": HEIGHT,
"id": 1,
"name": "Ground",
"opacity": 1,
"type": "tilelayer",
"visible": True,
"width": WIDTH,
"x": 0,
"y": 0
},
{
"data": objects_data,
"height": HEIGHT,
"id": 2,
"name": "Objects",
"opacity": 1,
"type": "tilelayer",
"visible": True,
"width": WIDTH,
"x": 0,
"y": 0
},
{
"data": player_data,
"height": HEIGHT,
"id": 3,
"name": "Player",
"opacity": 1,
"type": "tilelayer",
"visible": True,
"width": WIDTH,
"x": 0,
"y": 0
}
],
"nextlayerid": 4,
"nextobjectid": 1,
"orientation": "orthogonal",
"renderorder": "right-down",
"tileheight": TILE_SIZE,
"tilesets": [
{
"columns": 16,
"firstgid": 1,
"image": "../narezano_in_majhno/krvava_zetev_sprites/grass_soil_tileset_1766171156780_obdelan.png",
"imageheight": 512,
"imagewidth": 512,
"margin": 0,
"name": "01_Ground",
"spacing": 0,
"tilecount": 256,
"tileheight": 32,
"tilewidth": 32
},
{
"columns": 10,
"firstgid": 1500,
"image": "../krvava_zetev_sprites/kai_character_2x2_grid_1766098341666.png",
"imageheight": 1024,
"imagewidth": 1024,
"margin": 0,
"name": "Kai_Character",
"spacing": 0,
"tilecount": 100,
"tileheight": 96,
"tilewidth": 96
}
],
"tilewidth": TILE_SIZE,
"type": "map",
"version": "1.10",
"width": WIDTH
}
output_path = "assets/maps/TownSquare.json"
with open(output_path, "w") as f:
json.dump(map_structure, f, indent=4)
print(f"✅ Generated 100x100 TownSquare scaffold: {output_path}")