feature/save_and_loaaaaaad #32
@@ -34,6 +34,7 @@ stream_3/stream = ExtResource("9_dltn0")
|
|||||||
z_index = 1
|
z_index = 1
|
||||||
y_sort_enabled = true
|
y_sort_enabled = true
|
||||||
script = ExtResource("1_tlhp6")
|
script = ExtResource("1_tlhp6")
|
||||||
|
metadata/SaveID = ""
|
||||||
|
|
||||||
[node name="SpawnWithItem" type="Node" parent="."]
|
[node name="SpawnWithItem" type="Node" parent="."]
|
||||||
script = ExtResource("3_xu8me")
|
script = ExtResource("3_xu8me")
|
||||||
|
|||||||
@@ -1069,6 +1069,7 @@ shape = SubResource("CircleShape2D_p6n74")
|
|||||||
|
|
||||||
[node name="CanGenericPickup" parent="YSorted" instance=ExtResource("25_hukxv")]
|
[node name="CanGenericPickup" parent="YSorted" instance=ExtResource("25_hukxv")]
|
||||||
position = Vector2(8192, 3507)
|
position = Vector2(8192, 3507)
|
||||||
|
metadata/SaveID = "5a823507-8107-40ce-8b32-6d0f81a3c44e"
|
||||||
|
|
||||||
[node name="SpawnWithItem" parent="YSorted/CanGenericPickup" index="0"]
|
[node name="SpawnWithItem" parent="YSorted/CanGenericPickup" index="0"]
|
||||||
_blueprint = ExtResource("28_ipqaa")
|
_blueprint = ExtResource("28_ipqaa")
|
||||||
@@ -1086,6 +1087,7 @@ offset = Vector2(0, -50)
|
|||||||
|
|
||||||
[node name="RakeGenericPickup" parent="YSorted" instance=ExtResource("25_hukxv")]
|
[node name="RakeGenericPickup" parent="YSorted" instance=ExtResource("25_hukxv")]
|
||||||
position = Vector2(8391, 2060)
|
position = Vector2(8391, 2060)
|
||||||
|
metadata/SaveID = "e13886b1-2131-4072-bc06-7d8abb19357b"
|
||||||
|
|
||||||
[node name="SpawnWithItem" parent="YSorted/RakeGenericPickup" index="0"]
|
[node name="SpawnWithItem" parent="YSorted/RakeGenericPickup" index="0"]
|
||||||
_blueprint = ExtResource("28_6b2nr")
|
_blueprint = ExtResource("28_6b2nr")
|
||||||
@@ -1100,15 +1102,13 @@ shape = SubResource("CircleShape2D_tm0yg")
|
|||||||
|
|
||||||
[node name="SeedPickup" parent="YSorted" instance=ExtResource("25_hukxv")]
|
[node name="SeedPickup" parent="YSorted" instance=ExtResource("25_hukxv")]
|
||||||
position = Vector2(9927, 2257)
|
position = Vector2(9927, 2257)
|
||||||
_infiniteSupply = true
|
|
||||||
_finiteSupply = 3
|
_finiteSupply = 3
|
||||||
|
metadata/SaveID = "e1bbe13f-0622-42b8-97f3-87a8af369dc0"
|
||||||
|
|
||||||
[node name="SpawnWithItem" parent="YSorted/SeedPickup" index="0"]
|
[node name="SpawnWithItem" parent="YSorted/SeedPickup" index="0"]
|
||||||
_blueprint = ExtResource("35_64mdn")
|
_blueprint = ExtResource("35_64mdn")
|
||||||
|
|
||||||
[node name="PickupInteractionArea" parent="YSorted/SeedPickup" index="3" node_paths=PackedStringArray("_spritesToOutline")]
|
[node name="PickupInteractionArea" parent="YSorted/SeedPickup" index="3"]
|
||||||
_outlineMaterial = null
|
|
||||||
_spritesToOutline = []
|
|
||||||
metadata/SaveID = "ad152c51-3631-42c1-9aa4-4df896b35d8c"
|
metadata/SaveID = "ad152c51-3631-42c1-9aa4-4df896b35d8c"
|
||||||
|
|
||||||
[node name="CollisionShape3D" parent="YSorted/SeedPickup/PickupInteractionArea/Area2D" index="0"]
|
[node name="CollisionShape3D" parent="YSorted/SeedPickup/PickupInteractionArea/Area2D" index="0"]
|
||||||
@@ -1120,13 +1120,12 @@ scale = Vector2(1, 1)
|
|||||||
[node name="SeedPickup2" parent="YSorted" instance=ExtResource("25_hukxv")]
|
[node name="SeedPickup2" parent="YSorted" instance=ExtResource("25_hukxv")]
|
||||||
position = Vector2(10705, 2257)
|
position = Vector2(10705, 2257)
|
||||||
_finiteSupply = 3
|
_finiteSupply = 3
|
||||||
|
metadata/SaveID = "77972c50-63a7-461a-bc7d-6fa46333bc5c"
|
||||||
|
|
||||||
[node name="SpawnWithItem" parent="YSorted/SeedPickup2" index="0"]
|
[node name="SpawnWithItem" parent="YSorted/SeedPickup2" index="0"]
|
||||||
_blueprint = ExtResource("36_fv1t2")
|
_blueprint = ExtResource("36_fv1t2")
|
||||||
|
|
||||||
[node name="PickupInteractionArea" parent="YSorted/SeedPickup2" index="3" node_paths=PackedStringArray("_spritesToOutline")]
|
[node name="PickupInteractionArea" parent="YSorted/SeedPickup2" index="3"]
|
||||||
_outlineMaterial = null
|
|
||||||
_spritesToOutline = []
|
|
||||||
metadata/SaveID = "09e115e7-1d21-485a-be3e-b3fff9c83e78"
|
metadata/SaveID = "09e115e7-1d21-485a-be3e-b3fff9c83e78"
|
||||||
|
|
||||||
[node name="CollisionShape3D" parent="YSorted/SeedPickup2/PickupInteractionArea/Area2D" index="0"]
|
[node name="CollisionShape3D" parent="YSorted/SeedPickup2/PickupInteractionArea/Area2D" index="0"]
|
||||||
|
|||||||
@@ -63,6 +63,8 @@ public partial class ItemOnGround2D : Node, ISaveable
|
|||||||
{
|
{
|
||||||
QueueFree();
|
QueueFree();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateSaveData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,7 +94,14 @@ public partial class ItemOnGround2D : Node, ISaveable
|
|||||||
|
|
||||||
public void UpdateSaveData()
|
public void UpdateSaveData()
|
||||||
{
|
{
|
||||||
// do nothing?
|
var payloadData = new Dictionary<string, Variant>
|
||||||
|
{
|
||||||
|
{"pickupCounter", pickUpCounter}
|
||||||
|
};
|
||||||
|
|
||||||
|
string id = GetMeta("SaveID").AsString();
|
||||||
|
GD.Print($"Updating Save ID for object {Name}: {id}");
|
||||||
|
SavegameService.AppendDataToSave( id, payloadData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadFromSaveData()
|
public void LoadFromSaveData()
|
||||||
@@ -100,6 +109,26 @@ public partial class ItemOnGround2D : Node, ISaveable
|
|||||||
if (_infiniteSupply)
|
if (_infiniteSupply)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// standard check: how many times has this item been collected?
|
||||||
|
string id = GetMeta("SaveID").AsString();
|
||||||
|
GD.Print($"Loading Save ID for object {Name}: " + id);
|
||||||
|
|
||||||
|
Dictionary<string, Variant> save = SavegameService.GetSaveData(id);
|
||||||
|
if (save.Count > 0)
|
||||||
|
{
|
||||||
|
if(save.TryGetValue("pickupCounter", out Variant countVar))
|
||||||
|
{
|
||||||
|
int count = countVar.AsInt32();
|
||||||
|
GD.Print($"Item count for {Name}: {count}");
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
Pickup();
|
||||||
|
GD.Print($"Picking up {Name}: {i}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//separate check for unique items: If already in inventory, delete this instance.
|
||||||
ItemResource itemResource = itemInstance.blueprint;
|
ItemResource itemResource = itemInstance.blueprint;
|
||||||
Dictionary<string, Variant> savegameData = SavegameService.GetSaveData(InventoryInstance.ID);
|
Dictionary<string, Variant> savegameData = SavegameService.GetSaveData(InventoryInstance.ID);
|
||||||
if (savegameData.Count > 0)
|
if (savegameData.Count > 0)
|
||||||
@@ -121,7 +150,6 @@ public partial class ItemOnGround2D : Node, ISaveable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user