State after inventory clip (farming mechanic still WIP)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=60 format=3 uid="uid://gigb28qk8t12"]
|
||||
[gd_scene load_steps=61 format=3 uid="uid://gigb28qk8t12"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://c25udixd5m6l0" path="res://prefabs/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"]
|
||||
@@ -35,6 +35,7 @@
|
||||
[ext_resource type="Texture2D" uid="uid://x8hr8287ff2n" path="res://art/farm/farming/farmobjekte/tools atlas.png" id="29_p6n74"]
|
||||
[ext_resource type="Resource" uid="uid://datee0flk1e84" path="res://resources/items/scythe.tres" id="29_wtdui"]
|
||||
[ext_resource type="PackedScene" uid="uid://cgjc4wurbgimy" path="res://prefabs/UI/Inventory/Inventory.tscn" id="32_2nee2"]
|
||||
[ext_resource type="PackedScene" uid="uid://b1d2e7ely6hyw" path="res://prefabs/farm/base_field_2d.tscn" id="33_wtdui"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_xy0kg"]
|
||||
shader = ExtResource("13_7p0hq")
|
||||
@@ -679,12 +680,10 @@ shape = SubResource("RectangleShape2D_klb81")
|
||||
z_index = 1
|
||||
y_sort_enabled = true
|
||||
|
||||
[node name="Player2d" parent="YSorted" node_paths=PackedStringArray("_fieldParent") instance=ExtResource("1_7wfwe")]
|
||||
[node name="Vesna" parent="YSorted" node_paths=PackedStringArray("_fieldParent") instance=ExtResource("1_7wfwe")]
|
||||
z_index = 1
|
||||
position = Vector2(1071, 2125)
|
||||
_fieldParent = NodePath("../Farm visuals/FieldParent")
|
||||
|
||||
[node name="CharacterBody2D" parent="YSorted/Player2d" index="0"]
|
||||
_hoe = ExtResource("28_6b2nr")
|
||||
_wateringCan = ExtResource("28_ipqaa")
|
||||
|
||||
@@ -795,6 +794,32 @@ shape = SubResource("RectangleShape2D_2nee2")
|
||||
position = Vector2(13772, 2960)
|
||||
shape = SubResource("RectangleShape2D_p6n74")
|
||||
|
||||
[node name="TestFields" type="Node" parent="YSorted"]
|
||||
|
||||
[node name="BaseField" parent="YSorted/TestFields" instance=ExtResource("33_wtdui")]
|
||||
position = Vector2(8221, 2809)
|
||||
|
||||
[node name="BaseField2" parent="YSorted/TestFields" instance=ExtResource("33_wtdui")]
|
||||
position = Vector2(8225, 3458)
|
||||
|
||||
[node name="BaseField3" parent="YSorted/TestFields" instance=ExtResource("33_wtdui")]
|
||||
position = Vector2(7492, 2812)
|
||||
|
||||
[node name="BaseField4" parent="YSorted/TestFields" instance=ExtResource("33_wtdui")]
|
||||
position = Vector2(7496, 3458)
|
||||
|
||||
[node name="BaseField5" parent="YSorted/TestFields" instance=ExtResource("33_wtdui")]
|
||||
position = Vector2(11266, 2772)
|
||||
|
||||
[node name="BaseField6" parent="YSorted/TestFields" instance=ExtResource("33_wtdui")]
|
||||
position = Vector2(11270, 3421)
|
||||
|
||||
[node name="BaseField7" parent="YSorted/TestFields" instance=ExtResource("33_wtdui")]
|
||||
position = Vector2(10537, 2775)
|
||||
|
||||
[node name="BaseField8" parent="YSorted/TestFields" instance=ExtResource("33_wtdui")]
|
||||
position = Vector2(10541, 3421)
|
||||
|
||||
[node name="Hoe Pickup" parent="." node_paths=PackedStringArray("_sprites") instance=ExtResource("27_klb81")]
|
||||
visible = false
|
||||
position = Vector2(7728, 2000)
|
||||
@@ -851,15 +876,15 @@ size_flags_horizontal = 4
|
||||
size_flags_vertical = 8
|
||||
_inventoryOpenedOffset = -600.0
|
||||
|
||||
[connection signal="PickedUpTool" from="YSorted/Player2d" to="Hoe Pickup" method="SetSpriteActiveState"]
|
||||
[connection signal="PickedUpTool" from="YSorted/Player2d" to="Watercan Pickup" method="SetSpriteActiveState"]
|
||||
[connection signal="InteractedTool" from="YSorted/Brünnen/InteractionArea" to="YSorted/Player2d" method="TryFillWateringCan"]
|
||||
[connection signal="PickedUpTool" from="YSorted/Vesna" to="Hoe Pickup" method="SetSpriteActiveState"]
|
||||
[connection signal="PickedUpTool" from="YSorted/Vesna" to="Watercan Pickup" method="SetSpriteActiveState"]
|
||||
[connection signal="InteractedTool" from="YSorted/Brünnen/InteractionArea" to="YSorted/Vesna" method="TryFillWateringCan"]
|
||||
[connection signal="mouse_entered" from="YSorted/Farm visuals/FieldParent/Area2D" to="YSorted/Farm visuals/FieldParent" method="MouseEnteredAllowedArea"]
|
||||
[connection signal="mouse_exited" from="YSorted/Farm visuals/FieldParent/Area2D" to="YSorted/Farm visuals/FieldParent" method="MouseExitedAllowedArea"]
|
||||
[connection signal="InteractedTool" from="Hoe Pickup" to="YSorted/Player2d" method="ActivateTool"]
|
||||
[connection signal="InteractedTool" from="Watercan Pickup" to="YSorted/Player2d" method="ActivateTool"]
|
||||
[connection signal="InteractedTool" from="Hoe Pickup" to="YSorted/Vesna" method="ActivateTool"]
|
||||
[connection signal="InteractedTool" from="Watercan Pickup" to="YSorted/Vesna" method="ActivateTool"]
|
||||
|
||||
[editable path="YSorted/Player2d"]
|
||||
[editable path="YSorted/Vesna"]
|
||||
[editable path="YSorted/Brünnen/InteractionArea"]
|
||||
[editable path="YSorted/HoeGenericPickup"]
|
||||
[editable path="YSorted/HoeGenericPickup/InteractionArea2"]
|
||||
|
||||
@@ -10,8 +10,6 @@ public partial class Player2D : CharacterBody2D
|
||||
[Export] private float _speed = 100f;
|
||||
[Export] private AnimatedSprite2D _sprite;
|
||||
[Export] private SceneTree.GroupCallFlags _fieldFlags;
|
||||
[Export] private ItemResource _hoe;
|
||||
[Export] private ItemResource _wateringCan;
|
||||
|
||||
// -1 means no tool.
|
||||
private int _toolID = -1;
|
||||
@@ -22,14 +20,10 @@ public partial class Player2D : CharacterBody2D
|
||||
private bool _farmingAnimationInProgress;
|
||||
private Vector2 _lastDirection = Vector2.Zero;
|
||||
private InventoryManager _inventoryManager;
|
||||
private InventoryInstance _inventoryInstance;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_inventoryManager = InventoryManager.Instance;
|
||||
_inventoryInstance = _inventoryManager.playerInventory;
|
||||
_inventoryManager.SlotIndexChanged += HandleInventorySelectedSlotIndexChanged;
|
||||
_inventoryInstance.InventoryContentsChanged += HandleNewItemInInventory;
|
||||
InventoryManager.Instance.playerInventory.InventoryContentsChanged += HandleNewItemInInventory;
|
||||
}
|
||||
|
||||
private void HandleNewItemInInventory()
|
||||
@@ -38,30 +32,6 @@ public partial class Player2D : CharacterBody2D
|
||||
PlayPickUpAnimation();
|
||||
}
|
||||
|
||||
private void HandleInventorySelectedSlotIndexChanged(int newIndex)
|
||||
{
|
||||
InventorySlot currentSlot = InventoryManager.Instance.GetCurrentSelectedSlot();
|
||||
ItemInstance? currentItem = currentSlot.itemInstance;
|
||||
|
||||
if (currentItem == null)
|
||||
return;
|
||||
|
||||
if (currentItem.blueprint == _hoe)
|
||||
{
|
||||
ActivateTool(true, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentItem.blueprint == _wateringCan)
|
||||
{
|
||||
ActivateTool(true, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
ActivateTool(false, 0);
|
||||
ActivateTool(false, 1);
|
||||
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
|
||||
@@ -31,21 +31,13 @@ public partial class FarmingControls2D : Node2D
|
||||
bool activate;
|
||||
|
||||
//if our hands are empty, activate
|
||||
if (_toolId == -1)
|
||||
if (toolId == -1)
|
||||
{
|
||||
activate = true;
|
||||
activate = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
//if we're already carrying a tool, deactivate or fail return
|
||||
if (_toolId == toolId)
|
||||
{
|
||||
activate = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
activate = true;
|
||||
}
|
||||
|
||||
_toolId = activate ? toolId : -1;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Babushka.scripts.CSharp.Common.Inventory;
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
@@ -7,12 +8,44 @@ public partial class VesnaBehaviour2D : Node
|
||||
[ExportGroup("Farming")]
|
||||
[Export] private FieldService2D _fieldParent;
|
||||
[Export] private FarmingControls2D _farmingControls;
|
||||
[Export] private ItemResource _hoe;
|
||||
[Export] private ItemResource _wateringCan;
|
||||
|
||||
[Signal] public delegate void PickedUpToolEventHandler(bool success, int toolId);
|
||||
|
||||
private InventoryManager _inventoryManager;
|
||||
private InventoryInstance _inventoryInstance;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_farmingControls.FieldService = _fieldParent;
|
||||
_inventoryManager = InventoryManager.Instance;
|
||||
_inventoryInstance = _inventoryManager.playerInventory;
|
||||
_inventoryManager.SlotIndexChanged += HandleInventorySelectedSlotIndexChanged;
|
||||
}
|
||||
|
||||
private void HandleInventorySelectedSlotIndexChanged(int newIndex)
|
||||
{
|
||||
InventorySlot currentSlot = InventoryManager.Instance.GetCurrentSelectedSlot();
|
||||
ItemInstance? currentItem = currentSlot.itemInstance;
|
||||
|
||||
if (currentItem == null)
|
||||
return;
|
||||
|
||||
if (currentItem.blueprint == _hoe)
|
||||
{
|
||||
ActivateTool(0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentItem.blueprint == _wateringCan)
|
||||
{
|
||||
ActivateTool(1);
|
||||
return;
|
||||
}
|
||||
|
||||
ActivateTool(-1);
|
||||
|
||||
}
|
||||
|
||||
#region Farming
|
||||
|
||||
Reference in New Issue
Block a user