Added saving of inventory.

main
Martin Felis 2024-08-15 20:24:41 +02:00
parent 616dab80c7
commit bdfee0e94b
9 changed files with 141 additions and 150 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -2,7 +2,6 @@ extends Control
@onready var tool_slots = %ToolSlots @onready var tool_slots = %ToolSlots
@onready var game_menu_ui = %GameMenuUI @onready var game_menu_ui = %GameMenuUI
@onready var world = %World
func _on_message_timer_timeout(): func _on_message_timer_timeout():

View File

@ -14,6 +14,10 @@ func get_items() -> Array[Item]:
return _content return _content
func clear() -> void:
_content.clear()
func has_all(items:Array[Item]) -> bool: func has_all(items:Array[Item]) -> bool:
var needed:Array[Item] = items.duplicate() var needed:Array[Item] = items.duplicate()

View File

@ -4,3 +4,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 @export var quest_states:Dictionary
@export var inventory:Array[Item]

View File

@ -7,7 +7,7 @@
height = 0.2 height = 0.2
radius = 0.15682 radius = 0.15682
[node name="Item" type="Node3D"] [node name="Item" type="Node3D" groups=["pickup_item"]]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.00393829, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.00393829, 0)
script = ExtResource("1_1i8k2") script = ExtResource("1_1i8k2")
item = ExtResource("2_dph0g") item = ExtResource("2_dph0g")

View File

@ -21,6 +21,9 @@ func save_game():
if (property.usage & PROPERTY_USAGE_STORAGE != 0) and (property.usage & PROPERTY_USAGE_SCRIPT_VARIABLE) != 0: 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) save_game.quest_states[node.name][property.name] = node.get(property.name)
for item in player.inventory.get_items():
save_game.inventory.append(item)
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)
@ -34,5 +37,9 @@ func load_game():
if (property.usage & PROPERTY_USAGE_STORAGE != 0) and (property.usage & PROPERTY_USAGE_SCRIPT_VARIABLE) != 0: 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]) node.set(property.name, save_game.quest_states[node.name][property.name])
player.inventory.clear()
for item in save_game.inventory:
player.inventory.add_item(item)
root_ui.activate_ui_panel(%GameUI) root_ui.activate_ui_panel(%GameUI)

View File

