Files
novafarma/scripts/setup_ldtk_entity_images.py
2026-01-20 01:05:17 +01:00

68 lines
2.6 KiB
Python

import json
import os
PROJECT_ROOT = "/Users/davidkotnik/repos/novafarma"
LDTK_FILE = os.path.join(PROJECT_ROOT, "AutoLayers_2_stamps.ldtk")
def main():
with open(LDTK_FILE, 'r') as f:
data = json.load(f)
# Need to add separate tilesets for Entities or single tile references
# For Entities in LDtk, best way to show image is:
# 1. Create a "Tileset" definition for the image
# 2. Link the Entity definition to that Tileset
# KAI IMAGE
kai_path = "godot/characters/KAI/kai_walk_east_1767695851347.png"
# (Using the one found, relative path)
# CANNABIS IMAGE
weed_path = "godot/phases/DEMO/crops/cannabis/growth_stages/cannabis_stage1_sprout.png"
# 1. CREATE TILESETS FOR ENTITIES
ts_kai_uid = 160
ts_kai = {
"__cWid": 1, "__cHei": 1, "identifier": "TS_Kai", "uid": ts_kai_uid,
"relPath": kai_path, "embedAtlas": None, "pxWid": 256, "pxHei": 256,
"tileGridSize": 256, "spacing": 0, "padding": 0, "tags": [], "tagsSourceEnumUid": None, "enumTags": [], "customData": [], "savedSelections": [], "cachedPixelData": None
}
ts_weed_uid = 161
ts_weed = {
"__cWid": 1, "__cHei": 1, "identifier": "TS_Weed", "uid": ts_weed_uid,
"relPath": weed_path, "embedAtlas": None, "pxWid": 32, "pxHei": 32, # Assuming resized to 32 earlier? Or 256?
# Check resize script: DEMO crops resized to 256.
# So pxWid should be 256 probably.
# Wait, grid size is 32. If image is 256, it will be huge.
# Entity definition width/height is what matters for collision, but visual is tile.
# Let's assume 256 for now.
"tileGridSize": 256, "spacing": 0, "padding": 0, "tags": [], "tagsSourceEnumUid": None, "enumTags": [], "customData": [], "savedSelections": [], "cachedPixelData": None
}
# Add to defs
data['defs']['tilesets'].append(ts_kai)
data['defs']['tilesets'].append(ts_weed)
# 2. UPDATE ENTITY DEFINITIONS
for ent in data['defs']['entities']:
if ent['identifier'] == "Kai_Hoe":
ent['tilesetId'] = ts_kai_uid
ent['tileId'] = 0 # First tile
ent['tileRenderMode'] = "FitInside" # Fit image in box
ent['renderMode'] = "Tile"
if ent['identifier'] == "Crop_Cannabis":
ent['tilesetId'] = ts_weed_uid
ent['tileId'] = 0
ent['tileRenderMode'] = "FitInside"
ent['renderMode'] = "Tile"
with open(LDTK_FILE, 'w') as f:
json.dump(data, f, indent=2)
print("LDtk Entities updated with Images!")
if __name__ == "__main__":
main()