Quest state is now properly saved.

main
Martin Felis 2024-08-02 01:03:40 +02:00
parent 6c59b551dc
commit 616dab80c7
7 changed files with 22 additions and 6 deletions

View File

@ -3,3 +3,4 @@ extends Resource
@export var player_transform:Transform3D @export var player_transform:Transform3D
@export var player_name:String @export var player_name:String
@export var quest_states:Dictionary

View File

@ -6,7 +6,7 @@ const JUMP_VELOCITY = 2.5
@onready var geometry = %Geometry @onready var geometry = %Geometry
@onready var actionable_detector = %ActionableDetector @onready var actionable_detector = %ActionableDetector
@onready var quest_state = %QuestState @onready var quest_state = %BuilderMissingTool
@onready var bridge = %Bridge @onready var bridge = %Bridge
# Get the gravity from the project settings to be synced with RigidBody nodes. # Get the gravity from the project settings to be synced with RigidBody nodes.

View File

@ -10,7 +10,7 @@ config_version=5
[application] [application]
config/name="UIAndInteractionTests" config/name="TinyBuildAdventure"
run/main_scene="res://scenes/game.tscn" run/main_scene="res://scenes/game.tscn"
config/features=PackedStringArray("4.2", "Forward Plus") config/features=PackedStringArray("4.2", "Forward Plus")
config/icon="res://icon.svg" config/icon="res://icon.svg"

View File

@ -18,7 +18,7 @@ func _ready():
var recipe:Recipe = load(resource_file) as Recipe var recipe:Recipe = load(resource_file) as Recipe
_all_recipes.append(recipe) _all_recipes.append(recipe)
set_root_ui_state(ROOT_UI_STATE.MENU) set_root_ui_state(ROOT_UI_STATE.GAME)
func activate_ui_panel(ui_panel:Control): func activate_ui_panel(ui_panel:Control):
for control in ui_panels: for control in ui_panels:

View File

@ -5,6 +5,7 @@ extends Node3D
@onready var message_textedit:TextEdit = %MessageTextEdit @onready var message_textedit:TextEdit = %MessageTextEdit
@onready var player = %Player @onready var player = %Player
@onready var builder_missing_tool = %BuilderMissingTool
@onready var root_ui:RootUI = %RootUI @onready var root_ui:RootUI = %RootUI
@ -13,6 +14,13 @@ func save_game():
save_game.player_transform = player.global_transform save_game.player_transform = player.global_transform
for node:Node in get_tree().get_nodes_in_group("quest_state"):
save_game.quest_states[node.name] = {}
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)
ResourceSaver.save(save_game, "user://savegame.tres") ResourceSaver.save(save_game, "user://savegame.tres")
root_ui.activate_ui_panel(%GameUI) root_ui.activate_ui_panel(%GameUI)
@ -21,5 +29,10 @@ func load_game():
player.global_transform = save_game.player_transform player.global_transform = save_game.player_transform
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])
root_ui.activate_ui_panel(%GameUI) root_ui.activate_ui_panel(%GameUI)

View File

@ -14,7 +14,7 @@
[ext_resource type="PackedScene" uid="uid://cej0a41nm3eh7" path="res://assets/3rdparty/kenney/platformer-kit/Models/GLB format/mushrooms.glb" id="11_ytfwt"] [ext_resource type="PackedScene" uid="uid://cej0a41nm3eh7" path="res://assets/3rdparty/kenney/platformer-kit/Models/GLB format/mushrooms.glb" id="11_ytfwt"]
[ext_resource type="PackedScene" uid="uid://kpyvcyklt68g" path="res://assets/scene_props/bridge.tscn" id="12_ybrl7"] [ext_resource type="PackedScene" uid="uid://kpyvcyklt68g" path="res://assets/scene_props/bridge.tscn" id="12_ybrl7"]
[ext_resource type="Script" path="res://player.gd" id="13_2wo8v"] [ext_resource type="Script" path="res://player.gd" id="13_2wo8v"]
[ext_resource type="Script" path="res://model/quest_state.gd" id="14_g3xjj"] [ext_resource type="Script" path="res://quests/builder_missing_tool_quest.gd" id="14_g3xjj"]
[ext_resource type="PackedScene" uid="uid://dy8vjf760prhq" path="res://assets/characters/rogue.tscn" id="15_2476h"] [ext_resource type="PackedScene" uid="uid://dy8vjf760prhq" path="res://assets/characters/rogue.tscn" id="15_2476h"]
[ext_resource type="PackedScene" uid="uid://bo788o53t4rbq" path="res://scenes/startup_scene.tscn" id="16_7jwuc"] [ext_resource type="PackedScene" uid="uid://bo788o53t4rbq" path="res://scenes/startup_scene.tscn" id="16_7jwuc"]
[ext_resource type="Script" path="res://root_ui.gd" id="16_winq7"] [ext_resource type="Script" path="res://root_ui.gd" id="16_winq7"]
@ -138,7 +138,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.375699, -0.115042, 0)
[node name="BridgePart2" parent="GameScene/Bridge" instance=ExtResource("12_ybrl7")] [node name="BridgePart2" parent="GameScene/Bridge" instance=ExtResource("12_ybrl7")]
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 5.723, 0.0837148, -1.439) transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 5.723, 0.0837148, -1.439)
[node name="Player" type="CharacterBody3D" parent="GameScene" groups=["savable_nodes"]] [node name="Player" type="CharacterBody3D" parent="GameScene"]
unique_name_in_owner = true unique_name_in_owner = true
script = ExtResource("13_2wo8v") script = ExtResource("13_2wo8v")
@ -170,7 +170,9 @@ shape = SubResource("SphereShape3D_wrkyq")
unique_name_in_owner = true unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 0.460138, 0.887848, 0, -0.887848, 0.460138, 0, 2.91421, 1.186) transform = Transform3D(1, 0, 0, 0, 0.460138, 0.887848, 0, -0.887848, 0.460138, 0, 2.91421, 1.186)
[node name="QuestState" type="Node" parent="GameScene/Player"] [node name="Quests" type="Node" parent="GameScene"]
[node name="BuilderMissingTool" type="Node" parent="GameScene/Quests" groups=["quest_state"]]
unique_name_in_owner = true unique_name_in_owner = true
script = ExtResource("14_g3xjj") script = ExtResource("14_g3xjj")