Fixed Tomato farming (again)

pull/16/head
kziolkowski 4 months ago
parent 975dd45c94
commit 2cb605261e

@ -43,21 +43,6 @@ label_settings = SubResource("LabelSettings_7emux")
horizontal_alignment = 1
vertical_alignment = 1
[node name="AmountLabel" type="Label" parent="."]
layout_mode = 1
anchors_preset = -1
anchor_left = 1.0
anchor_right = 1.0
offset_left = -50.0
offset_top = 9.0
offset_right = -10.0
offset_bottom = 49.0
grow_horizontal = 0
grow_vertical = 0
theme_override_colors/font_color = Color(0, 0, 0, 1)
text = "999"
horizontal_alignment = 2
[node name="Icon" type="TextureRect" parent="."]
layout_mode = 1
anchors_preset = -1
@ -73,4 +58,23 @@ texture = ExtResource("3_n5ryf")
expand_mode = 4
stretch_mode = 5
[node name="AmountLabel" type="Label" parent="."]
layout_mode = 1
anchors_preset = -1
anchor_left = 0.99
anchor_top = 0.92
anchor_right = 0.99
anchor_bottom = 0.92
offset_left = -47.0
offset_top = -35.0
offset_right = -8.00001
offset_bottom = -3.0
grow_horizontal = 0
grow_vertical = 0
theme_override_colors/font_color = Color(0, 0, 0, 1)
theme_override_font_sizes/font_size = 25
text = "999"
horizontal_alignment = 2
vertical_alignment = 2
[connection signal="gui_input" from="." to="." method="_on_gui_input"]

@ -1,4 +1,4 @@
[gd_scene load_steps=12 format=3 uid="uid://gishbn0a8eke"]
[gd_scene load_steps=13 format=3 uid="uid://gishbn0a8eke"]
[ext_resource type="Script" uid="uid://cms357f23fmfy" path="res://scripts/CSharp/Common/Farming/PlantBehaviour2D.cs" id="1_66p1c"]
[ext_resource type="Texture2D" uid="uid://dtr4uga5uspg" path="res://art/farm/farming/farmobjekte/tomaten/tomaten baby.png" id="2_vjw4j"]
@ -6,6 +6,7 @@
[ext_resource type="Texture2D" uid="uid://b2gu6ur2xc7s4" path="res://art/farm/farming/farmobjekte/tomaten/tomaten blume.png" id="4_hmj2d"]
[ext_resource type="PackedScene" uid="uid://cqc72e4hq6bcd" path="res://prefabs/interactions/interaction_area_2d.tscn" id="5_3j24b"]
[ext_resource type="PackedScene" uid="uid://dpbbroif2tnil" path="res://prefabs/interactions/generic_item_on_ground_2d.tscn" id="6_gdrin"]
[ext_resource type="Resource" uid="uid://blr8tine5m0ma" path="res://resources/items/tomato.tres" id="7_vjw4j"]
[ext_resource type="Texture2D" uid="uid://cnwd3mb3jnuxm" path="res://art/farm/farming/farmobjekte/tomaten/teen adulte tomaten.png" id="8_evgr8"]
[ext_resource type="Texture2D" uid="uid://bleimj6jr1jka" path="res://art/general/rectangle.png" id="9_vjw4j"]
@ -150,6 +151,9 @@ shape = SubResource("CircleShape2D_vjw4j")
position = Vector2(0, 2.3)
IsActive = false
[node name="SpawnWithItem" parent="ReadyPlantInventoryItem" index="0"]
_blueprint = ExtResource("7_vjw4j")
[node name="ItemLabel" parent="ReadyPlantInventoryItem" index="1"]
visible = false
z_index = 100

@ -1,8 +1,11 @@
[gd_resource type="Resource" script_class="ItemRepository" load_steps=2 format=3 uid="uid://d284vxftxhym0"]
[gd_resource type="Resource" script_class="ItemRepository" load_steps=3 format=3 uid="uid://d284vxftxhym0"]
[ext_resource type="Resource" uid="uid://d1uuxp1lp4aro" path="res://resources/items/tomato_seed.tres" id="1_67bbe"]
[ext_resource type="Script" uid="uid://oafmfqkdqewd" path="res://scripts/CSharp/Common/Inventory/ItemRepository.cs" id="1_ew4x0"]
[resource]
script = ExtResource("1_ew4x0")
itemInventoryRepository = Dictionary[Object, String]({})
itemInventoryRepository = Dictionary[Object, String]({
ExtResource("1_67bbe"): "res://prefabs/farm/tomato_plant.tscn"
})
metadata/_custom_type_script = "uid://oafmfqkdqewd"

@ -1092,7 +1092,7 @@ shape = SubResource("CircleShape2D_tm0yg")
[node name="SeedPickup" parent="YSorted" instance=ExtResource("25_hukxv")]
position = Vector2(10114, 2469)
_infiniteSupply = true
_finiteSupply = 3
[node name="SpawnWithItem" parent="YSorted/SeedPickup" index="0"]
_blueprint = ExtResource("35_64mdn")

