Lua script something
This commit is contained in:
39
tools/assetstool/processscript.py
Normal file
39
tools/assetstool/processscript.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import sys
|
||||
import os
|
||||
from assetstool.args import args
|
||||
from assetstool.assetcache import assetCache, assetGetCache
|
||||
from assetstool.assethelpers import getAssetRelativePath
|
||||
from dusk.defs import defs
|
||||
|
||||
def processScript(asset):
|
||||
cache = assetGetCache(asset['path'])
|
||||
if cache is not None:
|
||||
return cache
|
||||
|
||||
# Load the lua file as a string
|
||||
with open(asset['path'], 'r', encoding='utf-8') as f:
|
||||
luaCode = f.read()
|
||||
|
||||
# TODO: I will precompile or minify the Lua code here in the future
|
||||
|
||||
# Create output Dusk Script File (DSF) data
|
||||
data = ""
|
||||
data += "DSF"
|
||||
data += luaCode
|
||||
|
||||
# Write to relative output file path.
|
||||
relative = getAssetRelativePath(asset['path'])
|
||||
fileNameWithoutExt = os.path.splitext(os.path.basename(asset['path']))[0]
|
||||
outputFileRelative = os.path.join(os.path.dirname(relative), f"{fileNameWithoutExt}.dsf")
|
||||
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.encode('utf-8'))
|
||||
|
||||
outScript = {
|
||||
'data': data,
|
||||
'path': asset['path'],
|
||||
'files': [ outputFilePath ],
|
||||
'scriptPath': outputFileRelative,
|
||||
}
|
||||
return assetCache(asset['path'], outScript)
|
||||
Reference in New Issue
Block a user