From e04f9f65d4c65e0c0845c4054208470231637b39 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Sun, 15 Jun 2025 18:59:38 +0200 Subject: [PATCH] WIP trying to toggle interactable colliders at runtime for fields --- prefabs/farm/base_field_2d.tscn | 21 ++++++++++++++++--- .../CSharp/Common/Farming/FieldBehaviour2D.cs | 4 ++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/prefabs/farm/base_field_2d.tscn b/prefabs/farm/base_field_2d.tscn index f0efc2e..200b387 100644 --- a/prefabs/farm/base_field_2d.tscn +++ b/prefabs/farm/base_field_2d.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=7 format=3 uid="uid://b1d2e7ely6hyw"] +[gd_scene load_steps=8 format=3 uid="uid://b1d2e7ely6hyw"] [ext_resource type="PackedScene" uid="uid://cqc72e4hq6bcd" path="res://prefabs/interactions/interaction_area_2d.tscn" id="1_femni"] [ext_resource type="Script" uid="uid://bdffon388rkty" path="res://scripts/CSharp/Common/Farming/FieldBehaviour2D.cs" id="2_femni"] @@ -6,9 +6,13 @@ [ext_resource type="Texture2D" uid="uid://d3dq15edmgbwf" path="res://art/farm/tilable grounds/böden/nasse farming erde rund.png" id="4_lsfck"] [ext_resource type="PackedScene" uid="uid://c3hwbwo423nbm" path="res://prefabs/farm/base_plant_2d.tscn" id="5_femni"] +[sub_resource type="CircleShape2D" id="CircleShape2D_yi42k"] +resource_local_to_scene = true +radius = 201.345 + [sub_resource type="CircleShape2D" id="CircleShape2D_femni"] resource_local_to_scene = true -radius = 300.0 +radius = 194.926 [node name="BaseField" type="Node2D"] @@ -17,13 +21,14 @@ visible = false z_index = 1 scale = Vector2(2.225, 2.225) -[node name="FieldBehaviour" type="Sprite2D" parent="."] +[node name="FieldBehaviour" type="Sprite2D" parent="." node_paths=PackedStringArray("_growingCollider")] z_index = -1 scale = Vector2(0.9, 1) texture = ExtResource("2_yi42k") script = ExtResource("2_femni") Tilled = ExtResource("2_yi42k") Watered = ExtResource("4_lsfck") +_growingCollider = NodePath("BasePlant/InteractionArea") [node name="BasePlant" parent="FieldBehaviour" node_paths=PackedStringArray("_field") instance=ExtResource("5_femni")] _field = NodePath("..") @@ -31,9 +36,18 @@ _field = NodePath("..") [node name="BigPlant" parent="FieldBehaviour/BasePlant" index="2"] position = Vector2(6, -161) +[node name="InteractionArea" parent="FieldBehaviour/BasePlant" index="3"] +z_index = 3 + +[node name="CollisionShape3D" parent="FieldBehaviour/BasePlant/InteractionArea/Area2D" index="0"] +shape = SubResource("CircleShape2D_yi42k") + [node name="CollisionShape3D" parent="FieldBehaviour/BasePlant/ReadyPlantInventoryItem/InteractionArea2/Area2D" index="0"] shape = SubResource("CircleShape2D_femni") +[node name="Label" parent="FieldBehaviour/BasePlant/ReadyPlantInventoryItem/InteractionArea2" index="1"] +visible = false + [node name="ReadyPlant" parent="FieldBehaviour/BasePlant/ReadyPlantInventoryItem" index="5"] visible = false position = Vector2(0, -291.3) @@ -44,5 +58,6 @@ visible = true [connection signal="Interacted" from="InteractionArea2" to="FieldBehaviour/BasePlant" method="Grow"] [editable path="FieldBehaviour/BasePlant"] +[editable path="FieldBehaviour/BasePlant/InteractionArea"] [editable path="FieldBehaviour/BasePlant/ReadyPlantInventoryItem"] [editable path="FieldBehaviour/BasePlant/ReadyPlantInventoryItem/InteractionArea2"] diff --git a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs index 26beaa7..de7c165 100644 --- a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs @@ -1,3 +1,4 @@ +using Babushka.scripts.CSharp.Common.CharacterControls; using Godot; namespace Babushka.scripts.CSharp.Common.Farming; @@ -17,6 +18,7 @@ public partial class FieldBehaviour2D : Sprite2D [Export] private Texture2D Tilled; [Export] private Texture2D Watered; [Export] public FieldState FieldState = FieldState.Tilled; + [Export] private InteractionArea2D _growingCollider; public Vector2 FieldPosition; @@ -36,10 +38,12 @@ public partial class FieldBehaviour2D : Sprite2D case FieldState.Tilled: FieldState = FieldState.Tilled; Texture = Tilled; + _growingCollider.Visible = false; break; case FieldState.Watered: FieldState = FieldState.Watered; Texture = Watered; + _growingCollider.Visible = true; break; case FieldState.Planted: FieldState = FieldState.Planted;