freettrpg/scripts/createStats.gd

26 lines
978 B
GDScript3
Raw Normal View History

2024-06-14 09:44:34 +02:00
extends Node
var field = preload("res://scenes/menu/inputOutput.tscn")
2024-06-18 19:17:42 +02:00
var data
func _ready():
2024-06-18 19:17:42 +02:00
data = Load.loadJSON("res://content/stats.json")
for i in range(int(data.get("amount"))):
var fieldInstance = field.instantiate()
$"ScrollContainer/VBoxContainer".add_child(fieldInstance)
$"ScrollContainer/VBoxContainer".get_child(i).position = Vector2(16,(16+i*88))
$"ScrollContainer/VBoxContainer".get_child(i).placeholder_text = data.get(str(i))
$"ScrollContainer/VBoxContainer".get_child(i).custom_minimum_size.y = 40
2024-06-18 19:17:42 +02:00
func _on_button_pressed():
var savePath = str("user://player_data"+$"ScrollContainer/VBoxContainer".get_child(0).text+".json")
var saveData = {}
for i in range(int(data.get("amount"))):
if i > 0:
saveData[data.get(str(i))] = $"ScrollContainer/VBoxContainer".get_child(i).text
2024-06-18 19:17:42 +02:00
Save.saveJSON(savePath, saveData)
func _process(delta):
if Input.is_action_pressed("escape"):
get_tree().change_scene_to_file("res://scenes/menu/main.tscn")