About to start parsing different ent types.
This commit is contained in:
@ -4,8 +4,4 @@ CHUNK_HEIGHT = 8
|
||||
CHUNK_TILE_COUNT = CHUNK_WIDTH * CHUNK_HEIGHT
|
||||
CHUNK_ENTITY_COUNT_MAX = 8
|
||||
TILE_WIDTH_HEIGHT = 16
|
||||
TILE_WIDTH_HEIGHT = 16
|
||||
|
||||
ENTITY_TYPE_MAP = {
|
||||
"npc": "ENTITY_TYPE_NPC",
|
||||
}
|
||||
TILE_WIDTH_HEIGHT = 16
|
@ -1,15 +1,40 @@
|
||||
from constants import TILE_WIDTH_HEIGHT, ENTITY_TYPE_MAP
|
||||
from helper import floatToFixed248
|
||||
import sys
|
||||
from constants import TILE_WIDTH_HEIGHT
|
||||
|
||||
ENTITY_TYPE_MAP = {
|
||||
'templates/NPC.tx': 'ENTITY_TYPE_NPC',
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
if 'properties' not in obj:
|
||||
obj['properties'] = {}
|
||||
|
||||
obj['localX'] = obj['x'] - (chunkData['topLeftTileX'] * TILE_WIDTH_HEIGHT)
|
||||
obj['localY'] = obj['y'] - (chunkData['topLeftTileY'] * TILE_WIDTH_HEIGHT)
|
||||
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
|
@ -89,6 +89,24 @@ for chunkY in range(mapData['mapHeightInRealChunks']):
|
||||
if 'dir' in entity:
|
||||
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(f" }},\n")
|
||||
|
||||
|
Reference in New Issue
Block a user