limited field creation to specified shape

remotes/checkIfPRContentChanged-1749880758504311652/farming_mechanic
kziolkowski 8 months ago
parent 8af825bc18
commit 222c10fe0a

@ -1,4 +1,4 @@
[gd_scene load_steps=47 format=3 uid="uid://gigb28qk8t12"]
[gd_scene load_steps=48 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"]
@ -93,6 +93,9 @@ shader_parameter/value_mult = 1.068
shader_parameter/brightness_add = 0.0
shader_parameter/contrast_mult = 0.913
[sub_resource type="RectangleShape2D" id="RectangleShape2D_p6n74"]
size = Vector2(5176, 1192)
[sub_resource type="ShaderMaterial" id="ShaderMaterial_2vojv"]
shader = ExtResource("13_7p0hq")
shader_parameter/hue_shift = 0.0
@ -658,10 +661,18 @@ collision_mask = 2
position = Vector2(-257.6, 236.8)
polygon = PackedVector2Array(232, -4.80005, 0, 0, 0, -96, -262.4, -97.6, -265.6, -260.8, -310.4, -260.8, -235.2, -321.6, -124.8, -323.2, -57.6, -424, 84.8, -436.8, 118.4, -452.8, 136, -436.8, 726.4, -452.8, 817.6, -299.2, 785.6, -291.2, 785.6, -108.8, 241.6, -94.4)
[node name="FieldService2D" type="Node2D" parent="Farm visuals"]
[node name="FieldParent" type="Node2D" parent="Farm visuals"]
position = Vector2(48, 0)
script = ExtResource("25_0qu0h")
metadata/_custom_type_script = "uid://dhxtdhfqx3bte"
[node name="Area2D" type="Area2D" parent="Farm visuals/FieldParent"]
position = Vector2(-48, -16)
[node name="CollisionShape2D" type="CollisionShape2D" parent="Farm visuals/FieldParent/Area2D"]
position = Vector2(-2492, 2980)
shape = SubResource("RectangleShape2D_p6n74")
[node name="YSorted" type="Node2D" parent="."]
z_index = 1
y_sort_enabled = true
@ -669,7 +680,7 @@ y_sort_enabled = true
[node name="Player2d" parent="YSorted" node_paths=PackedStringArray("_fieldParent") instance=ExtResource("1_7wfwe")]
z_index = 1
position = Vector2(1064, 2128)
_fieldParent = NodePath("../../Farm visuals/FieldService2D")
_fieldParent = NodePath("../../Farm visuals/FieldParent")
[node name="Brünnen" type="Sprite2D" parent="YSorted"]
z_index = 1
@ -723,6 +734,8 @@ region_rect = Rect2(-2, 1135, 421, 292)
texture = ExtResource("29_p6n74")
region_rect = Rect2(1, 1138, 418, 288)
[connection signal="mouse_entered" from="Farm visuals/FieldParent/Area2D" to="Farm visuals/FieldParent" method="MouseEnteredAllowedArea"]
[connection signal="mouse_exited" from="Farm visuals/FieldParent/Area2D" to="Farm visuals/FieldParent" method="MouseExitedAllowedArea"]
[connection signal="PickedUpTool" from="YSorted/Player2d" to="Hoe Pickup" method="SetSpriteActiveState"]
[connection signal="PickedUpTool" from="YSorted/Player2d" to="Watercan Pickup" method="SetSpriteActiveState"]
[connection signal="Interacted" from="Hoe Pickup" to="YSorted/Player2d" method="ActivateTool"]

@ -66,7 +66,7 @@ public partial class FarmingControls2D : Node2D
public override void _Input(InputEvent @event)
{
Vector2 mousePosition = GetViewport().GetMousePosition();
Vector2 mousePosition = _camera.GetGlobalMousePosition();
Vector2I adjustedPosition = new Vector2I(AdjustValue(mousePosition.X), AdjustValue(mousePosition.Y));
@ -94,6 +94,14 @@ public partial class FarmingControls2D : Node2D
{
if(FieldParent == null || _fieldPrefab == null)
return;
bool fieldAllowed = FieldParent.FieldAllowed();
GD.Print($"Field allowed at {fieldPosition}: {fieldAllowed}");
// only try to instantiate a field if you're in the allowed area
if (!fieldAllowed)
return;
// only instantiate a field if there isn't one already.
if(FieldParent.Get(fieldPosition) == null)

@ -7,7 +7,26 @@ namespace Babushka.scripts.CSharp.Common.Farming;
public partial class FieldService2D : Node2D
{
[Export] private Dictionary<Vector2I, FieldBehaviour2D> fields = new Dictionary<Vector2I, FieldBehaviour2D>();
private bool _fieldAllowed = false;
//Validate
public void MouseEnteredAllowedArea()
{
_fieldAllowed = true;
}
public void MouseExitedAllowedArea()
{
_fieldAllowed = false;
}
public bool FieldAllowed()
{
return _fieldAllowed;
}
//Create
public bool TryAddEntry(Vector2I key, FieldBehaviour2D field)
{

Loading…
Cancel
Save