Also saving level resource with savegame.
parent
4612e79e1f
commit
89b39ae9b1
|
@ -1,7 +1,8 @@
|
|||
class_name SaveGame
|
||||
extends Resource
|
||||
|
||||
@export var player_transform:Transform3D
|
||||
@export var level:String
|
||||
@export var player_name:String
|
||||
@export var quest_states:Dictionary
|
||||
@export var player_transform:Transform3D
|
||||
@export var inventory:Array[Item]
|
||||
|
|
|
@ -15,6 +15,8 @@ var _root_ui_state:ROOT_UI_STATE = ROOT_UI_STATE.UNDEFINED
|
|||
var _all_recipes:Array[Recipe] = []
|
||||
var _player:Player = null
|
||||
|
||||
var current_level_resource:String
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
for file in DirAccess.get_files_at("res://data/recipes"):
|
||||
|
@ -47,7 +49,9 @@ func load_scene(scene_resource:PackedScene):
|
|||
child.queue_free()
|
||||
child.get_parent().remove_child(child)
|
||||
|
||||
print("Loading level '" + scene_resource.resource_path + "'")
|
||||
scene.add_child(scene_resource.instantiate())
|
||||
current_level_resource = scene_resource.resource_path
|
||||
|
||||
_player = scene.find_child("Player", true, false)
|
||||
|
||||
|
|
|
@ -4,8 +4,6 @@ extends Node3D
|
|||
@onready var message_container:Control = %MessagesContainer
|
||||
@onready var message_textedit:TextEdit = %MessageTextEdit
|
||||
|
||||
@onready var builder_missing_tool = %BuilderMissingTool
|
||||
|
||||
@onready var root_ui:RootUI = %RootUI
|
||||
|
||||
func save_game():
|
||||
|
@ -17,6 +15,7 @@ func save_game():
|
|||
|
||||
var save_game:SaveGame = SaveGame.new()
|
||||
|
||||
save_game.level = root_ui.current_level_resource
|
||||
save_game.player_transform = player.global_transform
|
||||
|
||||
for node:Node in get_tree().get_nodes_in_group("quest_state"):
|
||||
|
@ -33,14 +32,16 @@ func save_game():
|
|||
root_ui.activate_ui_panel(%GameUI)
|
||||
|
||||
func load_game():
|
||||
var save_game:SaveGame = load("user://savegame.tres") as SaveGame
|
||||
var level_resource:PackedScene = load(save_game.level)
|
||||
root_ui.load_scene(level_resource)
|
||||
|
||||
var player:Player = find_child("Player", true, false)
|
||||
|
||||
if player == null:
|
||||
push_error("Cannot load game: no player found!")
|
||||
return
|
||||
|
||||
var save_game:SaveGame = load("user://savegame.tres") as SaveGame
|
||||
|
||||
player.global_transform = save_game.player_transform
|
||||
|
||||
for node:Node in get_tree().get_nodes_in_group("quest_state"):
|
||||
|
|
Loading…
Reference in New Issue