Saving of pickup items works.
parent
89b39ae9b1
commit
c240b0d74c
|
@ -6,3 +6,4 @@ extends Resource
|
|||
@export var quest_states:Dictionary
|
||||
@export var player_transform:Transform3D
|
||||
@export var inventory:Array[Item]
|
||||
@export var level_pickup_items:Array[NodePath]
|
||||
|
|
|
@ -4,6 +4,8 @@ extends Node3D
|
|||
|
||||
var editor_child_scene:Node3D = null
|
||||
|
||||
signal item_picked_up(node_path:NodePath)
|
||||
|
||||
@export var item:Item:
|
||||
get:
|
||||
return item
|
||||
|
@ -30,4 +32,5 @@ func _ready():
|
|||
func _on_area_3d_body_entered(body):
|
||||
if body.has_method("on_item_picked_up"):
|
||||
body.on_item_picked_up(item)
|
||||
emit_signal("item_picked_up", get_path())
|
||||
queue_free()
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://da5r82nvypfk4"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://da5r82nvypfk4"]
|
||||
|
||||
[ext_resource type="Script" path="res://objects/pickup_item.gd" id="1_1i8k2"]
|
||||
[ext_resource type="Resource" uid="uid://dmjr6pmb17l2y" path="res://data/items/woodplanks.tres" id="2_dph0g"]
|
||||
[ext_resource type="PackedScene" uid="uid://ysfnsrvgemi6" path="res://assets/resources/wood_planks.tscn" id="3_fvgmq"]
|
||||
|
||||
[sub_resource type="CylinderShape3D" id="CylinderShape3D_1ndog"]
|
||||
height = 0.2
|
||||
|
@ -12,6 +13,8 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.00393829, 0)
|
|||
script = ExtResource("1_1i8k2")
|
||||
item = ExtResource("2_dph0g")
|
||||
|
||||
[node name="Planks" type="Node3D" parent="." instance=ExtResource("3_fvgmq")]
|
||||
|
||||
[node name="Area3D" type="Area3D" parent="."]
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D"]
|
||||
|
|
|
@ -53,6 +53,9 @@ func load_scene(scene_resource:PackedScene):
|
|||
scene.add_child(scene_resource.instantiate())
|
||||
current_level_resource = scene_resource.resource_path
|
||||
|
||||
for pickup_item in get_tree().get_nodes_in_group("pickup_item"):
|
||||
pickup_item.connect("item_picked_up", get_parent().on_item_pickup)
|
||||
|
||||
_player = scene.find_child("Player", true, false)
|
||||
|
||||
if _player:
|
||||
|
|
|
@ -124,5 +124,3 @@ script = ExtResource("14_g3xjj")
|
|||
|
||||
[node name="ScaredToWalkInTheDark" type="Node" parent="Quests" groups=["quest_state"]]
|
||||
script = ExtResource("18_7v3bk")
|
||||
|
||||
[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"]
|
||||
|
|
|
@ -6,6 +6,8 @@ extends Node3D
|
|||
|
||||
@onready var root_ui:RootUI = %RootUI
|
||||
|
||||
var _picked_up_level_items:Array[NodePath] = []
|
||||
|
||||
func save_game():
|
||||
var player:Player = find_child("Player", true, false)
|
||||
|
||||
|
@ -16,6 +18,7 @@ func save_game():
|
|||
var save_game:SaveGame = SaveGame.new()
|
||||
|
||||
save_game.level = root_ui.current_level_resource
|
||||
save_game.level_pickup_items = _picked_up_level_items
|
||||
save_game.player_transform = player.global_transform
|
||||
|
||||
for node:Node in get_tree().get_nodes_in_group("quest_state"):
|
||||
|
@ -32,6 +35,8 @@ func save_game():
|
|||
root_ui.activate_ui_panel(%GameUI)
|
||||
|
||||
func load_game():
|
||||
_picked_up_level_items.clear()
|
||||
|
||||
var save_game:SaveGame = load("user://savegame.tres") as SaveGame
|
||||
var level_resource:PackedScene = load(save_game.level)
|
||||
root_ui.load_scene(level_resource)
|
||||
|
@ -44,14 +49,25 @@ func load_game():
|
|||
|
||||
player.global_transform = save_game.player_transform
|
||||
|
||||
# Quest state
|
||||
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])
|
||||
|
||||
# Inventory
|
||||
player.inventory.clear()
|
||||
for item in save_game.inventory:
|
||||
player.inventory.add_item(item)
|
||||
|
||||
# Picked up items
|
||||
for item_path in save_game.level_pickup_items:
|
||||
if get_tree().root.has_node(item_path):
|
||||
var item_node = get_tree().root.get_node(item_path)
|
||||
_picked_up_level_items.append(item_path)
|
||||
item_node.queue_free()
|
||||
|
||||
root_ui.activate_ui_panel(%GameUI)
|
||||
|
||||
func on_item_pickup(node_path:NodePath):
|
||||
_picked_up_level_items.append(node_path)
|
||||
|
|
Loading…
Reference in New Issue