66 lines
1.8 KiB
Python
66 lines
1.8 KiB
Python
import sys, os
|
|
from assetstool.args import args
|
|
from assetstool.processasset import processAsset
|
|
from assetstool.processpalette import processPaletteList
|
|
from assetstool.processtileset import processTilesetList
|
|
from assetstool.processlanguage import processLanguageList
|
|
from assetstool.assethelpers import getBuiltAssetsRelativePath
|
|
import zipfile
|
|
|
|
# Parse input file args.
|
|
inputAssets = []
|
|
for inputArg in args.input:
|
|
files = inputArg.split('$')
|
|
for file in files:
|
|
if str(file).strip() == '':
|
|
continue
|
|
|
|
pieces = file.split('#')
|
|
|
|
if len(pieces) < 2:
|
|
print(f"Error: Invalid input asset format '{file}'. Expected format: type#path[#option1%option2...]")
|
|
sys.exit(1)
|
|
|
|
options = {}
|
|
if len(pieces) > 2:
|
|
optionParts = pieces[2].split('%')
|
|
for part in optionParts:
|
|
partSplit = part.split('=')
|
|
|
|
if len(partSplit) < 1:
|
|
continue
|
|
if len(partSplit) == 2:
|
|
options[partSplit[0]] = partSplit[1]
|
|
else:
|
|
options[partSplit[0]] = True
|
|
|
|
inputAssets.append({
|
|
'type': pieces[0],
|
|
'path': pieces[1],
|
|
'options': options
|
|
})
|
|
|
|
if not inputAssets:
|
|
print("Error: No input assets provided.")
|
|
sys.exit(1)
|
|
|
|
# Process each asset.
|
|
files = []
|
|
for asset in inputAssets:
|
|
asset = processAsset(asset)
|
|
files.extend(asset['files'])
|
|
|
|
# Generate additional files
|
|
files.extend(processLanguageList()['files'])
|
|
|
|
# Take assets and add to a zip archive.
|
|
outputFileName = args.output_file
|
|
print(f"Creating output file: {outputFileName}")
|
|
with zipfile.ZipFile(outputFileName, 'w') as zipf:
|
|
for file in files:
|
|
relativeOutputPath = getBuiltAssetsRelativePath(file)
|
|
zipf.write(file, arcname=relativeOutputPath)
|
|
|
|
# Generate additional headers.
|
|
processPaletteList()
|
|
processTilesetList() |