ok
This commit is contained in:
171
scripts/setup_ldtk.py
Normal file
171
scripts/setup_ldtk.py
Normal file
@@ -0,0 +1,171 @@
|
||||
import json
|
||||
import os
|
||||
import glob
|
||||
|
||||
# Paths
|
||||
PROJECT_ROOT = "/Users/davidkotnik/repos/novafarma"
|
||||
LDTK_FILE = os.path.join(PROJECT_ROOT, "AutoLayers_2_stamps.ldtk")
|
||||
GODOT_DIR = os.path.join(PROJECT_ROOT, "godot")
|
||||
|
||||
def create_tileset_def(uid, identifier, rel_path, w=512, h=512):
|
||||
return {
|
||||
"__cWid": w // 32,
|
||||
"__cHei": h // 32,
|
||||
"identifier": identifier,
|
||||
"uid": uid,
|
||||
"relPath": rel_path,
|
||||
"embedAtlas": None,
|
||||
"pxWid": w,
|
||||
"pxHei": h,
|
||||
"tileGridSize": 32,
|
||||
"spacing": 0,
|
||||
"padding": 0,
|
||||
"tags": [],
|
||||
"tagsSourceEnumUid": None,
|
||||
"enumTags": [],
|
||||
"customData": [],
|
||||
"savedSelections": [],
|
||||
"cachedPixelData": None
|
||||
}
|
||||
|
||||
def create_entity_def(uid, identifier, rel_path, w=32, h=32):
|
||||
return {
|
||||
"identifier": identifier,
|
||||
"uid": uid,
|
||||
"width": w,
|
||||
"height": h,
|
||||
"color": "#94D9B3",
|
||||
"renderMode": "Tile",
|
||||
"tileRenderMode": "FitInside",
|
||||
"tileRect": {
|
||||
"tilesetUid": None, # Will need to add the image as a 'tileset' usually, or use 'Tile' mode referencing a tileset?
|
||||
# Actually LDtk entities often just reference the tileset.
|
||||
# But for individual images, we might use 'renderMode': 'Tile' w/ tileId if connected to a tileset.
|
||||
# Easier mode: 'Rectangle' or 'Cross' for now if complex.
|
||||
# BUT user wants to see the images.
|
||||
# Better: create a "Characters" tileset if possible.
|
||||
# Since we have individual images, let's just use RenderMode 'Tile' and link to a specific tileset we create for each?
|
||||
# That might be too many tilesets.
|
||||
# Let's skip visual sprite for now and just set color + identifier,
|
||||
# OR better: Just map the Ground tilesets first.
|
||||
},
|
||||
"tilesetId": None,
|
||||
"tileId": None,
|
||||
"resizableX": False,
|
||||
"resizableY": False,
|
||||
"keepAspectRatio": True,
|
||||
"fillOpacity": 1,
|
||||
"lineOpacity": 1,
|
||||
"hollow": False,
|
||||
"pivotX": 0.5,
|
||||
"pivotY": 1,
|
||||
"fieldDefs": [],
|
||||
"maxCount": 0,
|
||||
"limitScope": "PerLevel",
|
||||
"limitBehavior": "MoveLastOne"
|
||||
}
|
||||
|
||||
def main():
|
||||
if not os.path.exists(LDTK_FILE):
|
||||
print(f"File not found: {LDTK_FILE}")
|
||||
return
|
||||
|
||||
with open(LDTK_FILE, 'r') as f:
|
||||
data = json.load(f)
|
||||
|
||||
# 1. SETUP TILESETS (Ground)
|
||||
# IDs starting at 100
|
||||
next_uid = 100
|
||||
tileset_defs = []
|
||||
|
||||
# Ground textures
|
||||
grounds = [
|
||||
("Grass", "godot/world/GROUND/grass.png"),
|
||||
("Dirt", "godot/world/GROUND/dirt.png"),
|
||||
("Water", "godot/world/GROUND/water.png"),
|
||||
("Farmland", "godot/world/GROUND/farmland.png")
|
||||
]
|
||||
|
||||
for name, path in grounds:
|
||||
# Check if file exists
|
||||
full_path = os.path.join(PROJECT_ROOT, path)
|
||||
if os.path.exists(full_path):
|
||||
ts = create_tileset_def(next_uid, name, path, 512, 512)
|
||||
tileset_defs.append(ts)
|
||||
next_uid += 1
|
||||
|
||||
data['defs']['tilesets'] = tileset_defs
|
||||
|
||||
# 2. SETUP LAYERS
|
||||
# Create a Tile layer for each ground type? Or one layer that can switch?
|
||||
# Usually one layer per tileset if they are separate images.
|
||||
# We will create "Ground_Grass", "Ground_Dirt" etc. for simplicity.
|
||||
|
||||
layer_defs = []
|
||||
layer_uid = 200
|
||||
|
||||
for ts in tileset_defs:
|
||||
layer = {
|
||||
"__type": "Tiles",
|
||||
"identifier": f"Layer_{ts['identifier']}",
|
||||
"type": "Tiles",
|
||||
"uid": layer_uid,
|
||||
"gridSize": 32,
|
||||
"displayOpacity": 1,
|
||||
"pxOffsetX": 0,
|
||||
"pxOffsetY": 0,
|
||||
"requiredTags": [],
|
||||
"excludedTags": [],
|
||||
"intGridValues": [],
|
||||
"autoRuleGroups": [],
|
||||
"autoSourceLayerDefUid": None,
|
||||
"tilesetDefUid": ts['uid'],
|
||||
"tilePivotX": 0,
|
||||
"tilePivotY": 0
|
||||
}
|
||||
layer_defs.append(layer)
|
||||
layer_uid += 1
|
||||
|
||||
# Add Entity Layer
|
||||
entity_layer = {
|
||||
"__type": "Entities",
|
||||
"identifier": "Entities",
|
||||
"type": "Entities",
|
||||
"uid": layer_uid,
|
||||
"gridSize": 32,
|
||||
"displayOpacity": 1,
|
||||
"pxOffsetX": 0,
|
||||
"pxOffsetY": 0,
|
||||
"requiredTags": [],
|
||||
"excludedTags": [],
|
||||
"intGridValues": [],
|
||||
"autoRuleGroups": [],
|
||||
"autoSourceLayerDefUid": None,
|
||||
"tilesetDefUid": None,
|
||||
"tilePivotX": 0,
|
||||
"tilePivotY": 0
|
||||
}
|
||||
layer_defs.append(entity_layer)
|
||||
|
||||
data['defs']['layers'] = layer_defs
|
||||
|
||||
# 3. SETUP ENTITIES (Placeholders)
|
||||
# Just adding definitions for Kai, Ana, Gronk
|
||||
entity_defs = []
|
||||
ent_uid = 300
|
||||
|
||||
for name in ["Kai", "Ana", "Gronk"]:
|
||||
ent = create_entity_def(ent_uid, name, "")
|
||||
entity_defs.append(ent)
|
||||
ent_uid += 1
|
||||
|
||||
data['defs']['entities'] = entity_defs
|
||||
|
||||
# Save
|
||||
with open(LDTK_FILE, 'w') as f:
|
||||
json.dump(data, f, indent=2)
|
||||
|
||||
print("LDtk file updated successfully!")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user