2024-08-15 21:29:01 +02:00
|
|
|
class_name Main
|
2024-07-09 22:33:38 +02:00
|
|
|
extends Node3D
|
|
|
|
|
|
|
|
@onready var message_container:Control = %MessagesContainer
|
|
|
|
@onready var message_textedit:TextEdit = %MessageTextEdit
|
2024-07-20 11:20:18 +02:00
|
|
|
|
2024-08-02 01:03:40 +02:00
|
|
|
@onready var builder_missing_tool = %BuilderMissingTool
|
2024-07-20 11:20:18 +02:00
|
|
|
|
|
|
|
@onready var root_ui:RootUI = %RootUI
|
|
|
|
|
|
|
|
func save_game():
|
2024-08-15 22:15:24 +02:00
|
|
|
var player:Player = find_child("Player", true, false)
|
|
|
|
|
|
|
|
if player == null:
|
|
|
|
push_error("Cannot load game: no player found!")
|
|
|
|
return
|
|
|
|
|
2024-07-20 11:20:18 +02:00
|
|
|
var save_game:SaveGame = SaveGame.new()
|
|
|
|
|
|
|
|
save_game.player_transform = player.global_transform
|
|
|
|
|
2024-08-02 01:03:40 +02:00
|
|
|
for node:Node in get_tree().get_nodes_in_group("quest_state"):
|
|
|
|
save_game.quest_states[node.name] = {}
|
2024-08-15 22:15:24 +02:00
|
|
|
|
2024-08-02 01:03:40 +02:00
|
|
|
for property in node.get_property_list():
|
|
|
|
if (property.usage & PROPERTY_USAGE_STORAGE != 0) and (property.usage & PROPERTY_USAGE_SCRIPT_VARIABLE) != 0:
|
|
|
|
save_game.quest_states[node.name][property.name] = node.get(property.name)
|
|
|
|
|
2024-08-15 20:24:41 +02:00
|
|
|
for item in player.inventory.get_items():
|
|
|
|
save_game.inventory.append(item)
|
|
|
|
|
2024-07-20 11:20:18 +02:00
|
|
|
ResourceSaver.save(save_game, "user://savegame.tres")
|
|
|
|
root_ui.activate_ui_panel(%GameUI)
|
|
|
|
|
|
|
|
func load_game():
|
2024-08-15 22:15:24 +02:00
|
|
|
var player:Player = find_child("Player", true, false)
|
|
|
|
|
|
|
|
if player == null:
|
|
|
|
push_error("Cannot load game: no player found!")
|
|
|
|
return
|
|
|
|
|
2024-07-20 11:20:18 +02:00
|
|
|
var save_game:SaveGame = load("user://savegame.tres") as SaveGame
|
|
|
|
|
|
|
|
player.global_transform = save_game.player_transform
|
|
|
|
|
2024-08-02 01:03:40 +02:00
|
|
|
for node:Node in get_tree().get_nodes_in_group("quest_state"):
|
|
|
|
for property in node.get_property_list():
|
|
|
|
if (property.usage & PROPERTY_USAGE_STORAGE != 0) and (property.usage & PROPERTY_USAGE_SCRIPT_VARIABLE) != 0:
|
|
|
|
node.set(property.name, save_game.quest_states[node.name][property.name])
|
|
|
|
|
2024-08-15 20:24:41 +02:00
|
|
|
player.inventory.clear()
|
|
|
|
for item in save_game.inventory:
|
|
|
|
player.inventory.add_item(item)
|
|
|
|
|
2024-07-20 11:20:18 +02:00
|
|
|
root_ui.activate_ui_panel(%GameUI)
|
2024-08-02 00:06:50 +02:00
|
|
|
|