2024-06-14 09:44:34 +02:00
|
|
|
extends Node
|
|
|
|
|
2024-06-18 18:58:47 +02:00
|
|
|
# Reference to the inputOutput.tscn scene
|
2024-06-16 19:32:19 +02:00
|
|
|
var field = preload("res://scenes/menu/inputOutput.tscn")
|
2024-06-18 18:58:47 +02:00
|
|
|
|
|
|
|
# Variable to store loaded JSON data
|
2024-06-18 19:17:42 +02:00
|
|
|
var data
|
2024-06-15 21:56:18 +02:00
|
|
|
|
2024-06-18 18:58:47 +02:00
|
|
|
# Called when the node is added to the scene
|
2024-06-15 21:56:18 +02:00
|
|
|
func _ready():
|
2024-06-18 18:58:47 +02:00
|
|
|
# Load JSON data from stats.json
|
|
|
|
data = Load.loadJSON("res://content/stats.json")
|
|
|
|
|
|
|
|
# Instantiate input fields based on 'amount' from data
|
|
|
|
for i in range(int(data.get("amount"))):
|
|
|
|
var fieldInstance = field.instance()
|
|
|
|
$"ScrollContainer/VBoxContainer".add_child(fieldInstance)
|
|
|
|
|
|
|
|
# Set position, placeholder text, and minimum size for each field
|
|
|
|
$"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-15 21:56:18 +02:00
|
|
|
|
2024-06-18 18:58:47 +02:00
|
|
|
# Handler for when a button is pressed
|
2024-06-18 19:17:42 +02:00
|
|
|
func _on_button_pressed():
|
2024-06-18 18:58:47 +02:00
|
|
|
# Construct save path based on user input
|
|
|
|
var savePath = "user://player_data" + $"ScrollContainer/VBoxContainer".get_child(0).text + ".json"
|
|
|
|
|
|
|
|
# Prepare data to save
|
|
|
|
var saveData = {}
|
|
|
|
for i in range(int(data.get("amount"))):
|
|
|
|
if i > 0:
|
|
|
|
saveData[data.get(str(i))] = $"ScrollContainer/VBoxContainer".get_child(i).text
|
|
|
|
|
|
|
|
# Save data to JSON file
|
|
|
|
Save.saveJSON(savePath, saveData)
|
2024-06-15 20:33:37 +02:00
|
|
|
|
2024-06-18 18:58:47 +02:00
|
|
|
# Process function called every frame
|
2024-06-15 20:33:37 +02:00
|
|
|
func _process(delta):
|
2024-06-18 18:58:47 +02:00
|
|
|
# Check if the Escape key is pressed to change scene to main.tscn
|
|
|
|
if Input.is_action_pressed("escape"):
|
|
|
|
get_tree().change_scene_to_file("res://scenes/menu/main.tscn")
|