@ -72,7 +72,6 @@ rest = Transform2D(1, 0, 0, 1, 24.3826, -1.82351)
[node name="head" type="Bone2D" parent="Vesna/Skeleton2D/hip/chest/neck"]
position = Vector2(13.2948, -0.197781)
rotation = 1.52891
scale = Vector2(1, 1)
rest = Transform2D(0.0418757, 0.999123, -0.999123, 0.0418757, 13.2948, -0.197781)
[node name="armR" type="Bone2D" parent="Vesna/Skeleton2D/hip/chest"]
@ -84,7 +83,6 @@ rest = Transform2D(-0.674355, -0.0959749, 0.0959749, -0.674355, 19.1624, -26.827
[node name="forearmR" type="Bone2D" parent="Vesna/Skeleton2D/hip/chest/armR"]
position = Vector2(26.3157, -1.29047)
rotation = -2.2602
scale = Vector2(1, 1)
rest = Transform2D(-0.636078, -0.771625, 0.771625, -0.636078, 26.3157, -1.29047)
[node name="handR" type="Bone2D" parent="Vesna/Skeleton2D/hip/chest/armR/forearmR"]
@ -101,5 +99,4 @@ rest = Transform2D(-0.99956, -0.0296662, 0.0296662, -0.99956, -4.51055, -13.9084
[node name="legRLower" type="Bone2D" parent="Vesna/Skeleton2D/hip/legR"]
position = Vector2(24.8604, -0.524962)
rotation = -3.11367
scale = Vector2(1, 1)
rest = Transform2D(-0.99961, -0.0279217, 0.0279217, -0.99961, 24.8604, -0.524962)

@ -81,7 +81,7 @@ public partial class FieldBehaviour2D : Sprite2D
int currentSlotIndex = InventoryManager.Instance.CurrentSelectedSlotIndex;
ItemInstance? item = InventoryManager.Instance.playerInventory.Slots[currentSlotIndex].itemInstance;
if (item == null || PlantingPlaceholder.GetChildCount() > 0)
if (item == null || PlantingPlaceholder.GetChildCount() > 0 || item.amount == 0)
return success;
string prefabPath = ItemRepository.TryGetPrefabPath(item.blueprint);
@ -98,7 +98,8 @@ public partial class FieldBehaviour2D : Sprite2D
{
plantBehaviour.Field = this;
}
InventoryManager.Instance.playerInventory.RemoveItem(currentSlotIndex);
success = true;
}

@ -3,8 +3,8 @@
public enum InventoryActionResult
{
Success,
DestinationDoesNotExists,
DestinationDoesNotExist,
DestinationFull,
SourceDoesNotExists,
SourceDoesNotExist,
SourceIsEmpty
}

@ -17,6 +17,9 @@ public partial class InventoryInstance : Node
[Signal]
public delegate void InventoryContentsChangedEventHandler();
/// <summary>
/// The total amount of Inventoryslots in the inventory (empty and occupied).
/// </summary>
[Export]
public int SlotAmount
{
@ -49,7 +52,7 @@ public partial class InventoryInstance : Node
private InventoryActionResult AddItemAndStackRecursive(ItemInstance newItem, int slotSearch)
{
if (newItem.blueprint == null || newItem.amount == 0)
return InventoryActionResult.SourceDoesNotExists;
return InventoryActionResult.SourceDoesNotExist;
var slotIndex = -1;
// find stackable slot
@ -97,7 +100,7 @@ public partial class InventoryInstance : Node
if (inventorySlot < 0 || inventorySlot >= _slots.Count)
{
itemInstance = null;
return InventoryActionResult.SourceDoesNotExists;
return InventoryActionResult.SourceDoesNotExist;
}
if (_slots[inventorySlot].IsEmpty())
@ -107,6 +110,10 @@ public partial class InventoryInstance : Node
}
itemInstance = _slots[inventorySlot].itemInstance;
if (itemInstance == null)
return InventoryActionResult.SourceDoesNotExist;
itemInstance.amount -= 1;
_slots[inventorySlot].itemInstance = null;
EmitSignal(SignalName.InventoryContentsChanged);
return InventoryActionResult.Success;
@ -120,7 +127,7 @@ public partial class InventoryInstance : Node
public InventoryActionResult AddItemToSlot(ItemInstance itemInstance, int destinationSlot)
{
if (destinationSlot < 0 || destinationSlot >= _slots.Count)
return InventoryActionResult.DestinationDoesNotExists;
return InventoryActionResult.DestinationDoesNotExist;
if (!_slots[destinationSlot].IsEmpty())
return InventoryActionResult.DestinationFull;

@ -1,9 +1,21 @@
#nullable enable
namespace Babushka.scripts.CSharp.Common.Inventory;
/// <summary>
/// Represents a virtual object wrapper for an item instance.
/// Can return the containing item or null.
/// </summary>
public class InventorySlot
{
/// <summary>
/// The inventory item instance that may or may not be bound to this slot.
/// </summary>
public ItemInstance? itemInstance;
/// <summary>
/// Whether or not this slot is currently occupied by an item instance.
/// </summary>
/// <returns></returns>
public bool IsEmpty()
{
return itemInstance == null;

Loading…
Cancel
Save