2024-06-15 20:33:37 +02:00
|
|
|
extends Node
|
|
|
|
|
2024-06-19 18:27:40 +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
|
|
|
var amount
|
|
|
|
|
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, false)
|
|
|
|
amount = data.get("amount")
|
2024-06-15 20:33:37 +02:00
|
|
|
|
2024-06-19 18:27:40 +02:00
|
|
|
# Upon pressing the "Get" button, also called in game
|
2024-06-15 20:33:37 +02:00
|
|
|
func _on_button_pressed():
|
2024-06-19 18:27:40 +02:00
|
|
|
# Construct save path based on user input
|
|
|
|
var savePath = "user://player_" + $"ScrollContainer/VBoxContainer".get_child(0).text + ".json"
|
|
|
|
|
|
|
|
# Load JSON data from the constructed save path
|
|
|
|
data = Load.loadJSON(savePath)
|
|
|
|
|
|
|
|
# Check if data is successfully loaded (type 27 corresponds to Dictionary in Godot, although the wiki says it's 18...)
|
|
|
|
if typeof(data) == 27:
|
|
|
|
# Populate fields with loaded data
|
|
|
|
for i in range(int(amount) - 1):
|
|
|
|
$"ScrollContainer/VBoxContainer".get_child(i + 1).text = data.get(str($"ScrollContainer/VBoxContainer".get_child(i + 1).placeholder_text))
|
2024-06-15 20:33:37 +02:00
|
|
|
|
2024-06-19 18:27:40 +02:00
|
|
|
# Only for the Main Menu "shortcut"
|
2024-06-16 20:01:56 +02:00
|
|
|
func _process(_delta):
|
2024-06-19 18:27:40 +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")
|
|
|
|
|
2024-06-18 18:58:47 +02:00
|
|
|
# Function to hide the 'get' button
|
2024-06-16 19:32:19 +02:00
|
|
|
func hideGet():
|
2024-06-19 18:27:40 +02:00
|
|
|
$button.visible = false
|
|
|
|
$button.disabled = true
|