Image generation?
This commit is contained in:
@@ -47,32 +47,28 @@ def processTileset(assetPath):
|
||||
relativeFile = getAssetRelativePath(assetPath)
|
||||
relativeDir = os.path.dirname(relativeFile)
|
||||
|
||||
data = "DTF" # Header for Dusk Tileset Format
|
||||
# Write width (int32_t)
|
||||
data += tilewidth.to_bytes(4, byteorder='little').decode('latin1')
|
||||
# Write height (int32_t)
|
||||
data += tileheight.to_bytes(4, byteorder='little').decode('latin1')
|
||||
# Write tilecount (int32_t)
|
||||
data += tilecount.to_bytes(4, byteorder='little').decode('latin1')
|
||||
# Write column count (int32_t)
|
||||
data += columns.to_bytes(4, byteorder='little').decode('latin1')
|
||||
# Write row count (int32_t)
|
||||
rows = (tilecount + columns - 1) // columns
|
||||
data += rows.to_bytes(4, byteorder='little').decode('latin1')
|
||||
|
||||
buf = bytearray(b"DTF")
|
||||
buf += tilewidth.to_bytes(4, byteorder='little')
|
||||
buf += tileheight.to_bytes(4, byteorder='little')
|
||||
buf += tilecount.to_bytes(4, byteorder='little')
|
||||
buf += columns.to_bytes(4, byteorder='little')
|
||||
buf += rows.to_bytes(4, byteorder='little')
|
||||
|
||||
# Write image source file name, padd to ASSET_FILE_NAME_MAX_LENGTH
|
||||
imageSourceBytes = image["outputFile"].encode('utf-8')
|
||||
data += len(imageSourceBytes).to_bytes(4, byteorder='little').decode('latin1')
|
||||
data += imageSourceBytes.decode('latin1')
|
||||
buf += len(imageSourceBytes).to_bytes(4, byteorder='little')
|
||||
buf += imageSourceBytes
|
||||
paddingLength = max(0, ASSET_FILE_NAME_MAX_LENGTH - len(imageSourceBytes))
|
||||
data += '\x00' * paddingLength
|
||||
buf += b'\x00' * paddingLength
|
||||
|
||||
# Write to output file
|
||||
fileNameWithoutExt = os.path.splitext(os.path.basename(assetPath))[0]
|
||||
outputFilePath = os.path.join(args.output_assets, relativeDir, f"{fileNameWithoutExt}.dtf")
|
||||
os.makedirs(os.path.dirname(outputFilePath), exist_ok=True)
|
||||
with open(outputFilePath, 'wb') as f:
|
||||
f.write(data.encode('latin1'))
|
||||
f.write(buf)
|
||||
|
||||
return {
|
||||
"outputFile": os.path.relpath(outputFilePath, args.output_assets),
|
||||
@@ -81,5 +77,6 @@ def processTileset(assetPath):
|
||||
"tileCount": tilecount,
|
||||
"columns": columns,
|
||||
"rows": rows,
|
||||
"image": image
|
||||
"image": image,
|
||||
"files": [ outputFilePath ] + image["files"]
|
||||
}
|
Reference in New Issue
Block a user