diff --git a/scripts/generate-items.py b/scripts/generate-items.py new file mode 100755 index 00000000..6750424a --- /dev/null +++ b/scripts/generate-items.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python3 + +import shutil, sys, glob, os, math +from pathlib import Path +from PIL import Image + +class bcolors: + HEADER = '\033[95m' + OKBLUE = '\033[94m' + OKCYAN = '\033[96m' + OKGREEN = '\033[92m' + WARNING = '\033[93m' + FAIL = '\033[91m' + ENDC = '\033[0m' + BOLD = '\033[1m' + UNDERLINE = '\033[4m' + +def printHelp(): + print ('./generate-items -i -o -p ') + +params = sys.argv +print(params) +if(len(params) < 4): + print("Missing params") + sys.exit() + +inputDir = params[1] +outputDir = params[2] +itemPrefix = params[3] + +if inputDir == "": + print ('Input directory is required') + printHelp() + sys.exit() +if outputDir == "": + print ('Output directory is required') + printHelp() + sys.exit() +if itemPrefix == "": + print ('Item prefix is required') + printHelp() + sys.exit() + +if(outputDir[-1] != "/"): + outputDir += "/" + + +escenteTemplate = open('./item-template.tscn') + +files = glob.glob(inputDir + "*.png") +for file in files: + baseName = 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" + print(f"{bcolors.OKCYAN}Image:{bcolors.ENDC} {newImageOutputPath} {bcolors.OKGREEN}generated.{bcolors.ENDC}") + newImage.save(newImageOutputPath) + + scriptName = itemPrefix + "_" + baseName + ".esc" + scriptOutputPath = outputDir + scriptName + if(os.path.isfile(scriptOutputPath)): + 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}") + + + esceneName = itemPrefix + "_" + baseName + ".tscn" + esceneOutputPath = outputDir + esceneName + + if(os.path.isfile(esceneOutputPath)): + 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)) + newScene.close() + print(f"{bcolors.OKCYAN}Scene:{bcolors.ENDC} {esceneOutputPath} {bcolors.OKGREEN}generated.{bcolors.ENDC}") + + +escenteTemplate.close() + + + + + diff --git a/scripts/item-template.esc b/scripts/item-template.esc new file mode 100644 index 00000000..db47f32c --- /dev/null +++ b/scripts/item-template.esc @@ -0,0 +1,6 @@ +:action1 +say player "Que cosa tan curiosa" + +:action2 +say player "No lo quiero coger" + diff --git a/scripts/item-template.tscn b/scripts/item-template.tscn new file mode 100644 index 00000000..7329c3c4 --- /dev/null +++ b/scripts/item-template.tscn @@ -0,0 +1,34 @@ +[gd_scene load_steps=5 format=2] + +[ext_resource path="res://gymkhana/addons/escoria-ui-return-monkey-island/esc_item_with_tooltip.gd" type="Script" id=1] +[ext_resource path="res://gymkhana/items/inventory/assets/BASENAME.png" type="Texture" id=2] +[ext_resource path="res://addons/escoria-core/game/core-scripts/esc_location.gd" type="Script" id=3] + +[sub_resource type="RectangleShape2D" id=1] +extents = Vector2( 22.5, 12.5 ) + +[node name="BASENAME" type="Area2D"] +pause_mode = 1 +script = ExtResource( 1 ) +global_id = "BASENAME" +esc_script = "res://gymkhana/items/inventory/BASENAME.esc" +inventory_texture = ExtResource( 2 ) +dialog_color = Color( 1, 1, 1, 1 ) +action1_text = "¿Que es esto?" +action2_text = "Coger" +action3_text = "Mirar" +action4_text = "Usar" +animations = null + +[node name="Sprite" type="Sprite" parent="."] +position = Vector2( -2, 0 ) +scale = Vector2( 0.5, 0.5 ) +texture = ExtResource( 2 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +position = Vector2( -1.5, -0.5 ) +shape = SubResource( 1 ) + +[node name="ESCLocation" type="Position2D" parent="."] +position = Vector2( -51, 69 ) +script = ExtResource( 3 ) \ No newline at end of file