Added trash object savestate
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
[gd_scene load_steps=17 format=3 uid="uid://sbf12hin4kes"]
|
||||
[gd_scene load_steps=18 format=3 uid="uid://sbf12hin4kes"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://bylgmr0skwtrs" path="res://art/farm/farming/farmobjekte/broken tools atlas.png" id="1_k4ca3"]
|
||||
[ext_resource type="PackedScene" uid="uid://cqc72e4hq6bcd" path="res://prefabs/interactions/interaction_area_2d.tscn" id="2_gcgfd"]
|
||||
[ext_resource type="Script" uid="uid://c2cgj153m05sp" path="res://scripts/CSharp/Common/Interactables/TrashObject.cs" id="2_u7jgg"]
|
||||
[ext_resource type="AudioStream" uid="uid://be6g8b3v3u1ai" path="res://audio/sfx/Kitchen/SFX_Cooking_Knife_PickUp_01.wav" id="3_ktmp7"]
|
||||
[ext_resource type="AudioStream" uid="uid://cgjsajsdrrn0j" path="res://audio/sfx/Kitchen/SFX_Cooking_Knife_PutDown_01.wav" id="4_ic616"]
|
||||
[ext_resource type="AudioStream" uid="uid://br4drgupled6c" path="res://audio/sfx/Kitchen/SFX_Cooking_Pot_01.wav" id="5_dx175"]
|
||||
@@ -29,13 +30,15 @@ stream_7/stream = ExtResource("10_aqih4")
|
||||
stream_8/stream = ExtResource("11_kb03l")
|
||||
stream_9/stream = ExtResource("12_kka6u")
|
||||
|
||||
[node name="trashObject" type="Sprite2D"]
|
||||
[node name="trashObject" type="Sprite2D" groups=["Saveable"]]
|
||||
z_index = 1
|
||||
y_sort_enabled = true
|
||||
texture = ExtResource("1_k4ca3")
|
||||
offset = Vector2(1, -215)
|
||||
region_enabled = true
|
||||
region_rect = Rect2(44, 479, 356, 503)
|
||||
script = ExtResource("2_u7jgg")
|
||||
metadata/SaveID = ""
|
||||
|
||||
[node name="InteractionArea" parent="." node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("2_gcgfd")]
|
||||
position = Vector2(0, -172)
|
||||
@@ -51,6 +54,6 @@ script = ExtResource("13_wswkg")
|
||||
script = ExtResource("14_dx175")
|
||||
_eventResources = Array[Object]([ExtResource("15_u7jgg")])
|
||||
|
||||
[connection signal="Interacted" from="InteractionArea" to="." method="queue_free"]
|
||||
[connection signal="Interacted" from="InteractionArea" to="." method="Collect"]
|
||||
[connection signal="Interacted" from="InteractionArea" to="AudioStreamPlayer2D" method="PlayOneShot"]
|
||||
[connection signal="Interacted" from="InteractionArea" to="PickupAnimationEventRaiser" method="RaiseEvents"]
|
||||
|
||||
@@ -2302,6 +2302,7 @@ position = Vector2(-569, -42)
|
||||
z_index = 0
|
||||
y_sort_enabled = false
|
||||
position = Vector2(1269, 3170)
|
||||
metadata/SaveID = "f6bf35b0-a145-4a8d-a946-38dc6ee53507"
|
||||
|
||||
[node name="trashObject2" parent="YSorted/trash" instance=ExtResource("53_j4nx2")]
|
||||
z_index = 0
|
||||
@@ -2309,10 +2310,7 @@ y_sort_enabled = false
|
||||
position = Vector2(3183, 2369)
|
||||
offset = Vector2(1, -50)
|
||||
region_rect = Rect2(207, 1184, 149, 142)
|
||||
|
||||
[node name="InteractionArea" parent="YSorted/trash/trashObject2" index="0"]
|
||||
position = Vector2(-9, -46)
|
||||
metadata/SaveID = "549bbcf4-ea57-4b8f-80b1-b13ca648559b"
|
||||
metadata/SaveID = "1b175e9c-f4a6-4b30-b024-95ab1a6c4ec7"
|
||||
|
||||
[node name="trashObject3" parent="YSorted/trash" instance=ExtResource("53_j4nx2")]
|
||||
z_index = 0
|
||||
@@ -2320,10 +2318,7 @@ y_sort_enabled = false
|
||||
position = Vector2(4724, 3519)
|
||||
offset = Vector2(1, -50)
|
||||
region_rect = Rect2(400, 1053, 163, 141)
|
||||
|
||||
[node name="InteractionArea" parent="YSorted/trash/trashObject3" index="0"]
|
||||
position = Vector2(-13, -53)
|
||||
metadata/SaveID = "29874314-50c1-4a21-9494-18f936d6e097"
|
||||
metadata/SaveID = "28770149-73d5-45bd-b760-6e84a07c59b8"
|
||||
|
||||
[node name="trashObject4" parent="YSorted/trash" instance=ExtResource("53_j4nx2")]
|
||||
z_index = 0
|
||||
@@ -2331,10 +2326,7 @@ y_sort_enabled = false
|
||||
position = Vector2(5385, 3391)
|
||||
offset = Vector2(1, -50)
|
||||
region_rect = Rect2(1048, 1092, 348, 106)
|
||||
|
||||
[node name="InteractionArea" parent="YSorted/trash/trashObject4" index="0"]
|
||||
position = Vector2(0, -59)
|
||||
metadata/SaveID = "7ccaa831-5526-40ed-8ca3-31ba2ad929a6"
|
||||
metadata/SaveID = "1cbdfeb5-68d4-4489-896e-7879e7baa26f"
|
||||
|
||||
[node name="trashObject5" parent="YSorted/trash" instance=ExtResource("53_j4nx2")]
|
||||
z_index = 0
|
||||
@@ -2342,6 +2334,7 @@ y_sort_enabled = false
|
||||
position = Vector2(8051, 2541)
|
||||
offset = Vector2(1, -50)
|
||||
region_rect = Rect2(531, 1207, 176, 167)
|
||||
metadata/SaveID = "b6bdce90-0b79-45c8-a2d1-3078a58d3314"
|
||||
|
||||
[node name="trashObject6" parent="YSorted/trash" instance=ExtResource("53_j4nx2")]
|
||||
z_index = 0
|
||||
@@ -2349,11 +2342,13 @@ y_sort_enabled = false
|
||||
position = Vector2(9629, 3312)
|
||||
offset = Vector2(1, -50)
|
||||
region_rect = Rect2(207, 1184, 149, 142)
|
||||
metadata/SaveID = "391ab18e-e9a5-4a52-bf3b-c30b7dde60f3"
|
||||
|
||||
[node name="trashObject7" parent="YSorted/trash" instance=ExtResource("53_j4nx2")]
|
||||
z_index = 0
|
||||
y_sort_enabled = false
|
||||
position = Vector2(12050, 3391)
|
||||
metadata/SaveID = "e4a2eaa4-6f91-4d12-ae2e-161442a0c71e"
|
||||
|
||||
[node name="trashObject8" parent="YSorted/trash" instance=ExtResource("53_j4nx2")]
|
||||
z_index = 0
|
||||
@@ -2361,6 +2356,7 @@ y_sort_enabled = false
|
||||
position = Vector2(14589, 2505)
|
||||
rotation = 1.77025
|
||||
region_rect = Rect2(629, 81, 227, 829)
|
||||
metadata/SaveID = "cbd5b6e3-a2da-4d3f-a6d0-209ec433755b"
|
||||
|
||||
[node name="trashObject9" parent="YSorted/trash" instance=ExtResource("53_j4nx2")]
|
||||
z_index = 0
|
||||
@@ -2369,10 +2365,7 @@ position = Vector2(15322, 3472)
|
||||
rotation = 1.77025
|
||||
offset = Vector2(0, 0)
|
||||
region_rect = Rect2(1048, 1092, 348, 106)
|
||||
|
||||
[node name="InteractionArea" parent="YSorted/trash/trashObject9" index="0"]
|
||||
position = Vector2(22.40873, 25.05658)
|
||||
metadata/SaveID = "7bf227d6-3844-41e9-a9cd-524052aced3b"
|
||||
metadata/SaveID = "9db3ecb6-5392-4545-bb06-f701579460ea"
|
||||
|
||||
[node name="CanvasLayer" parent="." instance=ExtResource("54_233a1")]
|
||||
|
||||
@@ -2527,8 +2520,4 @@ script = ExtResource("79_m37ba")
|
||||
[editable path="YSorted/SeedPickup2"]
|
||||
[editable path="YSorted/SeedPickup2/PickupInteractionArea"]
|
||||
[editable path="YSorted/Blocker/InteractionArea"]
|
||||
[editable path="YSorted/trash/trashObject2"]
|
||||
[editable path="YSorted/trash/trashObject3"]
|
||||
[editable path="YSorted/trash/trashObject4"]
|
||||
[editable path="YSorted/trash/trashObject9"]
|
||||
[editable path="CanvasLayer"]
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
using Godot;
|
||||
using Babushka.scripts.CSharp.Common.Savegame;
|
||||
using Godot.Collections;
|
||||
|
||||
/// <summary>
|
||||
/// Simple collectible scene objects with saveable state.
|
||||
/// </summary>
|
||||
public partial class TrashObject : Sprite2D, ISaveable
|
||||
{
|
||||
private bool _collected;
|
||||
|
||||
/// <summary>
|
||||
/// Loads objects state on scene start.
|
||||
/// </summary>
|
||||
public override void _Ready()
|
||||
{
|
||||
LoadFromSaveData();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets object state to collected and updates save data.
|
||||
/// </summary>
|
||||
public void Collect()
|
||||
{
|
||||
SetCollectedState();
|
||||
UpdateSaveData();
|
||||
}
|
||||
|
||||
private void SetCollectedState()
|
||||
{
|
||||
_collected = true;
|
||||
Visible = false;
|
||||
ProcessMode = ProcessModeEnum.Disabled;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the save data with the current state of the object.
|
||||
/// </summary>
|
||||
public void UpdateSaveData()
|
||||
{
|
||||
var payloadData = new Dictionary<string, Variant>
|
||||
{
|
||||
{ "collectedState", _collected },
|
||||
};
|
||||
|
||||
string id = GetMeta("SaveID").AsString();
|
||||
SavegameService.AppendDataToSave( id, payloadData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads objects state from save data.
|
||||
/// </summary>
|
||||
public void LoadFromSaveData()
|
||||
{
|
||||
string id = GetMeta("SaveID").AsString();
|
||||
|
||||
Dictionary<string, Variant> save = SavegameService.GetSaveData(id);
|
||||
if (save.Count > 0)
|
||||
{
|
||||
if (save.TryGetValue("collectedState", out Variant collectedVar))
|
||||
{
|
||||
if (collectedVar.AsBool())
|
||||
{
|
||||
SetCollectedState();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://c2cgj153m05sp
|
||||
@@ -1,6 +1,4 @@
|
||||
using System.Threading.Tasks;
|
||||
using Babushka.scripts.CSharp.Common.Savegame;
|
||||
using Babushka.scripts.CSharp.Low_Code.Variables;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user