@ -12,13 +12,13 @@
[ext_resource type="PackedScene" uid="uid://cgde10y3e7w86" path="res://assets/3rdparty/kenney/platformer-kit/Models/GLB format/rocks.glb" id="9_0hvyx"] [ext_resource type="PackedScene" uid="uid://cgde10y3e7w86" path="res://assets/3rdparty/kenney/platformer-kit/Models/GLB format/rocks.glb" id="9_0hvyx"]
[ext_resource type="PackedScene" uid="uid://dg1rtct0vrk3p" path="res://assets/3rdparty/kenney/platformer-kit/Models/GLB format/poles.glb" id="10_8fhnl"] [ext_resource type="PackedScene" uid="uid://dg1rtct0vrk3p" path="res://assets/3rdparty/kenney/platformer-kit/Models/GLB format/poles.glb" id="10_8fhnl"]
[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="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://quests/builder_missing_tool_quest.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"]
[ext_resource type="Theme" uid="uid://dmk7hc81l8gbw" path="res://ui/ui_theme.tres" id="17_1odts"] [ext_resource type="Theme" uid="uid://dmk7hc81l8gbw" path="res://ui/ui_theme.tres" id="17_1odts"]
[ext_resource type="Script" path="res://quests/scared_to_walk_in_the_dark.gd" id="18_7v3bk"]
[ext_resource type="Script" path="res://game_ui.gd" id="18_i4pxl"] [ext_resource type="Script" path="res://game_ui.gd" id="18_i4pxl"]
[ext_resource type="Script" path="res://ui/game_menu_ui.gd" id="18_lr26g"] [ext_resource type="Script" path="res://ui/game_menu_ui.gd" id="18_lr26g"]
[ext_resource type="Texture2D" uid="uid://c7fu3paj3b4e8" path="res://assets/3rdparty/kenney/ui-pack-rpg-expansion/PNG/cursorSword_silver.png" id="19_mn7wc"] [ext_resource type="Texture2D" uid="uid://c7fu3paj3b4e8" path="res://assets/3rdparty/kenney/ui-pack-rpg-expansion/PNG/cursorSword_silver.png" id="19_mn7wc"]
@ -135,9 +135,6 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.851, 0, 0.798104)
unique_name_in_owner = true unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.375699, -0.115042, 0) 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")]
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"] [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")
@ -176,6 +173,9 @@ transform = Transform3D(1, 0, 0, 0, 0.460138, 0.887848, 0, -0.887848, 0.460138,
unique_name_in_owner = true unique_name_in_owner = true
script = ExtResource("14_g3xjj") script = ExtResource("14_g3xjj")
[node name="ScaredToWalkInTheDark" type="Node" parent="GameScene/Quests" groups=["quest_state"]]
script = ExtResource("18_7v3bk")
[node name="RootUI" type="CanvasLayer" parent="."] [node name="RootUI" type="CanvasLayer" parent="."]
unique_name_in_owner = true unique_name_in_owner = true
script = ExtResource("16_winq7") script = ExtResource("16_winq7")

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=16 format=3 uid="uid://dmagdl5pi6jdj"] [gd_scene load_steps=15 format=3 uid="uid://dmagdl5pi6jdj"]
[ext_resource type="MeshLibrary" uid="uid://dcpuitbu16j1a" path="res://assets/mesh_library.tres" id="1_q0eym"] [ext_resource type="MeshLibrary" uid="uid://dcpuitbu16j1a" path="res://assets/mesh_library.tres" id="1_q0eym"]
[ext_resource type="PackedScene" uid="uid://da5r82nvypfk4" path="res://objects/pickup_item.tscn" id="2_qurr0"] [ext_resource type="PackedScene" uid="uid://da5r82nvypfk4" path="res://objects/pickup_item.tscn" id="2_qurr0"]
@ -7,7 +7,6 @@
[ext_resource type="Resource" uid="uid://egkatj1ci0ga" path="res://data/items/wrench.tres" id="5_tmrcc"] [ext_resource type="Resource" uid="uid://egkatj1ci0ga" path="res://data/items/wrench.tres" id="5_tmrcc"]
[ext_resource type="Resource" uid="uid://coser1y1y5unl" path="res://data/items/door.tres" id="5_twsf3"] [ext_resource type="Resource" uid="uid://coser1y1y5unl" path="res://data/items/door.tres" id="5_twsf3"]
[ext_resource type="PackedScene" uid="uid://ca2l61b2j3y5b" path="res://assets/tools/Pickaxe.tscn" id="6_fq3ct"] [ext_resource type="PackedScene" uid="uid://ca2l61b2j3y5b" path="res://assets/tools/Pickaxe.tscn" id="6_fq3ct"]
[ext_resource type="PackedScene" uid="uid://ysfnsrvgemi6" path="res://assets/resources/wood_planks.tscn" id="8_4vlpe"]
[ext_resource type="Resource" uid="uid://c1ll2snhgv3m1" path="res://data/items/treelog.tres" id="8_pafka"] [ext_resource type="Resource" uid="uid://c1ll2snhgv3m1" path="res://data/items/treelog.tres" id="8_pafka"]
[ext_resource type="PackedScene" uid="uid://bbmt7xom1j84b" path="res://assets/resources/tree_log.tscn" id="9_51v1q"] [ext_resource type="PackedScene" uid="uid://bbmt7xom1j84b" path="res://assets/resources/tree_log.tscn" id="9_51v1q"]
[ext_resource type="PackedScene" uid="uid://dnobr4inhiskv" path="res://assets/3rdparty/kenney/platformer-kit/Models/GLB format/tree-pine.glb" id="11_ldjca"] [ext_resource type="PackedScene" uid="uid://dnobr4inhiskv" path="res://assets/3rdparty/kenney/platformer-kit/Models/GLB format/tree-pine.glb" id="11_ldjca"]
@ -25,9 +24,9 @@ mesh_library = ExtResource("1_q0eym")
cell_size = Vector3(0.5, 0.5, 0.5) cell_size = Vector3(0.5, 0.5, 0.5)
cell_center_y = false cell_center_y = false
data = { data = {
"cells": PackedInt32Array(1, 65534, 655374, 65534, 65534, 655374, 65534, 65531, 655374, 1, 65531, 655374, 4, 65534, 655374, 4, 65531, 655374, 65534, 1, 655374, 1, 1, 655374, 4, 1, 655374, 7, 1, 655374, 7, 65534, 655374, 7, 65531, 655374, 7, 65528, 655374, 4, 65528, 655374, 1, 65528, 655374, 65534, 65528, 655374, 13, 1, 1048590, 13, 65534, 1048590, 13, 65531, 1048590, 13, 65528, 1048590, 65531, 65528, 1048590, 65531, 65531, 1048590, 65531, 65534, 1048590, 65531, 1, 1048590, 65531, 65525, 1048590, 65534, 65525, 1048590, 1, 65525, 1048590, 4, 65525, 1048590, 7, 65525, 1048590, 13, 65525, 1048590, 7, 65522, 1048590, 4, 65522, 1048590, 1, 65522, 1048590, 65534, 65522, 1048590, 65531, 65522, 1048590, 65531, 4, 1048590, 65534, 4, 1048590, 1, 4, 1048590, 4, 4, 1048590, 7, 4, 1048590, 65543, 65527, 9, 65541, 65527, 9, 65538, 65527, 9, 131067, 65527, 9, 131066, 65529, 1441801, 131066, 65532, 1441801, 131066, 65535, 1441801, 131066, 1, 1441801, 131066, 4, 1441801, 131068, 5, 655369, 131071, 5, 655369, 65538, 5, 655369, 65541, 5, 655369, 65543, 5, 9, 65544, 4, 1441801, 65544, 1, 1441801) "cells": PackedInt32Array(1, 65534, 655374, 65534, 65534, 655374, 65534, 65531, 655374, 1, 65531, 655374, 4, 65534, 655374, 4, 65531, 655374, 65534, 1, 655374, 1, 1, 655374, 4, 1, 655374, 7, 1, 655374, 7, 65534, 655374, 7, 65531, 655374, 7, 65528, 655374, 4, 65528, 655374, 1, 65528, 655374, 65534, 65528, 655374, 13, 1, 1048590, 13, 65534, 1048590, 13, 65531, 1048590, 13, 65528, 1048590, 65531, 65528, 1048590, 65531, 65531, 1048590, 65531, 65534, 1048590, 65531, 1, 1048590, 65531, 65525, 1048590, 65534, 65525, 1048590, 1, 65525, 1048590, 4, 65525, 1048590, 7, 65525, 1048590, 13, 65525, 1048590, 7, 65522, 1048590, 4, 65522, 1048590, 1, 65522, 1048590, 65534, 65522, 1048590, 65531, 65522, 1048590, 65531, 4, 1048590, 65534, 4, 1048590, 1, 4, 1048590, 4, 4, 1048590, 7, 4, 1048590, 65543, 65527, 9, 65541, 65527, 9, 65538, 65527, 9, 131067, 65527, 9, 131066, 65529, 1441801, 131066, 65532, 1441801, 131066, 65535, 1441801, 131066, 1, 1441801, 131066, 4, 1441801, 131068, 5, 655369, 131071, 5, 655369, 65538, 5, 655369, 65541, 5, 655369, 65543, 5, 9, 65544, 4, 1441801, 65544, 1, 1441801, 15, 65521, 13, 15, 65522, 13, 15, 65523, 13, 15, 65524, 13, 15, 65525, 13, 15, 65526, 13, 16, 65527, 13, 16, 65528, 13, 15, 65528, 13, 15, 65529, 13, 15, 65530, 13)
} }
metadata/_editor_floor_ = Vector3(0, 1, 0) metadata/_editor_floor_ = Vector3(0, 0, 0)
[node name="Objects" type="Node3D" parent="."] [node name="Objects" type="Node3D" parent="."]
@ -47,11 +46,6 @@ item = ExtResource("5_twsf3")
[node name="_Node3D_153924" parent="Objects/Item4" instance=ExtResource("6_fq3ct")] [node name="_Node3D_153924" parent="Objects/Item4" instance=ExtResource("6_fq3ct")]
[node name="Item2" parent="Objects" instance=ExtResource("2_qurr0")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.978853, -2.38419e-07, -1.39068)
[node name="_Node3D_153925" parent="Objects/Item2" instance=ExtResource("8_4vlpe")]
[node name="Item3" parent="Objects" instance=ExtResource("2_qurr0")] [node name="Item3" parent="Objects" instance=ExtResource("2_qurr0")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.28455, 0, -0.204204) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.28455, 0, -0.204204)
item = ExtResource("8_pafka") item = ExtResource("8_pafka")