load map first pass
This commit is contained in:
@@ -2,6 +2,7 @@ import sys, os
|
||||
from args import inputAssets, args
|
||||
from processasset import processAsset
|
||||
from processpalette import processPaletteList
|
||||
from processtileset import processTilesetList
|
||||
from assethelpers import getBuiltAssetsRelativePath
|
||||
import zipfile
|
||||
|
||||
@@ -29,6 +30,7 @@ with zipfile.ZipFile(outputFileName, 'w') as zipf:
|
||||
|
||||
# Generate additional headers.
|
||||
processPaletteList()
|
||||
processTilesetList()
|
||||
|
||||
# Finalize build
|
||||
if args.build_type == 'header':
|
||||
|
@@ -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]
|
||||
|
@@ -8,6 +8,8 @@ from args import args
|
||||
from xml.etree import ElementTree
|
||||
from assetcache import assetGetCache, assetCache
|
||||
|
||||
tilesets = []
|
||||
|
||||
def loadTilesetFromTSX(asset):
|
||||
# Load the TSX file
|
||||
tree = ElementTree.parse(asset['path'])
|
||||
@@ -138,10 +140,36 @@ def processTileset(asset):
|
||||
os.makedirs(os.path.dirname(outputFile), exist_ok=True)
|
||||
with open(outputFile, 'w') as f:
|
||||
f.write(data)
|
||||
|
||||
return assetCache(asset['path'], {
|
||||
|
||||
|
||||
tileset = {
|
||||
"files": [],
|
||||
"image": tilesetData['image'],
|
||||
"headerFile": outputFile,
|
||||
"headerFile": os.path.relpath(outputFile, args.headers_dir),
|
||||
"tilesetName": tilesetName,
|
||||
"tilesetNameUpper": tilesetNameUpper,
|
||||
"tilesetIndex": len(tilesets),
|
||||
"tilesetData": tilesetData,
|
||||
"files": tilesetData['image']['files'],
|
||||
})
|
||||
}
|
||||
|
||||
tilesets.append(tileset)
|
||||
return assetCache(asset['path'], tileset)
|
||||
|
||||
def processTilesetList():
|
||||
data = f"// Tileset List Generated at {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n"
|
||||
data += f"#pragma once\n"
|
||||
for tileset in tilesets:
|
||||
data += f"#include \"{tileset['headerFile']}\"\n"
|
||||
data += f"\n"
|
||||
data += f"#define TILESET_LIST_COUNT {len(tilesets)}\n\n"
|
||||
data += f"static const tileset_t* TILESET_LIST[TILESET_LIST_COUNT] = {{\n"
|
||||
for tileset in tilesets:
|
||||
data += f" &TILESET_{tileset['tilesetNameUpper']},\n"
|
||||
data += f"}};\n"
|
||||
|
||||
# Write header.
|
||||
outputFile = os.path.join(args.headers_dir, "display", "tileset", f"tilesetlist.h")
|
||||
os.makedirs(os.path.dirname(outputFile), exist_ok=True)
|
||||
with open(outputFile, 'w') as f:
|
||||
f.write(data)
|
Reference in New Issue
Block a user