item generator script fix
This commit is contained in:
@@ -18,6 +18,8 @@ class bcolors:
|
||||
def printHelp():
|
||||
print ('./generate-items -i <inputDir> -o <outputDir> -p <prefix>')
|
||||
|
||||
overWrite=False
|
||||
|
||||
params = sys.argv
|
||||
print(params)
|
||||
if(len(params) < 4):
|
||||
@@ -45,44 +47,47 @@ if(outputDir[-1] != "/"):
|
||||
outputDir += "/"
|
||||
|
||||
|
||||
escenteTemplate = open('./item-template.tscn')
|
||||
esceneFile = open('./item-template.tscn')
|
||||
esceneTemplate = esceneFile.read()
|
||||
|
||||
files = glob.glob(inputDir + "*.png")
|
||||
for file in files:
|
||||
baseName = Path(file).resolve().stem
|
||||
baseName = itemPrefix + "_" + Path(file).resolve().stem
|
||||
|
||||
print(f"Generating: {bcolors.BOLD}{baseName}{bcolors.ENDC}")
|
||||
|
||||
|
||||
originalImage = Image.open(file)
|
||||
scale = 0.15
|
||||
newImage = originalImage.resize((math.ceil(originalImage.width * scale),math.ceil(originalImage.height * scale)))
|
||||
newImageOutputPath = outputDir + "assets/" + itemPrefix + "_" + baseName + ".png"
|
||||
newImageOutputPath = outputDir + "assets/" + baseName + ".png"
|
||||
print(f"{bcolors.OKCYAN}Image:{bcolors.ENDC} {newImageOutputPath} {bcolors.OKGREEN}generated.{bcolors.ENDC}")
|
||||
newImage.save(newImageOutputPath)
|
||||
|
||||
scriptName = itemPrefix + "_" + baseName + ".esc"
|
||||
scriptName = baseName + ".esc"
|
||||
scriptOutputPath = outputDir + scriptName
|
||||
if(os.path.isfile(scriptOutputPath)):
|
||||
if(os.path.isfile(scriptOutputPath) and not(overWrite)):
|
||||
print(f"{bcolors.OKCYAN}Script:{bcolors.ENDC} {scriptOutputPath} {bcolors.WARNING}already exists.{bcolors.ENDC}")
|
||||
shutil.copy('item-template.esc', scriptOutputPath)
|
||||
else:
|
||||
print(f"{bcolors.OKCYAN}Script:{bcolors.ENDC} {scriptOutputPath} {bcolors.OKGREEN}generated.{bcolors.ENDC}")
|
||||
shutil.copy('item-template.esc', scriptOutputPath)
|
||||
|
||||
|
||||
esceneName = itemPrefix + "_" + baseName + ".tscn"
|
||||
esceneName = baseName + ".tscn"
|
||||
esceneOutputPath = outputDir + esceneName
|
||||
|
||||
if(os.path.isfile(esceneOutputPath)):
|
||||
if(os.path.isfile(esceneOutputPath) and not(overWrite)):
|
||||
print(f"{bcolors.OKCYAN}Scene:{bcolors.ENDC} {esceneOutputPath} {bcolors.WARNING}already exists.{bcolors.ENDC}")
|
||||
shutil.copy('item-template.esc', scriptOutputPath)
|
||||
else:
|
||||
newScene = open(esceneOutputPath, mode='wt', encoding='utf-8')
|
||||
newScene.write(escenteTemplate.read().replace('BASENAME', baseName))
|
||||
newSceneTemplate = esceneTemplate
|
||||
newSceneTemplate = newSceneTemplate.replace("BASENAME", baseName)
|
||||
newScene.write(newSceneTemplate)
|
||||
newScene.close()
|
||||
print(f"{bcolors.OKCYAN}Scene:{bcolors.ENDC} {esceneOutputPath} {bcolors.OKGREEN}generated.{bcolors.ENDC}")
|
||||
|
||||
|
||||
escenteTemplate.close()
|
||||
esceneFile.close()
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user