Add exec command
This commit is contained in:
@@ -2,6 +2,7 @@ import sys
|
||||
# from processtileset import processTileset
|
||||
from processimage import processImage
|
||||
from processpalette import processPalette
|
||||
from processconfig import processConfig
|
||||
|
||||
processedAssets = []
|
||||
|
||||
@@ -17,6 +18,8 @@ def processAsset(asset):
|
||||
return processPalette(asset)
|
||||
elif t == 'image':
|
||||
return processImage(asset)
|
||||
elif t == 'config':
|
||||
return processConfig(asset)
|
||||
# elif t == 'tileset':
|
||||
# return processTileset(asset)
|
||||
else:
|
||||
|
44
tools/assetstool/processconfig.py
Normal file
44
tools/assetstool/processconfig.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import os
|
||||
import sys
|
||||
from args import args
|
||||
from assethelpers import getAssetRelativePath
|
||||
|
||||
def processConfig(asset):
|
||||
assetPath = asset['path']
|
||||
print(f"Processing config: {assetPath}")
|
||||
|
||||
# Takes each line, seperates it by either semicolon or newline,
|
||||
# trims whitespace. Then outputs it to a file.
|
||||
with open(assetPath, "r") as f:
|
||||
lines = f.read().replace('\r', '').split('\n')
|
||||
|
||||
commands = []
|
||||
for line in lines:
|
||||
lineCommands = line.split(';')
|
||||
for command in lineCommands:
|
||||
command = command.strip()
|
||||
if command != '':
|
||||
commands.append(command)
|
||||
|
||||
data = bytearray()
|
||||
data.extend(b"DCF") # Dusk Config File
|
||||
for command in commands:
|
||||
# Convert to string and seperate each command with semicolon
|
||||
data.extend(command.encode('utf-8'))
|
||||
data.append(0x3B) # Semicolon
|
||||
|
||||
if len(commands) > 0:
|
||||
data.pop() # Remove last semicolon
|
||||
|
||||
relative = getAssetRelativePath(assetPath)
|
||||
fileNameWithoutExt = os.path.splitext(os.path.basename(assetPath))[0]
|
||||
outputFileRelative = os.path.join(os.path.dirname(relative), f"{fileNameWithoutExt}.dcf")
|
||||
outputFilePath = os.path.join(args.output_assets, outputFileRelative)
|
||||
os.makedirs(os.path.dirname(outputFilePath), exist_ok=True)
|
||||
with open(outputFilePath, "wb") as f:
|
||||
f.write(data)
|
||||
|
||||
outConfig = {
|
||||
"files": [ outputFilePath ],
|
||||
}
|
||||
return outConfig
|
Reference in New Issue
Block a user