🐛 field creation at the same spot no longer possible, also watering works now.
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
[gd_resource type="Resource" script_class="VariableResource" load_steps=2 format=3 uid="uid://tt3d166mntmi"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://dtvx2cakx0bey" path="res://scripts/CSharp/Low Code/Variables/VariableResource.cs" id="1_m5pb0"]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
script = ExtResource("1_m5pb0")
|
||||||
|
Payload = "farmOutside"
|
||||||
|
metadata/_custom_type_script = "uid://dtvx2cakx0bey"
|
||||||
@@ -1044,7 +1044,7 @@ _hoe = ExtResource("28_6b2nr")
|
|||||||
[node name="FarmingControls" parent="YSorted/Vesna" index="1" node_paths=PackedStringArray("_camera")]
|
[node name="FarmingControls" parent="YSorted/Vesna" index="1" node_paths=PackedStringArray("_camera")]
|
||||||
_camera = NodePath("../../../Camera2D")
|
_camera = NodePath("../../../Camera2D")
|
||||||
|
|
||||||
[node name="Brünnen" type="Sprite2D" parent="YSorted" node_paths=PackedStringArray("_interactionArea")]
|
[node name="Well" type="Sprite2D" parent="YSorted" node_paths=PackedStringArray("_interactionArea")]
|
||||||
z_index = 1
|
z_index = 1
|
||||||
y_sort_enabled = true
|
y_sort_enabled = true
|
||||||
material = SubResource("ShaderMaterial_2vojv")
|
material = SubResource("ShaderMaterial_2vojv")
|
||||||
@@ -1056,17 +1056,18 @@ region_rect = Rect2(0, 0, 1504, 1686)
|
|||||||
script = ExtResource("32_lbnqo")
|
script = ExtResource("32_lbnqo")
|
||||||
_interactionArea = NodePath("InteractionArea")
|
_interactionArea = NodePath("InteractionArea")
|
||||||
|
|
||||||
[node name="StaticBody2D" type="StaticBody2D" parent="YSorted/Brünnen"]
|
[node name="StaticBody2D" type="StaticBody2D" parent="YSorted/Well"]
|
||||||
collision_mask = 4
|
collision_mask = 4
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="YSorted/Brünnen/StaticBody2D"]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="YSorted/Well/StaticBody2D"]
|
||||||
position = Vector2(145.5, -224)
|
position = Vector2(145.5, -224)
|
||||||
shape = SubResource("RectangleShape2D_0sfl7")
|
shape = SubResource("RectangleShape2D_0sfl7")
|
||||||
|
|
||||||
[node name="InteractionArea" parent="YSorted/Brünnen" node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("27_klb81")]
|
[node name="InteractionArea" parent="YSorted/Well" node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("27_klb81")]
|
||||||
_spritesToOutline = [NodePath("..")]
|
_spritesToOutline = [NodePath("..")]
|
||||||
|
_id = 1
|
||||||
|
|
||||||
[node name="CollisionShape3D" parent="YSorted/Brünnen/InteractionArea/Area2D" index="0"]
|
[node name="CollisionShape3D" parent="YSorted/Well/InteractionArea/Area2D" index="0"]
|
||||||
position = Vector2(146, -130)
|
position = Vector2(146, -130)
|
||||||
shape = SubResource("CircleShape2D_p6n74")
|
shape = SubResource("CircleShape2D_p6n74")
|
||||||
|
|
||||||
@@ -2421,7 +2422,7 @@ timeline = "quest2_tomatoes_end"
|
|||||||
|
|
||||||
[connection signal="FilledWateringCan" from="YSorted/Vesna" to="Audio/SFX/FillWater SFX2" method="PlayOneShot"]
|
[connection signal="FilledWateringCan" from="YSorted/Vesna" to="Audio/SFX/FillWater SFX2" method="PlayOneShot"]
|
||||||
[connection signal="WateringField" from="YSorted/Vesna/FarmingControls" to="Audio/SFX/Watering SFX" method="PlayOneShot"]
|
[connection signal="WateringField" from="YSorted/Vesna/FarmingControls" to="Audio/SFX/Watering SFX" method="PlayOneShot"]
|
||||||
[connection signal="InteractedTool" from="YSorted/Brünnen/InteractionArea" to="YSorted/Vesna" method="TryFillWateringCan"]
|
[connection signal="InteractedTool" from="YSorted/Well/InteractionArea" to="YSorted/Vesna" method="TryFillWateringCan"]
|
||||||
[connection signal="SuccessfulPickUp" from="YSorted/CanGenericPickup" to="YSorted/Vesna" method="HandlePickUp"]
|
[connection signal="SuccessfulPickUp" from="YSorted/CanGenericPickup" to="YSorted/Vesna" method="HandlePickUp"]
|
||||||
[connection signal="SuccessfulPickUp" from="YSorted/RakeGenericPickup" to="YSorted/Vesna" method="HandlePickUp"]
|
[connection signal="SuccessfulPickUp" from="YSorted/RakeGenericPickup" to="YSorted/Vesna" method="HandlePickUp"]
|
||||||
[connection signal="SuccessfulPickUp" from="YSorted/SeedPickup" to="YSorted/Vesna" method="HandlePickUp"]
|
[connection signal="SuccessfulPickUp" from="YSorted/SeedPickup" to="YSorted/Vesna" method="HandlePickUp"]
|
||||||
@@ -2443,7 +2444,7 @@ timeline = "quest2_tomatoes_end"
|
|||||||
[connection signal="OnFulfilled" from="SpecialQuestTrigger/FieldWorkTrigger" to="SpecialQuestTrigger/FieldWorkTrigger/StartDialog" method="open"]
|
[connection signal="OnFulfilled" from="SpecialQuestTrigger/FieldWorkTrigger" to="SpecialQuestTrigger/FieldWorkTrigger/StartDialog" method="open"]
|
||||||
|
|
||||||
[editable path="YSorted/Vesna"]
|
[editable path="YSorted/Vesna"]
|
||||||
[editable path="YSorted/Brünnen/InteractionArea"]
|
[editable path="YSorted/Well/InteractionArea"]
|
||||||
[editable path="YSorted/CanGenericPickup"]
|
[editable path="YSorted/CanGenericPickup"]
|
||||||
[editable path="YSorted/CanGenericPickup/PickupInteractionArea"]
|
[editable path="YSorted/CanGenericPickup/PickupInteractionArea"]
|
||||||
[editable path="YSorted/RakeGenericPickup"]
|
[editable path="YSorted/RakeGenericPickup"]
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using Babushka.scripts.CSharp.Low_Code.Variables;
|
||||||
using Godot;
|
using Godot;
|
||||||
using Godot.Collections;
|
using Godot.Collections;
|
||||||
|
|
||||||
@@ -6,14 +7,13 @@ namespace Babushka.scripts.CSharp.Common.Farming;
|
|||||||
[GlobalClass]
|
[GlobalClass]
|
||||||
public partial class FarmingControls2D : Node2D
|
public partial class FarmingControls2D : Node2D
|
||||||
{
|
{
|
||||||
[Export] private PackedScene _fieldPrefab;
|
[Export] private VariableResource _sceneKeyProvider;
|
||||||
|
[Export] private PackedScene? _fieldPrefab = null!;
|
||||||
[Export] private Node2D _movingPlayer;
|
[Export] private Node2D _movingPlayer;
|
||||||
[Export] private Camera2D _camera;
|
[Export] private Camera2D _camera;
|
||||||
[Export] private CpuParticles2D _wateringParticles;
|
[Export] private CpuParticles2D _wateringParticles;
|
||||||
[Export] private float _wateringCanParticlesVerticalOffset = 50f;
|
[Export] private float _wateringCanParticlesVerticalOffset = 50f;
|
||||||
|
|
||||||
public FieldService2D FieldService;
|
|
||||||
|
|
||||||
private int _toolId = -1;
|
private int _toolId = -1;
|
||||||
private bool _wateringCanFilled = false;
|
private bool _wateringCanFilled = false;
|
||||||
|
|
||||||
@@ -116,7 +116,7 @@ public partial class FarmingControls2D : Node2D
|
|||||||
|
|
||||||
private void WaterTheField(Vector2I fieldPosition)
|
private void WaterTheField(Vector2I fieldPosition)
|
||||||
{
|
{
|
||||||
FieldBehaviour2D field = FieldService.Get(fieldPosition);
|
FieldBehaviour2D? field = FieldService.Instance.TryGet(_sceneKeyProvider.Payload.AsString(), fieldPosition);
|
||||||
if (field == null || field.FieldState == FieldState.Watered)
|
if (field == null || field.FieldState == FieldState.Watered)
|
||||||
{
|
{
|
||||||
GD.Print($"The field at position {fieldPosition} is null!");
|
GD.Print($"The field at position {fieldPosition} is null!");
|
||||||
@@ -135,25 +135,30 @@ public partial class FarmingControls2D : Node2D
|
|||||||
#region FIELD CREATION
|
#region FIELD CREATION
|
||||||
private void MakeField(Vector2I fieldPosition)
|
private void MakeField(Vector2I fieldPosition)
|
||||||
{
|
{
|
||||||
if(FieldService == null || _fieldPrefab == null)
|
if(_fieldPrefab == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// only instantiate a field if there isn't one already.
|
// only instantiate a field if there isn't one already.
|
||||||
if(FieldService.Get(fieldPosition) == null)
|
if(FieldService.Instance.TryGet(_sceneKeyProvider.Payload.AsString(), fieldPosition) == null)
|
||||||
{
|
{
|
||||||
|
GD.Print($"FarmingControls: Creating a field at {fieldPosition}");
|
||||||
Node fieldInstance = _fieldPrefab.Instantiate();
|
Node fieldInstance = _fieldPrefab.Instantiate();
|
||||||
if (fieldInstance is Node2D field2d)
|
if (fieldInstance is Node2D field2d)
|
||||||
{
|
{
|
||||||
// add dictionary entry for the field
|
// add dictionary entry for the field
|
||||||
Array<Node> fields = field2d.FindChildren("*", nameof(FieldBehaviour2D));
|
Array<Node> fields = field2d.FindChildren("*", nameof(FieldBehaviour2D));
|
||||||
if (fields.Count > 0)
|
if (fields.Count > 0)
|
||||||
FieldService.TryAddEntry(fieldPosition, fields[0] as FieldBehaviour2D);
|
FieldService.Instance.TryAddEntry(_sceneKeyProvider.Payload.AsString(), fieldPosition, fields[0] as FieldBehaviour2D);
|
||||||
|
|
||||||
// reposition and reparent the instance
|
// reposition and reparent the instance
|
||||||
field2d.Position = new Vector2(fieldPosition.X, fieldPosition.Y);;
|
field2d.Position = new Vector2(fieldPosition.X, fieldPosition.Y);;
|
||||||
FieldService.AddChild(fieldInstance);
|
FieldService.Instance.AddChild(fieldInstance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GD.Print($"FarmingControls: Could not create a field at {fieldPosition}.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int AdjustValue(float value)
|
private int AdjustValue(float value)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using Babushka.scripts.CSharp.Common.CharacterControls;
|
using Babushka.scripts.CSharp.Common.CharacterControls;
|
||||||
using Babushka.scripts.CSharp.Common.Inventory;
|
using Babushka.scripts.CSharp.Common.Inventory;
|
||||||
|
using Babushka.scripts.CSharp.Low_Code.Variables;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
namespace Babushka.scripts.CSharp.Common.Farming;
|
namespace Babushka.scripts.CSharp.Common.Farming;
|
||||||
@@ -20,7 +21,6 @@ public partial class FieldBehaviour2D : Sprite2D
|
|||||||
|
|
||||||
|
|
||||||
public Vector2 FieldPosition;
|
public Vector2 FieldPosition;
|
||||||
public FieldService2D FieldService;
|
|
||||||
|
|
||||||
[Signal] public delegate void PlantedEventHandler();
|
[Signal] public delegate void PlantedEventHandler();
|
||||||
|
|
||||||
|
|||||||
@@ -3,75 +3,109 @@ using Godot;
|
|||||||
|
|
||||||
namespace Babushka.scripts.CSharp.Common.Farming;
|
namespace Babushka.scripts.CSharp.Common.Farming;
|
||||||
|
|
||||||
public partial class FieldService : Node2D
|
public partial class FieldService : Node
|
||||||
{
|
{
|
||||||
private Dictionary<PackedScene, FieldsInScene>? fieldsPerScene;
|
private Dictionary<string, FieldsInScene>? outerDict;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[Signal] public delegate void FieldCreatedEventHandler();
|
[Signal] public delegate void FieldCreatedEventHandler();
|
||||||
|
|
||||||
|
public static FieldService Instance { get; private set; } = null!;
|
||||||
|
|
||||||
|
public override void _EnterTree()
|
||||||
|
{
|
||||||
|
Instance = this;
|
||||||
|
outerDict = new Dictionary<string, FieldsInScene>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//Create
|
//Create
|
||||||
public bool TryAddEntry(PackedScene scene, Vector2I key, FieldBehaviour2D field)
|
public bool TryAddEntry(string sceneName, Vector2I position, FieldBehaviour2D field)
|
||||||
{
|
{
|
||||||
if (!fieldsPerScene.ContainsKey(scene))
|
GD.Print($"Fieldservice: Trying to add a new entry. SceneName: {sceneName} Position: {position}.");
|
||||||
|
if (outerDict != null )
|
||||||
{
|
{
|
||||||
FieldsInScene fieldInstance = new FieldsInScene();
|
FieldsInScene fieldsInScene;
|
||||||
fieldsPerScene.Add(scene, fieldInstance);
|
bool outerDictEntryExists = outerDict.TryGetValue(sceneName, out fieldsInScene);
|
||||||
|
|
||||||
|
if (!outerDictEntryExists)
|
||||||
|
{
|
||||||
|
fieldsInScene = new FieldsInScene();
|
||||||
|
outerDict.Add(sceneName, fieldsInScene);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fieldsInScene.fields.ContainsKey(position))
|
||||||
|
{
|
||||||
|
fieldsInScene.fields.Add(position, field);
|
||||||
EmitSignal(SignalName.FieldCreated);
|
EmitSignal(SignalName.FieldCreated);
|
||||||
|
GD.Print("Fieldservice: successfully added field to dictionary.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GD.Print("Fieldservice: Either no outerdict found or there is already a field here!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read
|
// Read
|
||||||
public FieldBehaviour2D Get(PackedScene key, Vector2I fieldPosition)
|
public FieldBehaviour2D? TryGet(string key, Vector2I fieldPosition)
|
||||||
{
|
{
|
||||||
if (fieldsPerScene.TryGetValue(key, out FieldsInScene field))
|
if (outerDict != null && outerDict.TryGetValue(key, out FieldsInScene? field))
|
||||||
{
|
{
|
||||||
if (field.fields.TryGetValue(fieldPosition, out FieldBehaviour2D fieldInstance))
|
GD.Print($"Fieldservice: Successfully retrieved fieldsPerScene Dictionary. " +
|
||||||
|
$"OuterDict Count: {outerDict.Count} InnerDict Count {outerDict[key].fields.Count}");
|
||||||
|
if (field.fields.TryGetValue(fieldPosition, out FieldBehaviour2D? fieldInstance))
|
||||||
|
{
|
||||||
|
GD.Print($"Fieldservice: Successfully retrieved fieldInstance at position: {fieldPosition}.");
|
||||||
return fieldInstance;
|
return fieldInstance;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
GD.Print("Fieldservice TryGet: No field found.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//todo:
|
|
||||||
// - Make this a singleton
|
|
||||||
// - Let this interact with the FarmingControls and the FieldBehaviours
|
|
||||||
// - Replace FieldService2D and remove it from scenes.
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
//Update
|
//Update
|
||||||
public void UpdateEntry(Vector2I fieldPosition, FieldBehaviour2D state)
|
public void UpdateEntry(string key, Vector2I fieldPosition, FieldBehaviour2D state)
|
||||||
{
|
{
|
||||||
|
GD.Print($"FieldService: Updating entry at {fieldPosition}");
|
||||||
if (fields.ContainsKey(fieldPosition))
|
if (outerDict != null && outerDict.TryGetValue(key, out FieldsInScene? field))
|
||||||
{
|
{
|
||||||
fields[fieldPosition] = state;
|
if (field.fields.ContainsKey(fieldPosition))
|
||||||
|
{
|
||||||
|
field.fields[fieldPosition] = state;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TryAddEntry(fieldPosition, state);
|
TryAddEntry(key, fieldPosition, state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//Delete
|
//Delete
|
||||||
|
|
||||||
public void RemoveEntry(Vector2I fieldPosition)
|
public void RemoveEntry(string key, Vector2I fieldPosition)
|
||||||
{
|
{
|
||||||
if (fields.ContainsKey(fieldPosition))
|
GD.Print($"FieldService: Removing entry at {fieldPosition}.");
|
||||||
|
if (outerDict != null && outerDict.TryGetValue(key, out FieldsInScene? field))
|
||||||
{
|
{
|
||||||
fields.Remove(fieldPosition);
|
if (field.fields.ContainsKey(fieldPosition))
|
||||||
|
{
|
||||||
|
field.fields.Remove(fieldPosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class FieldsInScene
|
internal class FieldsInScene
|
||||||
{
|
{
|
||||||
public Dictionary<Vector2I, FieldBehaviour2D> fields;
|
public Dictionary<Vector2I, FieldBehaviour2D?> fields;
|
||||||
|
|
||||||
|
public FieldsInScene()
|
||||||
|
{
|
||||||
|
fields = new Dictionary<Vector2I, FieldBehaviour2D?>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://slo0uydmmvnu
|
||||||
@@ -9,7 +9,6 @@ namespace Babushka.scripts.CSharp.Common.Farming;
|
|||||||
public partial class VesnaBehaviour2D : Node
|
public partial class VesnaBehaviour2D : Node
|
||||||
{
|
{
|
||||||
[ExportGroup("Farming")]
|
[ExportGroup("Farming")]
|
||||||
[Export] private FieldService2D _fieldParent;
|
|
||||||
[Export] private FarmingControls2D _farmingControls;
|
[Export] private FarmingControls2D _farmingControls;
|
||||||
[Export] private PlayerMovement _player2d;
|
[Export] private PlayerMovement _player2d;
|
||||||
[Export] private VesnaAnimations _vesnaAnimations;
|
[Export] private VesnaAnimations _vesnaAnimations;
|
||||||
@@ -26,7 +25,6 @@ public partial class VesnaBehaviour2D : Node
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_farmingControls.FieldService = _fieldParent;
|
|
||||||
_inventoryManager = InventoryManager.Instance;
|
_inventoryManager = InventoryManager.Instance;
|
||||||
_inventoryInstance = _inventoryManager.playerInventory;
|
_inventoryInstance = _inventoryManager.playerInventory;
|
||||||
_inventoryManager.SlotIndexChanged += HandleInventorySelectedSlotIndexChanged;
|
_inventoryManager.SlotIndexChanged += HandleInventorySelectedSlotIndexChanged;
|
||||||
|
|||||||
Reference in New Issue
Block a user