Started entity parser
This commit is contained in:
@ -5,8 +5,8 @@ import math
|
||||
from helper import floatToFixed248
|
||||
from inputParser import parseInputFile
|
||||
from mapParser import parseMap
|
||||
from chunkParser import chunkGetLocalTileX, chunkGetLocalTileY, chunkGetTileIndex, chunkGetOutputTileIndex, parseChunk
|
||||
from constants import CHUNK_WIDTH, CHUNK_HEIGHT, TILE_WIDTH_HEIGHT, ENTITY_TYPE_MAP, CHUNK_TILE_COUNT
|
||||
from chunkParser import parseChunk
|
||||
from constants import CHUNK_WIDTH, CHUNK_HEIGHT
|
||||
|
||||
# Check if the script is run with the correct arguments
|
||||
parser = argparse.ArgumentParser(description="Generate chunk header files")
|
||||
@ -79,19 +79,13 @@ for chunkY in range(mapData['mapHeightInRealChunks']):
|
||||
|
||||
f.write(f" .entities = {{\n")
|
||||
for entity in chunkData['entities']:
|
||||
# Entities are center aligned in tiled.
|
||||
localX = round(entity['x'] - (chunkData['topLeftTileX'] * TILE_WIDTH_HEIGHT))
|
||||
localY = round(entity['y'] - (chunkData['topLeftTileY'] * TILE_WIDTH_HEIGHT))
|
||||
|
||||
if 'type' in entity and entity['type'] not in ENTITY_TYPE_MAP:
|
||||
continue
|
||||
|
||||
f.write(" {\n")
|
||||
f.write(f" .id = {entity['id']},\n")
|
||||
f.write(f" .type = ENTITY_TYPE_NPC,\n")
|
||||
f.write(f" .x = {localX},\n")
|
||||
f.write(f" .y = {localY},\n")
|
||||
f.write(f" .dir = ENTITY_DIR_SOUTH,\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(" },\n")
|
||||
f.write(f" }},\n")
|
||||
|
||||
@ -106,12 +100,18 @@ with open(headerPath, 'w') as f:
|
||||
|
||||
# Now, for each chunk, include its header file
|
||||
for (x, y) in chunksDone:
|
||||
chunk_header = f"world/chunk/chunk_{x}_{y}.h"
|
||||
f.write(f"#include \"{chunk_header}\"\n")
|
||||
f.write(f"#include \"world/chunk/chunk_{x}_{y}.h\"\n")
|
||||
|
||||
f.write("\n")
|
||||
f.write(f"#define WORLD_WIDTH {worldWidth}\n")
|
||||
f.write(f"#define WORLD_HEIGHT {worldHeight}\n\n")
|
||||
f.write(f"#define WORLD_HEIGHT {worldHeight}\n")
|
||||
|
||||
# Write out other global variables.
|
||||
f.write(f"#define WORLD_PLAYER_SPAWN_X ((fixed248_t){floatToFixed248(mapData['playerSpawnX'])})\n")
|
||||
f.write(f"#define WORLD_PLAYER_SPAWN_Y ((fixed248_t){floatToFixed248(mapData['playerSpawnY'])})\n")
|
||||
|
||||
f.write("\n")
|
||||
|
||||
f.write(f"static const chunkdata_t* WORLD_CHUNKS[] = {{\n")
|
||||
for i in range(worldHeight):
|
||||
f.write(" ")
|
||||
@ -122,7 +122,5 @@ with open(headerPath, 'w') as f:
|
||||
f.write("NULL, ")
|
||||
f.write("\n")
|
||||
f.write("};\n\n")
|
||||
f.write(f"#define WORLD_PLAYER_SPAWN_X ((fixed248_t){floatToFixed248(mapData['playerSpawnX'])})\n")
|
||||
f.write(f"#define WORLD_PLAYER_SPAWN_Y ((fixed248_t){floatToFixed248(mapData['playerSpawnY'])})\n")
|
||||
|
||||
print(f"chunks.h generated at: {headerPath}")
|
Reference in New Issue
Block a user