44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
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 |