basic harvesting implemented

remotes/checkIfPRContentChanged-1749880758504311652/feature/farming_visuals
kziolkowski 8 months ago
parent a477f9ef4f
commit 25d8f217ff

@ -1,4 +1,4 @@
[gd_scene load_steps=8 format=3 uid="uid://c3hwbwo423nbm"]
[gd_scene load_steps=11 format=3 uid="uid://c3hwbwo423nbm"]
[ext_resource type="Script" uid="uid://cms357f23fmfy" path="res://scripts/CSharp/Common/Farming/PlantBehaviour2D.cs" id="1_tikj4"]
[ext_resource type="Shader" uid="uid://braevmqauoek7" path="res://prefabs/farm/swaying_plant.gdshader" id="2_goh03"]
@ -6,6 +6,8 @@
[ext_resource type="Texture2D" uid="uid://b2gu6ur2xc7s4" path="res://art/farm/farming/farmobjekte/tomaten/tomaten blume.png" id="3_goh03"]
[ext_resource type="Texture2D" uid="uid://cnwd3mb3jnuxm" path="res://art/farm/farming/farmobjekte/tomaten/teen adulte tomaten.png" id="4_u4cty"]
[ext_resource type="PackedScene" uid="uid://cqc72e4hq6bcd" path="res://prefabs/interaction_area_2d.tscn" id="5_tikj4"]
[ext_resource type="PackedScene" uid="uid://dpbbroif2tnil" path="res://prefabs/interactions/generic_item_on_ground_2d.tscn" id="6_u4cty"]
[ext_resource type="Resource" uid="uid://blr8tine5m0ma" path="res://resources/items/tomato.tres" id="7_yntkb"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_u4cty"]
shader = ExtResource("2_goh03")
@ -19,12 +21,17 @@ shader_parameter/distortion = 0.0
shader_parameter/heightOffset = 0.635
shader_parameter/offset = 0.0
[node name="BasePlant" type="Node2D" node_paths=PackedStringArray("_seeds", "_smallPlants", "_bigPlants", "_readyPlants")]
[sub_resource type="CircleShape2D" id="CircleShape2D_2tt5u"]
resource_local_to_scene = true
radius = 300.0
[node name="BasePlant" type="Node2D" node_paths=PackedStringArray("_seeds", "_smallPlants", "_bigPlants", "_readyPlants", "_harvestablePlant")]
script = ExtResource("1_tikj4")
_seeds = [NodePath("Seeds/TomatoSeed"), NodePath("Seeds/TomatoSeed2"), NodePath("Seeds/TomatoSeed3")]
_smallPlants = [NodePath("SmallPlant/01"), NodePath("SmallPlant/02"), NodePath("SmallPlant/03"), NodePath("SmallPlant/04")]
_bigPlants = [NodePath("BigPlant/01"), NodePath("BigPlant/02"), NodePath("BigPlant/03"), NodePath("BigPlant/04")]
_readyPlants = [NodePath("ReadyPlant/01"), NodePath("ReadyPlant/02"), NodePath("ReadyPlant/03"), NodePath("ReadyPlant/04")]
_readyPlants = [NodePath("ReadyPlantInventoryItem/ReadyPlant/01"), NodePath("ReadyPlantInventoryItem/ReadyPlant/02"), NodePath("ReadyPlantInventoryItem/ReadyPlant/03"), NodePath("ReadyPlantInventoryItem/ReadyPlant/04")]
_harvestablePlant = NodePath("ReadyPlantInventoryItem")
[node name="Seeds" type="Node2D" parent="."]
position = Vector2(0, 0.5)
@ -126,10 +133,31 @@ texture = ExtResource("3_goh03")
region_enabled = true
region_rect = Rect2(546, 697, 535, 687)
[node name="ReadyPlant" type="Node2D" parent="."]
[node name="InteractionArea" parent="." instance=ExtResource("5_tikj4")]
position = Vector2(0, 2.3)
[node name="01" type="Sprite2D" parent="ReadyPlant"]
[node name="ReadyPlantInventoryItem" parent="." instance=ExtResource("6_u4cty")]
position = Vector2(0, 2.3)
IsActive = false
[node name="SpawnWithItem" parent="ReadyPlantInventoryItem" index="0"]
_blueprint = ExtResource("7_yntkb")
[node name="ItemLabel" parent="ReadyPlantInventoryItem" index="1"]
visible = false
[node name="PickupErrorLabel" parent="ReadyPlantInventoryItem" index="2"]
visible = false
[node name="CollisionShape3D" parent="ReadyPlantInventoryItem/InteractionArea2/Area2D" index="0"]
shape = SubResource("CircleShape2D_2tt5u")
[node name="Icon" parent="ReadyPlantInventoryItem" index="4"]
visible = false
[node name="ReadyPlant" type="Node2D" parent="ReadyPlantInventoryItem"]
[node name="01" type="Sprite2D" parent="ReadyPlantInventoryItem/ReadyPlant"]
visible = false
y_sort_enabled = true
material = SubResource("ShaderMaterial_u4cty")
@ -137,7 +165,7 @@ texture = ExtResource("4_u4cty")
region_enabled = true
region_rect = Rect2(399, 3, 679, 808)
[node name="02" type="Sprite2D" parent="ReadyPlant"]
[node name="02" type="Sprite2D" parent="ReadyPlantInventoryItem/ReadyPlant"]
visible = false
y_sort_enabled = true
material = SubResource("ShaderMaterial_u4cty")
@ -145,7 +173,7 @@ texture = ExtResource("4_u4cty")
region_enabled = true
region_rect = Rect2(1077, 109, 633, 695)
[node name="03" type="Sprite2D" parent="ReadyPlant"]
[node name="03" type="Sprite2D" parent="ReadyPlantInventoryItem/ReadyPlant"]
visible = false
y_sort_enabled = true
material = SubResource("ShaderMaterial_u4cty")
@ -153,7 +181,7 @@ texture = ExtResource("4_u4cty")
region_enabled = true
region_rect = Rect2(415, 838, 639, 817)
[node name="04" type="Sprite2D" parent="ReadyPlant"]
[node name="04" type="Sprite2D" parent="ReadyPlantInventoryItem/ReadyPlant"]
visible = false
y_sort_enabled = true
material = SubResource("ShaderMaterial_u4cty")
@ -161,7 +189,7 @@ texture = ExtResource("4_u4cty")
region_enabled = true
region_rect = Rect2(1167, 863, 528, 785)
[node name="InteractionArea" parent="." instance=ExtResource("5_tikj4")]
position = Vector2(0, 2.3)
[connection signal="Interacted" from="InteractionArea" to="." method="Grow"]
[editable path="ReadyPlantInventoryItem"]
[editable path="ReadyPlantInventoryItem/InteractionArea2"]

@ -1,5 +1,6 @@
using System;
using Babushka.scripts.CSharp.Common.CharacterControls;
using Babushka.scripts.CSharp.Common.Inventory;
using Godot;
namespace Babushka.scripts.CSharp.Common.Farming;
@ -15,6 +16,7 @@ public partial class PlantBehaviour2D : Node2D
[Export] private Sprite2D[] _readyPlants;
[Export] private PlantState _state = PlantState.None;
[Export] private FieldBehaviour2D _field;
[Export] private ItemOnGround2D _harvestablePlant;
private Sprite2D _currentPlantSprite = null;
@ -52,6 +54,7 @@ public partial class PlantBehaviour2D : Node2D
_state = PlantState.Ready;
_currentPlantSprite.Visible = false;
_currentPlantSprite = GetRandomSprite(_readyPlants);
_harvestablePlant.IsActive = true;
_currentPlantSprite.Visible = true;
break;
case PlantState.Ready:

@ -6,8 +6,11 @@ public partial class ItemOnGround2D : Node
{
private ItemInstance _itemInstance;
[Export]
private bool _infiniteSupply = false;
[Export] private bool _infiniteSupply = false;
[Export] private int _finiteSupply = 1;
[Export] public bool IsActive = true;
private int pickUpCounter = 0;
private Label _itemLabel => GetNode<Label>("ItemLabel");
private Label _pickupErrorLabel => GetNode<Label>("PickupErrorLabel");
@ -31,16 +34,21 @@ public partial class ItemOnGround2D : Node
public void TryPickUp()
{
GD.Print("Trying to pick up item");
if (!IsActive)
return;
var result = InventoryManager.Instance.CollectItem(itemInstance.Clone());
if (result == InventoryActionResult.Success)
{
if (!_infiniteSupply)
{
pickUpCounter++;
if (pickUpCounter >= _finiteSupply)
{
QueueFree();
}
}
}
else
{
_pickupErrorLabel.Text = "Inventory Full";
@ -52,6 +60,9 @@ public partial class ItemOnGround2D : Node
public void UpdateVisuals()
{
if (!IsActive)
return;
_iconSprite.Texture = itemInstance?.blueprint?.icon;
if (_iconSprite.Texture == null)
{

Loading…
Cancel
Save