About to start parsing different ent types.

This commit is contained in:
2025-06-23 23:24:00 -05:00
parent 24eab84f4f
commit 57d231b561
6 changed files with 53 additions and 36 deletions

View File

@ -437,8 +437,8 @@
"value":"NPC_INTERACT_TYPE_TEXT" "value":"NPC_INTERACT_TYPE_TEXT"
}], }],
"template":"templates\/NPC.tx", "template":"templates\/NPC.tx",
"x":6575.625, "x":6539.95833333333,
"y":6816.33333333333 "y":6849.33333333333
}], }],
"opacity":1, "opacity":1,
"type":"objectgroup", "type":"objectgroup",

View File

@ -1,29 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<tileset version="1.10" tiledversion="1.11.1" name="overworld" tilewidth="16" tileheight="16" tilecount="256" columns="16"> <tileset version="1.10" tiledversion="1.11.1" name="overworld" tilewidth="16" tileheight="16" tilecount="256" columns="16">
<image source="tilemap.png" width="256" height="256"/> <image source="tilemap.png" width="256" height="256"/>
<tile id="1">
<properties>
<property name="solid" type="int" value="4"/>
</properties>
</tile>
<tile id="3">
<properties>
<property name="solid" type="int" value="5"/>
</properties>
</tile>
<tile id="18"> <tile id="18">
<properties> <properties>
<property name="solidType" propertytype="tileSolidType" value="TILE_SOLID_FULL"/> <property name="solidType" propertytype="tileSolidType" value="TILE_SOLID_NONE"/>
</properties>
</tile>
<tile id="33">
<properties>
<property name="solid" type="int" value="2"/>
</properties>
</tile>
<tile id="35">
<properties>
<property name="solid" type="int" value="3"/>
</properties> </properties>
</tile> </tile>
<tile id="54"> <tile id="54">

View File

@ -4,8 +4,6 @@
typedef struct _entity_t entity_t; typedef struct _entity_t entity_t;
#define NPC_INTERACT_TEXTS_MAX 4
typedef enum { typedef enum {
NPC_INTERACT_TYPE_NONE = 0, NPC_INTERACT_TYPE_NONE = 0,
NPC_INTERACT_TYPE_TEXT = 1, NPC_INTERACT_TYPE_TEXT = 1,
@ -17,7 +15,7 @@ typedef struct {
npcinteracttype_t interactType; npcinteracttype_t interactType;
union { union {
char_t* texts[NPC_INTERACT_TEXTS_MAX]; char_t* text;
}; };
} npc_t; } npc_t;

View File

@ -4,8 +4,4 @@ CHUNK_HEIGHT = 8
CHUNK_TILE_COUNT = CHUNK_WIDTH * CHUNK_HEIGHT CHUNK_TILE_COUNT = CHUNK_WIDTH * CHUNK_HEIGHT
CHUNK_ENTITY_COUNT_MAX = 8 CHUNK_ENTITY_COUNT_MAX = 8
TILE_WIDTH_HEIGHT = 16 TILE_WIDTH_HEIGHT = 16
TILE_WIDTH_HEIGHT = 16 TILE_WIDTH_HEIGHT = 16
ENTITY_TYPE_MAP = {
"npc": "ENTITY_TYPE_NPC",
}

View File

@ -1,15 +1,40 @@
from constants import TILE_WIDTH_HEIGHT, ENTITY_TYPE_MAP import sys
from helper import floatToFixed248 from constants import TILE_WIDTH_HEIGHT
ENTITY_TYPE_MAP = {
'templates/NPC.tx': 'ENTITY_TYPE_NPC',
}
def parseEntity(obj, chunkData): def parseEntity(obj, chunkData):
if 'type' in obj and obj['type'] not in ENTITY_TYPE_MAP: if 'type' in obj:
if obj['type'] not in ENTITY_TYPE_MAP:
print(f"Unknown entity type: {obj['type']}")
return None
entType = ENTITY_TYPE_MAP[obj['type']]
elif 'template' in obj:
if obj['template'] not in ENTITY_TYPE_MAP:
print(f"Unknown entity template: {obj['template']}")
return None
entType = ENTITY_TYPE_MAP[obj['template']]
else:
return None return None
if 'properties' not in obj:
obj['properties'] = {}
obj['localX'] = obj['x'] - (chunkData['topLeftTileX'] * TILE_WIDTH_HEIGHT) obj['localX'] = obj['x'] - (chunkData['topLeftTileX'] * TILE_WIDTH_HEIGHT)
obj['localY'] = obj['y'] - (chunkData['topLeftTileY'] * TILE_WIDTH_HEIGHT) obj['localY'] = obj['y'] - (chunkData['topLeftTileY'] * TILE_WIDTH_HEIGHT)
obj['dir'] = 'ENTITY_DIR_SOUTH' obj['dir'] = 'ENTITY_DIR_SOUTH'
obj['type'] = 'ENTITY_TYPE_NPC' obj['type'] = entType
print(obj) # Handle per-type properties
if entType == 'ENTITY_TYPE_NPC':
obj['data'] = {}
obj['data']['npc'] = {}
obj['data']['npc']['interactType'] = 'NPC_INTERACT_TYPE_TEXT'
obj['data']['npc']['text'] = '"test"'
return obj return obj

View File

@ -89,6 +89,24 @@ for chunkY in range(mapData['mapHeightInRealChunks']):
if 'dir' in entity: if 'dir' in entity:
f.write(f" .dir = {entity['dir']},\n") f.write(f" .dir = {entity['dir']},\n")
def printRecurse(obj, tabs = " "):
for key, value in obj:
if isinstance(value, dict):
f.write(f"{tabs}.{key} = {{\n")
printRecurse(value.items(), tabs + " ")
f.write(f"{tabs}}},\n")
elif isinstance(value, list):
f.write(f"{tabs}.{key} = {{\n")
for item in value:
f.write(f"{tabs} {item},\n")
f.write(f"{tabs}}},\n")
else:
f.write(f"{tabs}.{key} = {value},\n")
if 'data' in entity:
printRecurse(entity['data'].items())
f.write(" },\n") f.write(" },\n")
f.write(f" }},\n") f.write(f" }},\n")