diff --git a/prefabs/farm/animals/duck.tscn b/prefabs/farm/animals/duck.tscn index d3c0ff5..b28adea 100644 --- a/prefabs/farm/animals/duck.tscn +++ b/prefabs/farm/animals/duck.tscn @@ -160,9 +160,11 @@ libraries = { &"": 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) -_spritesToOutline = [NodePath("../Duck rendered")] +_sceneKeyProvider = null +_saveId = "f99549a9-c97e-45a4-b3c9-4bac23fe6fe7" +_outlineMaterial = null [node name="CollisionShape3D" parent="InteractionArea/Area2D" index="0"] shape = SubResource("CircleShape2D_uo3dh") diff --git a/scenes/Babushka_scene_farm_outside_2d.tscn b/scenes/Babushka_scene_farm_outside_2d.tscn index fcf00fc..d71fd58 100644 --- a/scenes/Babushka_scene_farm_outside_2d.tscn +++ b/scenes/Babushka_scene_farm_outside_2d.tscn @@ -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="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/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"] loop = false stream_count = 1 @@ -2243,7 +2257,6 @@ position = Vector2(-113.561, 193.035) shape = SubResource("RectangleShape2D_2vojv") [node name="ducks" type="Node2D" parent="YSorted"] -visible = false z_index = 1 y_sort_enabled = true script = ExtResource("49_uxa2m") @@ -2255,12 +2268,24 @@ y_sort_enabled = false position = Vector2(4374, 2652) _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")] z_index = 0 y_sort_enabled = false position = Vector2(9259, 3194) _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")] z_index = 0 y_sort_enabled = false @@ -2544,6 +2569,10 @@ script = ExtResource("79_065st") [editable path="YSorted/SeedPickup2"] [editable path="YSorted/SeedPickup2/PickupInteractionArea"] [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/trashObject3"] [editable path="YSorted/trash/trashObject4"] diff --git a/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs b/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs index fc3769a..ede7626 100644 --- a/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs +++ b/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs @@ -1,18 +1,18 @@ +using System; using System.Linq; using Babushka.scripts.CSharp.Common.Savegame; using Babushka.scripts.CSharp.Common.Services; -using Babushka.scripts.CSharp.Low_Code.Variables; using Godot; using Godot.Collections; namespace Babushka.scripts.CSharp.Common.CharacterControls; +[Tool] public partial class InteractionArea2D : Node2D, ISaveable { [ExportGroup("Persistence")] - [Export] public string SaveId = ""; - [Export] private VariableNode _sceneID; - [Export] public VariableResource _sceneKeyProvider; + [Export] public Babushka.scripts.CSharp.Low_Code.Variables.VariableResource _sceneKeyProvider; + [Export] private string _saveId; [ExportGroup("Settings")] [Export] private Area2D _area; @@ -48,9 +48,10 @@ public partial class InteractionArea2D : Node2D, ISaveable { _backupMaterials = _spritesToOutline.Select(s => s.Material).ToArray(); } + + LoadFromSaveData(); } - public void OnPlayerEntered(Node2D player) { if (!_active || !InputService.Instance.InputEnabled) @@ -113,12 +114,18 @@ public partial class InteractionArea2D : Node2D, ISaveable } } - EmitSignal(SignalName.InteractedTool, _id); - EmitSignal(SignalName.Interacted); - _interactionCounter++; + Interact(); + UpdateSaveData(); } } + private void Interact() + { + EmitSignal(SignalName.InteractedTool, _id); + EmitSignal(SignalName.Interacted); + _interactionCounter++; + } + public void SetSpriteActiveState(bool success, int id) // TODO: remove { if (!_active) @@ -137,18 +144,31 @@ public partial class InteractionArea2D : Node2D, ISaveable { var payloadData = new Dictionary { - { "interaction counter", _interactionCounter } + { "interaction_counter", _interactionCounter } }; - SavegameService.AppendDataToSave(_sceneKeyProvider.Payload.AsString(), SaveId + _sceneID.Payload.AsString(), payloadData); + SavegameService.AppendDataToSave(_sceneKeyProvider.Payload.AsString(), _saveId, payloadData); } public void LoadFromSaveData() { var sceneName = _sceneKeyProvider.Payload.AsString(); - var id = SaveId + _sceneID.Payload.AsString(); + var id = _saveId; + int counter = 0; Dictionary 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