more item things
This commit is contained in:
@@ -15,8 +15,6 @@ class bcolors:
|
||||
BOLD = '\033[1m'
|
||||
UNDERLINE = '\033[4m'
|
||||
|
||||
def printHelp():
|
||||
print ('./generate-items -i <inputDir> -o <outputDir> -p <prefix>')
|
||||
|
||||
overWrite=False
|
||||
|
||||
@@ -30,6 +28,61 @@ inputDir = params[1]
|
||||
outputDir = params[2]
|
||||
itemPrefix = params[3]
|
||||
|
||||
def printHelp():
|
||||
print ('./generate-items -i <inputDir> -o <outputDir> -p <prefix>')
|
||||
|
||||
def generateItem(inputFile):
|
||||
baseName = itemPrefix + "_" + Path(inputFile).resolve().stem
|
||||
print(f"Generating: {bcolors.BOLD}{baseName}{bcolors.ENDC}")
|
||||
|
||||
generateImage(inputFile, baseName)
|
||||
|
||||
if(baseName.find("_inventario") != -1):
|
||||
return
|
||||
|
||||
generateESCScript(baseName)
|
||||
generateScene(baseName)
|
||||
|
||||
|
||||
|
||||
def generateImage(inputFile, baseName):
|
||||
|
||||
|
||||
originalImage = Image.open(inputFile)
|
||||
scale = 0.15
|
||||
newImage = originalImage.resize((math.ceil(originalImage.width * scale),math.ceil(originalImage.height * scale)))
|
||||
newImageOutputPath = outputDir + "assets/" + baseName + ".png"
|
||||
print(f"{bcolors.OKCYAN}Image:{bcolors.ENDC} {newImageOutputPath} {bcolors.OKGREEN}generated.{bcolors.ENDC}")
|
||||
newImage.save(newImageOutputPath)
|
||||
|
||||
def generateESCScript(baseName):
|
||||
|
||||
|
||||
scriptName = baseName + ".esc"
|
||||
scriptOutputPath = outputDir + scriptName
|
||||
if(os.path.isfile(scriptOutputPath) and not(overWrite)):
|
||||
print(f"{bcolors.OKCYAN}Script:{bcolors.ENDC} {scriptOutputPath} {bcolors.WARNING}already exists.{bcolors.ENDC}")
|
||||
return
|
||||
|
||||
print(f"{bcolors.OKCYAN}Script:{bcolors.ENDC} {scriptOutputPath} {bcolors.OKGREEN}generated.{bcolors.ENDC}")
|
||||
shutil.copy('item-template.esc', scriptOutputPath)
|
||||
|
||||
def generateScene(baseName):
|
||||
esceneName = baseName + ".tscn"
|
||||
esceneOutputPath = outputDir + esceneName
|
||||
if(os.path.isfile(esceneOutputPath) and not(overWrite)):
|
||||
print(f"{bcolors.OKCYAN}Scene:{bcolors.ENDC} {esceneOutputPath} {bcolors.WARNING}already exists.{bcolors.ENDC}")
|
||||
return
|
||||
|
||||
newScene = open(esceneOutputPath, mode='wt', encoding='utf-8')
|
||||
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}")
|
||||
|
||||
|
||||
|
||||
if inputDir == "":
|
||||
print ('Input directory is required')
|
||||
printHelp()
|
||||
@@ -52,40 +105,7 @@ esceneTemplate = esceneFile.read()
|
||||
|
||||
files = glob.glob(inputDir + "*.png")
|
||||
for file in files:
|
||||
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/" + baseName + ".png"
|
||||
print(f"{bcolors.OKCYAN}Image:{bcolors.ENDC} {newImageOutputPath} {bcolors.OKGREEN}generated.{bcolors.ENDC}")
|
||||
newImage.save(newImageOutputPath)
|
||||
|
||||
scriptName = baseName + ".esc"
|
||||
scriptOutputPath = outputDir + scriptName
|
||||
if(os.path.isfile(scriptOutputPath) and not(overWrite)):
|
||||
print(f"{bcolors.OKCYAN}Script:{bcolors.ENDC} {scriptOutputPath} {bcolors.WARNING}already exists.{bcolors.ENDC}")
|
||||
else:
|
||||
print(f"{bcolors.OKCYAN}Script:{bcolors.ENDC} {scriptOutputPath} {bcolors.OKGREEN}generated.{bcolors.ENDC}")
|
||||
shutil.copy('item-template.esc', scriptOutputPath)
|
||||
|
||||
|
||||
esceneName = baseName + ".tscn"
|
||||
esceneOutputPath = outputDir + esceneName
|
||||
|
||||
if(os.path.isfile(esceneOutputPath) and not(overWrite)):
|
||||
print(f"{bcolors.OKCYAN}Scene:{bcolors.ENDC} {esceneOutputPath} {bcolors.WARNING}already exists.{bcolors.ENDC}")
|
||||
else:
|
||||
newScene = open(esceneOutputPath, mode='wt', encoding='utf-8')
|
||||
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}")
|
||||
|
||||
generateItem(file)
|
||||
|
||||
esceneFile.close()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user