Prepping for entities in map compiler

This commit is contained in:
2025-06-15 10:43:01 -05:00
parent 1e75471f5a
commit ef6b9473fc
7 changed files with 75 additions and 68 deletions

View File

@ -1,34 +0,0 @@
{
"chunk": {
"position": [ 0, 0 ],
"baseLayer": [
[ 1, 1, 1, 1, 1, 1, 1, 1 ],
[ 1, 1, 1, 1, 1, 1, 1, 1 ],
[ 1, 1, 1, 1, 1, 1, 1, 1 ],
[ 1, 1, 1, 1, 1, 1, 1, 1 ],
[ 1, 1, 1, 1, 1, 1, 1, 1 ],
[ 1, 1, 1, 1, 1, 1, 1, 1 ],
[ 1, 1, 1, 1, 1, 1, 1, 1 ],
[ 1, 1, 1, 1, 1, 1, 1, 1 ]
],
"overlayLayer": [
[ 1, 1, 1, 1, 1, 1, 1, 1 ],
[ 1, 1, 1, 1, 1, 1, 1, 1 ],
[ 1, 1, 1, 1, 1, 1, 1, 1 ],
[ 1, 1, 1, 1, 1, 1, 1, 1 ],
[ 1, 1, 1, 1, 1, 1, 1, 1 ],
[ 1, 1, 1, 1, 1, 1, 1, 1 ],
[ 1, 1, 1, 1, 1, 1, 1, 1 ],
[ 1, 1, 1, 1, 1, 1, 1, 1 ]
],
"entities": [
{
"type": "npc",
"x": "3",
"y": "3"
}
],
"triggers": [
]
}
}

View File

@ -1,29 +0,0 @@
{
"chunk": {
"position": [ 2, 1 ],
"baseLayer": [
[ 1, 1, 1, 1, 1, 1, 1, 1 ],
[ 1, 1, 1, 1, 1, 1, 1, 1 ],
[ 1, 1, 1, 1, 1, 1, 1, 1 ],
[ 1, 1, 1, 1, 1, 1, 1, 1 ],
[ 1, 1, 1, 1, 1, 1, 1, 1 ],
[ 1, 1, 1, 1, 1, 1, 1, 1 ],
[ 1, 1, 1, 1, 1, 1, 1, 1 ],
[ 1, 1, 1, 1, 1, 1, 1, 1 ]
],
"overlayLayer": [
[ 1, 1, 1, 1, 1, 1, 1, 1 ],
[ 1, 1, 1, 1, 1, 1, 1, 1 ],
[ 1, 1, 1, 1, 1, 1, 1, 1 ],
[ 1, 1, 1, 1, 1, 1, 1, 1 ],
[ 1, 1, 1, 1, 1, 1, 1, 1 ],
[ 1, 1, 1, 1, 1, 1, 1, 1 ],
[ 1, 1, 1, 1, 1, 1, 1, 1 ],
[ 1, 1, 1, 1, 1, 1, 1, 1 ]
],
"entities": [
],
"triggers": [
]
}
}

View File

@ -0,0 +1,14 @@
{
"automappingRulesFile": "",
"commands": [
],
"compatibilityVersion": 1100,
"extensionsPath": "extensions",
"folders": [
"."
],
"properties": [
],
"propertyTypes": [
]
}

View File

@ -0,0 +1,13 @@
{
"activeFile": "",
"expandedProjectPaths": [
],
"fileStates": {
},
"last.objectTemplatePath": "/home/yourwishes/htdocs/dusk/data/templates",
"openFiles": [
],
"project": "map project.tiled-project",
"recentFiles": [
]
}

View File

@ -2,6 +2,23 @@
"height":20,
"infinite":true,
"layers":[
{
"draworder":"topdown",
"id":3,
"name":"Object Layer 1",
"objects":[
{
"id":1,
"template":"templates\/NPC.tx",
"x":150.666666666667,
"y":96.3333333333333
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
},
{
"chunks":[
{
@ -182,7 +199,8 @@
}],
"height":32,
"id":1,
"name":"Tile Layer 1",
"locked":true,
"name":"Base Layer",
"opacity":1,
"startx":0,
"starty":0,
@ -192,8 +210,8 @@
"x":0,
"y":0
}],
"nextlayerid":2,
"nextobjectid":1,
"nextlayerid":5,
"nextobjectid":3,
"orientation":"orthogonal",
"renderorder":"right-down",
"tiledversion":"1.11.1",

4
data/templates/NPC.tx Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<template>
<object name="NPC" width="16" height="16"/>
</template>

View File

@ -67,8 +67,29 @@ if len(layers) == 0:
print(f"Error: Input file '{inputFile}' does not contain any layers.")
sys.exit(1)
# Object layer
objectLayer = None
for layer in layers:
if layer.get('type') == 'objectgroup':
objectLayer = layer
break
if objectLayer is None:
print(f"Error: Input file '{inputFile}' does not contain an object layer.")
sys.exit(1)
# Tile Layers
tileLayers = []
for layer in layers:
if layer.get('type') == 'tilelayer':
tileLayers.append(layer)
if len(tileLayers) == 0:
print(f"Error: Input file '{inputFile}' does not contain any tile layers.")
sys.exit(1)
# First layer
firstLayer = layers[0]
firstLayer = tileLayers[0]
if 'width' not in firstLayer or 'height' not in firstLayer:
print(f"Error: First layer in '{inputFile}' does not contain 'width' or 'height' key.")
sys.exit(1)
@ -112,7 +133,7 @@ for chunkY in range(mapHeightInRealChunks):
chunkLayers = []
# For each layer...
for layerIndex, layer in enumerate(layers):
for layerIndex, layer in enumerate(tileLayers):
foundChunk = None
if 'chunks' not in layer or not isinstance(layer['chunks'], list):
print(f"Error: Layer {layerIndex} in '{inputFile}' does not contain 'chunks' key.")