Compare commits
3 Commits
4ed6f4e7d9
...
bee6249c6f
| Author | SHA1 | Date | |
|---|---|---|---|
| bee6249c6f | |||
| fda2b95b38 | |||
| 4bbaab1a2a |
@@ -160,9 +160,11 @@ libraries = {
|
|||||||
&"": SubResource("AnimationLibrary_54k4r")
|
&"": SubResource("AnimationLibrary_54k4r")
|
||||||
}
|
}
|
||||||
|
|
||||||
[node name="InteractionArea" parent="." node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("15_uo3dh")]
|
[node name="InteractionArea" parent="." instance=ExtResource("15_uo3dh")]
|
||||||
position = Vector2(18, -250)
|
position = Vector2(18, -250)
|
||||||
_spritesToOutline = [NodePath("../Duck rendered")]
|
_sceneKeyProvider = null
|
||||||
|
_saveId = "f99549a9-c97e-45a4-b3c9-4bac23fe6fe7"
|
||||||
|
_outlineMaterial = null
|
||||||
|
|
||||||
[node name="CollisionShape3D" parent="InteractionArea/Area2D" index="0"]
|
[node name="CollisionShape3D" parent="InteractionArea/Area2D" index="0"]
|
||||||
shape = SubResource("CircleShape2D_uo3dh")
|
shape = SubResource("CircleShape2D_uo3dh")
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
[gd_scene load_steps=117 format=3 uid="uid://gigb28qk8t12"]
|
[gd_scene load_steps=121 format=3 uid="uid://gigb28qk8t12"]
|
||||||
|
|
||||||
[ext_resource type="PackedScene" uid="uid://c25udixd5m6l0" path="res://prefabs/characters/Player2D.tscn" id="1_7wfwe"]
|
[ext_resource type="PackedScene" uid="uid://c25udixd5m6l0" path="res://prefabs/characters/Player2D.tscn" id="1_7wfwe"]
|
||||||
[ext_resource type="Texture2D" uid="uid://8sr11ex30n0m" path="res://art/mockups/Kenney_Backgrounds/Samples/uncolored_hills.png" id="2_7b2ri"]
|
[ext_resource type="Texture2D" uid="uid://8sr11ex30n0m" path="res://art/mockups/Kenney_Backgrounds/Samples/uncolored_hills.png" id="2_7b2ri"]
|
||||||
@@ -236,6 +236,20 @@ shader_parameter/value_mult = 1.0
|
|||||||
shader_parameter/brightness_add = 0.0
|
shader_parameter/brightness_add = 0.0
|
||||||
shader_parameter/contrast_mult = 1.0
|
shader_parameter/contrast_mult = 1.0
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id="CircleShape2D_065st"]
|
||||||
|
resource_local_to_scene = true
|
||||||
|
radius = 200.0
|
||||||
|
|
||||||
|
[sub_resource type="ViewportTexture" id="ViewportTexture_w1kgo"]
|
||||||
|
viewport_path = NodePath("SubViewport")
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id="CircleShape2D_w1kgo"]
|
||||||
|
resource_local_to_scene = true
|
||||||
|
radius = 200.0
|
||||||
|
|
||||||
|
[sub_resource type="ViewportTexture" id="ViewportTexture_q1g8e"]
|
||||||
|
viewport_path = NodePath("SubViewport")
|
||||||
|
|
||||||
[sub_resource type="AudioStreamPlaylist" id="AudioStreamPlaylist_ceriq"]
|
[sub_resource type="AudioStreamPlaylist" id="AudioStreamPlaylist_ceriq"]
|
||||||
loop = false
|
loop = false
|
||||||
stream_count = 1
|
stream_count = 1
|
||||||
@@ -2243,7 +2257,6 @@ position = Vector2(-113.561, 193.035)
|
|||||||
shape = SubResource("RectangleShape2D_2vojv")
|
shape = SubResource("RectangleShape2D_2vojv")
|
||||||
|
|
||||||
[node name="ducks" type="Node2D" parent="YSorted"]
|
[node name="ducks" type="Node2D" parent="YSorted"]
|
||||||
visible = false
|
|
||||||
z_index = 1
|
z_index = 1
|
||||||
y_sort_enabled = true
|
y_sort_enabled = true
|
||||||
script = ExtResource("49_uxa2m")
|
script = ExtResource("49_uxa2m")
|
||||||
@@ -2255,12 +2268,24 @@ y_sort_enabled = false
|
|||||||
position = Vector2(4374, 2652)
|
position = Vector2(4374, 2652)
|
||||||
_penTarget = NodePath("../../pen/penSlot1")
|
_penTarget = NodePath("../../pen/penSlot1")
|
||||||
|
|
||||||
|
[node name="CollisionShape3D" parent="YSorted/ducks/Duck2/InteractionArea/Area2D" index="0"]
|
||||||
|
shape = SubResource("CircleShape2D_065st")
|
||||||
|
|
||||||
|
[node name="Duck rendered" parent="YSorted/ducks/Duck2" index="3"]
|
||||||
|
texture = SubResource("ViewportTexture_w1kgo")
|
||||||
|
|
||||||
[node name="Duck3" parent="YSorted/ducks" node_paths=PackedStringArray("_penTarget") instance=ExtResource("62_i36hd")]
|
[node name="Duck3" parent="YSorted/ducks" node_paths=PackedStringArray("_penTarget") instance=ExtResource("62_i36hd")]
|
||||||
z_index = 0
|
z_index = 0
|
||||||
y_sort_enabled = false
|
y_sort_enabled = false
|
||||||
position = Vector2(9259, 3194)
|
position = Vector2(9259, 3194)
|
||||||
_penTarget = NodePath("../../pen/penSlot2")
|
_penTarget = NodePath("../../pen/penSlot2")
|
||||||
|
|
||||||
|
[node name="CollisionShape3D" parent="YSorted/ducks/Duck3/InteractionArea/Area2D" index="0"]
|
||||||
|
shape = SubResource("CircleShape2D_w1kgo")
|
||||||
|
|
||||||
|
[node name="Duck rendered" parent="YSorted/ducks/Duck3" index="3"]
|
||||||
|
texture = SubResource("ViewportTexture_q1g8e")
|
||||||
|
|
||||||
[node name="Duck4" parent="YSorted/ducks" node_paths=PackedStringArray("_penTarget") instance=ExtResource("62_i36hd")]
|
[node name="Duck4" parent="YSorted/ducks" node_paths=PackedStringArray("_penTarget") instance=ExtResource("62_i36hd")]
|
||||||
z_index = 0
|
z_index = 0
|
||||||
y_sort_enabled = false
|
y_sort_enabled = false
|
||||||
@@ -2544,6 +2569,10 @@ script = ExtResource("79_065st")
|
|||||||
[editable path="YSorted/SeedPickup2"]
|
[editable path="YSorted/SeedPickup2"]
|
||||||
[editable path="YSorted/SeedPickup2/PickupInteractionArea"]
|
[editable path="YSorted/SeedPickup2/PickupInteractionArea"]
|
||||||
[editable path="YSorted/Blocker/InteractionArea"]
|
[editable path="YSorted/Blocker/InteractionArea"]
|
||||||
|
[editable path="YSorted/ducks/Duck2"]
|
||||||
|
[editable path="YSorted/ducks/Duck2/InteractionArea"]
|
||||||
|
[editable path="YSorted/ducks/Duck3"]
|
||||||
|
[editable path="YSorted/ducks/Duck3/InteractionArea"]
|
||||||
[editable path="YSorted/trash/trashObject2"]
|
[editable path="YSorted/trash/trashObject2"]
|
||||||
[editable path="YSorted/trash/trashObject3"]
|
[editable path="YSorted/trash/trashObject3"]
|
||||||
[editable path="YSorted/trash/trashObject4"]
|
[editable path="YSorted/trash/trashObject4"]
|
||||||
|
|||||||
@@ -1,13 +1,20 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Babushka.scripts.CSharp.Common.Savegame;
|
||||||
using Babushka.scripts.CSharp.Common.Services;
|
using Babushka.scripts.CSharp.Common.Services;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using Godot.Collections;
|
||||||
|
|
||||||
namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
||||||
|
|
||||||
public partial class InteractionArea2D : Node2D
|
[Tool]
|
||||||
|
public partial class InteractionArea2D : Node2D, ISaveable
|
||||||
{
|
{
|
||||||
|
[ExportGroup("Persistence")]
|
||||||
|
[Export] public Babushka.scripts.CSharp.Low_Code.Variables.VariableResource _sceneKeyProvider;
|
||||||
|
[Export] private string _saveId;
|
||||||
|
|
||||||
|
[ExportGroup("Settings")]
|
||||||
[Export] private Area2D _area;
|
[Export] private Area2D _area;
|
||||||
[Export] private Label _label;
|
[Export] private Label _label;
|
||||||
[Export] private bool _active = true;
|
[Export] private bool _active = true;
|
||||||
@@ -18,6 +25,7 @@ public partial class InteractionArea2D : Node2D
|
|||||||
[Export] private int _id = -1; // TODO: remove
|
[Export] private int _id = -1; // TODO: remove
|
||||||
|
|
||||||
private Material[] _backupMaterials;
|
private Material[] _backupMaterials;
|
||||||
|
private int _interactionCounter;
|
||||||
|
|
||||||
[Signal] public delegate void InteractedToolEventHandler(int id); // TODO: remove
|
[Signal] public delegate void InteractedToolEventHandler(int id); // TODO: remove
|
||||||
|
|
||||||
@@ -40,9 +48,10 @@ public partial class InteractionArea2D : Node2D
|
|||||||
{
|
{
|
||||||
_backupMaterials = _spritesToOutline.Select(s => s.Material).ToArray();
|
_backupMaterials = _spritesToOutline.Select(s => s.Material).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LoadFromSaveData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void OnPlayerEntered(Node2D player)
|
public void OnPlayerEntered(Node2D player)
|
||||||
{
|
{
|
||||||
if (!_active || !InputService.Instance.InputEnabled)
|
if (!_active || !InputService.Instance.InputEnabled)
|
||||||
@@ -105,11 +114,18 @@ public partial class InteractionArea2D : Node2D
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EmitSignal(SignalName.InteractedTool, _id);
|
Interact();
|
||||||
EmitSignal(SignalName.Interacted);
|
UpdateSaveData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Interact()
|
||||||
|
{
|
||||||
|
EmitSignal(SignalName.InteractedTool, _id);
|
||||||
|
EmitSignal(SignalName.Interacted);
|
||||||
|
_interactionCounter++;
|
||||||
|
}
|
||||||
|
|
||||||
public void SetSpriteActiveState(bool success, int id) // TODO: remove
|
public void SetSpriteActiveState(bool success, int id) // TODO: remove
|
||||||
{
|
{
|
||||||
if (!_active)
|
if (!_active)
|
||||||
@@ -121,4 +137,39 @@ public partial class InteractionArea2D : Node2D
|
|||||||
_active = !_active;
|
_active = !_active;
|
||||||
_label.Hide();
|
_label.Hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region SAVE AND LOAD
|
||||||
|
|
||||||
|
public void UpdateSaveData()
|
||||||
|
{
|
||||||
|
var payloadData = new Dictionary<string, Variant>
|
||||||
|
{
|
||||||
|
{ "interaction_counter", _interactionCounter }
|
||||||
|
};
|
||||||
|
|
||||||
|
SavegameService.AppendDataToSave(_sceneKeyProvider.Payload.AsString(), _saveId, payloadData);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoadFromSaveData()
|
||||||
|
{
|
||||||
|
var sceneName = _sceneKeyProvider.Payload.AsString();
|
||||||
|
var id = _saveId;
|
||||||
|
int counter = 0;
|
||||||
|
|
||||||
|
Dictionary<string, Variant> save = SavegameService.GetSaveData(sceneName, id);
|
||||||
|
if (save.Count > 0)
|
||||||
|
{
|
||||||
|
if (save.TryGetValue("interaction_counter", out Variant interactionCounterVar))
|
||||||
|
{
|
||||||
|
counter = interactionCounterVar.AsInt32();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < counter; i++)
|
||||||
|
{
|
||||||
|
Interact();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,7 @@ namespace Babushka.scripts.CSharp.Common.Farming;
|
|||||||
/// Defines the behaviour of the field, i.e. interactions, states and effects.
|
/// Defines the behaviour of the field, i.e. interactions, states and effects.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[GlobalClass]
|
[GlobalClass]
|
||||||
public partial class FieldBehaviour2D : Sprite2D
|
public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
||||||
{
|
{
|
||||||
[ExportGroup("Persistence")]
|
[ExportGroup("Persistence")]
|
||||||
[Export] public string SaveId = "";
|
[Export] public string SaveId = "";
|
||||||
@@ -185,10 +185,6 @@ public partial class FieldBehaviour2D : Sprite2D
|
|||||||
|
|
||||||
public void UpdateSaveData()
|
public void UpdateSaveData()
|
||||||
{
|
{
|
||||||
var saveData = new SaveData();
|
|
||||||
|
|
||||||
saveData.SceneName = _sceneKeyProvider.Payload.AsString();
|
|
||||||
saveData.Id = SaveId + _fieldIndex.Payload.AsString();
|
|
||||||
var payloadData = new Dictionary<string, Variant>
|
var payloadData = new Dictionary<string, Variant>
|
||||||
{
|
{
|
||||||
{ "field_state", (int)FieldState }
|
{ "field_state", (int)FieldState }
|
||||||
@@ -206,20 +202,15 @@ public partial class FieldBehaviour2D : Sprite2D
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
saveData.JsonPayload = Json.Stringify(payloadData, indent: "\t");
|
SavegameService.AppendDataToSave(_sceneKeyProvider.Payload.AsString(), SaveId + _fieldIndex.Payload.AsString(), payloadData);
|
||||||
|
|
||||||
SavegameService.AppendSave(saveData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadFromSaveData()
|
public void LoadFromSaveData()
|
||||||
{
|
{
|
||||||
var sceneName = _sceneKeyProvider.Payload.AsString();
|
var sceneName = _sceneKeyProvider.Payload.AsString();
|
||||||
var id = SaveId + _fieldIndex.Payload.AsString();
|
var id = SaveId + _fieldIndex.Payload.AsString();
|
||||||
string jsonPayload = SavegameService.GetSaveData(sceneName, id);
|
|
||||||
if (string.IsNullOrEmpty(jsonPayload))
|
|
||||||
return;
|
|
||||||
|
|
||||||
Dictionary<string, Variant> save = Json.ParseString(jsonPayload).AsGodotDictionary<string, Variant>();
|
Dictionary<string, Variant> save = SavegameService.GetSaveData(sceneName, id);
|
||||||
|
|
||||||
if (save.Count > 0)
|
if (save.Count > 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ using Babushka.scripts.CSharp.Common.Savegame;
|
|||||||
|
|
||||||
namespace Babushka.scripts.CSharp.Common.Inventory;
|
namespace Babushka.scripts.CSharp.Common.Inventory;
|
||||||
|
|
||||||
public partial class InventoryInstance : Node
|
public partial class InventoryInstance : Node, ISaveable
|
||||||
{
|
{
|
||||||
private List<InventorySlot> _slots = new();
|
private List<InventorySlot> _slots = new();
|
||||||
public IReadOnlyList<InventorySlot> Slots => _slots;
|
public IReadOnlyList<InventorySlot> Slots => _slots;
|
||||||
@@ -178,10 +178,6 @@ public partial class InventoryInstance : Node
|
|||||||
|
|
||||||
public void UpdateSaveData()
|
public void UpdateSaveData()
|
||||||
{
|
{
|
||||||
var saveData = new SaveData();
|
|
||||||
|
|
||||||
saveData.SceneName = SCENE_NAME;
|
|
||||||
saveData.Id = ID;
|
|
||||||
var payloadData = new Godot.Collections.Dictionary<string, Variant>();
|
var payloadData = new Godot.Collections.Dictionary<string, Variant>();
|
||||||
|
|
||||||
for (int i = 0; i < _slots.Count; i++)
|
for (int i = 0; i < _slots.Count; i++)
|
||||||
@@ -196,20 +192,15 @@ public partial class InventoryInstance : Node
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
saveData.JsonPayload = Json.Stringify(payloadData, indent: "\t");
|
SavegameService.AppendDataToSave(SCENE_NAME, ID, payloadData);
|
||||||
|
|
||||||
SavegameService.AppendSave(saveData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadFromSaveData()
|
public void LoadFromSaveData()
|
||||||
{
|
{
|
||||||
var sceneName = SCENE_NAME;
|
var sceneName = SCENE_NAME;
|
||||||
var id = ID;
|
var id = ID;
|
||||||
string jsonPayload = SavegameService.GetSaveData(sceneName, id);
|
|
||||||
if (string.IsNullOrEmpty(jsonPayload))
|
|
||||||
return;
|
|
||||||
|
|
||||||
Godot.Collections.Dictionary<string, Variant> save = Json.ParseString(jsonPayload).AsGodotDictionary<string, Variant>();
|
Godot.Collections.Dictionary<string, Variant> save = SavegameService.GetSaveData(sceneName, id);
|
||||||
|
|
||||||
if (save.Count > 0)
|
if (save.Count > 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
namespace Babushka.scripts.CSharp.Common.Savegame;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Defines the behaviour of Nodes that have fields that should save / load to disk.
|
||||||
|
/// </summary>
|
||||||
|
public interface ISaveable
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Adds or updates the field data that shall be stored to disk.
|
||||||
|
/// </summary>
|
||||||
|
public void UpdateSaveData();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Loads the field data from disk.
|
||||||
|
/// </summary>
|
||||||
|
public void LoadFromSaveData();
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://bqapxuprxuj20
|
||||||
@@ -18,13 +18,23 @@ public static class SavegameService
|
|||||||
public static Dictionary<string, string> SaveDatas = new ();
|
public static Dictionary<string, string> SaveDatas = new ();
|
||||||
|
|
||||||
public static bool _loaded = false;
|
public static bool _loaded = false;
|
||||||
|
|
||||||
|
|
||||||
|
public static void AppendDataToSave(string scenename, string id, Dictionary<string, Variant> payload)
|
||||||
|
{
|
||||||
|
var saveData = new SaveData();
|
||||||
|
|
||||||
|
saveData.SceneName = scenename;
|
||||||
|
saveData.Id = id;
|
||||||
|
saveData.JsonPayload = Json.Stringify(payload, indent: "\t");
|
||||||
|
AppendSave(saveData);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds or overwrites an entry in the SaveData dictionary.
|
/// Adds or overwrites an entry in the SaveData dictionary.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="saveData"></param>
|
/// <param name="saveData"></param>
|
||||||
public static void AppendSave(SaveData saveData)
|
private static void AppendSave(SaveData saveData)
|
||||||
{
|
{
|
||||||
string key = string.Concat(saveData.SceneName, "_", saveData.Id);
|
string key = string.Concat(saveData.SceneName, "_", saveData.Id);
|
||||||
|
|
||||||
@@ -46,21 +56,23 @@ public static class SavegameService
|
|||||||
/// <param name="sceneName"></param>
|
/// <param name="sceneName"></param>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string GetSaveData(string sceneName, string id)
|
public static Dictionary<string, Variant> GetSaveData(string sceneName, string id)
|
||||||
{
|
{
|
||||||
string saveData = "";
|
Dictionary<string, Variant> saveData = new();
|
||||||
|
|
||||||
string key = string.Concat(sceneName, "_", id);
|
string key = string.Concat(sceneName, "_", id);
|
||||||
|
string saveDataString = "";
|
||||||
|
|
||||||
if (!_loaded)
|
if (!_loaded)
|
||||||
{
|
{
|
||||||
GD.Print("SavegameService: SaveFile not loaded.");
|
GD.Print("SavegameService: SaveFile not loaded.");
|
||||||
return saveData;
|
return saveData;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SaveDatas.ContainsKey(key))
|
if (SaveDatas.ContainsKey(key))
|
||||||
{
|
{
|
||||||
saveData = SaveDatas[key];
|
saveDataString = SaveDatas[key];
|
||||||
|
saveData = Json.ParseString(saveDataString).AsGodotDictionary<string, Variant>();
|
||||||
}
|
}
|
||||||
|
|
||||||
return saveData;
|
return saveData;
|
||||||
|
|||||||
Reference in New Issue
Block a user