Update parsers to use more real C data.

This commit is contained in:
2025-06-23 22:23:18 -05:00
parent 22af9d1507
commit 24eab84f4f
17 changed files with 85 additions and 57 deletions

View File

@ -1,11 +1,12 @@
from constants import TILE_WIDTH_HEIGHT, ENTITY_TYPE_MAP
from helper import floatToFixed248
def parseEntity(obj, chunkData):
if 'type' in obj and obj['type'] not in ENTITY_TYPE_MAP:
return None
obj['localX'] = round(obj['x'] - (chunkData['topLeftTileX'] * TILE_WIDTH_HEIGHT))
obj['localY'] = round(obj['y'] - (chunkData['topLeftTileY'] * TILE_WIDTH_HEIGHT))
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'

View File

@ -2,4 +2,4 @@ def floatToFixed248(value):
# Converts a float to the fixed248_t used internally.
high24 = int(value) & 0xFFFFFF
low8 = int((value * 256.0 - high24) * 256.0) & 0xFF
return (high24 << 8) | low8
return f'((fixed248_t){(high24 << 8) | low8})'

View File

@ -121,6 +121,10 @@ def parseMap(data):
print(f"Error: Object in object layer does not contain 'x' or 'y' key.")
sys.exit(1)
if 'id' not in ob:
print(f"Error: Object in object layer does not contain 'id' key.")
sys.exit(1)
ob['x'] -= mapData['inputMapLowestX'] * TILE_WIDTH_HEIGHT
ob['y'] -= mapData['inputMapLowestY'] * TILE_WIDTH_HEIGHT

View File

@ -83,9 +83,12 @@ for chunkY in range(mapData['mapHeightInRealChunks']):
f.write(" {\n")
f.write(f" .id = {entity['id']},\n")
f.write(f" .type = {entity['type']},\n")
f.write(f" .x = {entity['localX']},\n")
f.write(f" .y = {entity['localY']},\n")
f.write(f" .dir = {entity['dir']},\n")
f.write(f" .x = {floatToFixed248(entity['x'])},\n")
f.write(f" .y = {floatToFixed248(entity['y'])},\n")
if 'dir' in entity:
f.write(f" .dir = {entity['dir']},\n")
f.write(" },\n")
f.write(f" }},\n")

View File

@ -91,14 +91,17 @@ with open(headerFile, 'w') as f:
def findProp(name, expectedType=''):
for prop in properties.findall('property'):
if prop.get('name') == name:
if len(expectedType) > 0 and prop.get('type') != expectedType:
continue
if len(expectedType) > 0:
if 'type' in prop.attrib and prop.get('type') != expectedType:
continue
if 'propertytype' in prop.attrib and prop.get('propertytype') != expectedType:
continue
return prop.get('value', '')
return None
f.write(f" {{\n")
propSolid = findProp('solid', 'int')
propSolid = findProp('solidType', 'tileSolidType')
if propSolid is not None:
f.write(f" .solidType = {propSolid},\n")