load map first pass

This commit is contained in:
2025-09-19 12:43:57 -05:00
parent 2f40724258
commit 061352bcff
14 changed files with 256 additions and 52 deletions

View File

@@ -109,42 +109,21 @@ def processMap(asset):
# Now we have our layers all parsed out.
data = bytearray()
data += b'drm' # Dusk RPG Map
data += b'DRM' # Dusk RPG Map
data += mapWidth.to_bytes(4, 'little') # Map width in tiles
data += mapHeight.to_bytes(4, 'little') # Map height in tiles
data += len(tilesets).to_bytes(4, 'little') # Number of tilesets
data += len(tileLayers).to_bytes(4, 'little') # Number of layers
# For each tileset
for tileset in tilesets:
data += tileset['firstGid'].to_bytes(4, 'little') # First GID
# For each layer...
for layer in tileLayers:
for gid in layer['data']:
# Get tileset for this gid, since the tilesets are already sorted we can
# simply find the first one that has firstGid <= gid
if gid == 0:
# Empty tile
localIndex = 0xFF
tilesetIndex = 0xFFFFFFFF
else:
for tileset in tilesets:
if gid >= tileset['firstGid']:
tilesetIndex = tilesets.index(tileset)
localIndex = gid - tileset['firstGid']
break
else:
# If no tileset was found, this is an invalid gid
print(f"Error: Invalid tile GID {gid} in {asset['path']}")
sys.exit(1)
data += gid.to_bytes(4, 'little') # Tileset index
if localIndex > 255:
print(f"Error: Local tile index {localIndex} exceeds 255 in {asset['path']}")
sys.exit(1)
data += tilesetIndex.to_bytes(4, 'little') # Tileset index
data += localIndex.to_bytes(1, 'little') # Local tile index
# For each tileset
for tileset in tilesets:
data += tileset['firstGid'].to_bytes(4, 'little') # First GID
data += tileset['tileset']['tilesetIndex'].to_bytes(4, 'little') # Tileset index
relative = getAssetRelativePath(asset['path'])
fileNameWithoutExt = os.path.splitext(os.path.basename(asset['path']))[0]