load map first pass
This commit is contained in:
@@ -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]
|
||||
|
Reference in New Issue
Block a user