2024-06-14 09:44:34 +02:00
|
|
|
extends Node
|
|
|
|
|
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-19 18:27:40 +02:00
|
|
|
var amount
|
2024-06-15 21:56:18 +02:00
|
|
|
|
2024-06-19 18:27:40 +02:00
|
|
|
# Get all needed things for Ui.placeFields and save amount from it.
|
2024-06-15 21:56:18 +02:00
|
|
|
func _ready():
|
2024-06-19 18:27:40 +02:00
|
|
|
data = Content.data
|
|
|
|
var container = $"ScrollContainer/VBoxContainer"
|
|
|
|
Ui.placeFields(data, container, true)
|
|
|
|
amount = data.get("amount")
|
2024-06-15 21:56:18 +02:00
|
|
|
|
2024-06-19 18:27:40 +02:00
|
|
|
# Upon pressing the "Send" button
|
2024-06-18 19:17:42 +02:00
|
|
|
func _on_button_pressed():
|
2024-06-19 18:27:40 +02:00
|
|
|
# Create the save path based on which ID was entered
|
|
|
|
var savePath = "user://player_" + $"ScrollContainer/VBoxContainer".get_child(0).text + ".json"
|
|
|
|
|
|
|
|
# Get data from the fields to save, except the first one, which is the ID and should be used in the filename.
|
|
|
|
var saveData = {}
|
|
|
|
for i in range(int(data.get("amount"))):
|
|
|
|
if i > 0:
|
|
|
|
saveData[data.get(str(i))] = $"ScrollContainer/VBoxContainer".get_child(i).text
|
|
|
|
|
|
|
|
# Call the global save function
|
|
|
|
Save.saveJSON(savePath, saveData)
|
2024-06-15 20:33:37 +02:00
|
|
|
|
2024-06-19 18:27:40 +02:00
|
|
|
# Only for the Main Menu "shortcut"
|
2024-06-15 20:33:37 +02:00
|
|
|
func _process(delta):
|
2024-06-19 18:27:40 +02:00
|
|
|
if Input.is_action_pressed("escape"):
|
|
|
|
get_tree().change_scene_to_file("res://scenes/menu/main.tscn")
|