🚧 watering fields kinda works now
This commit is contained in:
@@ -8,7 +8,6 @@ namespace Babushka.scripts.CSharp.Common.Animation;
|
||||
public partial class VesnaAnimations : Node
|
||||
{
|
||||
[Export] private AnimatedSprite2D _sprite;
|
||||
[Export] private CpuParticles2D _wateringParticles;
|
||||
|
||||
private bool anyActionPressed;
|
||||
private string _toolString;
|
||||
@@ -144,7 +143,6 @@ public partial class VesnaAnimations : Node
|
||||
_sprite.Animation = "diagonal wateringcan";
|
||||
_sprite.Play();
|
||||
InputService.Instance.InputEnabled = false;
|
||||
_wateringParticles.Emitting = true;
|
||||
Task.Run(DelayedInputHandlerReset);
|
||||
}
|
||||
}
|
||||
@@ -152,7 +150,6 @@ public partial class VesnaAnimations : Node
|
||||
private async Task DelayedInputHandlerReset()
|
||||
{
|
||||
await Task.Delay(1000);
|
||||
_wateringParticles.Emitting = false;
|
||||
InputService.Instance.InputEnabled = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,17 +11,14 @@ public partial class FarmingControls2D : Node2D
|
||||
[Export] private VariableResource _sceneKeyProvider;
|
||||
[Export] private Node2D _movingPlayer;
|
||||
[Export] private Camera2D _camera;
|
||||
[Export] private CpuParticles2D _wateringParticles;
|
||||
|
||||
[Export] private float _wateringCanParticlesVerticalOffset = 50f;
|
||||
[Export] private Vector2I _fieldOffsetVector = new Vector2I(735, 651);
|
||||
[Export] private Node2D _fieldParent;
|
||||
[Export] private VariableResource _cursorOnField;
|
||||
|
||||
private int _toolId = -1;
|
||||
private bool _wateringCanFilled = false;
|
||||
|
||||
[Signal] public delegate void WateringFieldEventHandler();
|
||||
|
||||
[Signal] public delegate void FieldCreatedEventHandler();
|
||||
|
||||
#region Tools
|
||||
@@ -58,14 +55,6 @@ public partial class FarmingControls2D : Node2D
|
||||
{
|
||||
if (@event.IsActionPressed("click"))
|
||||
{
|
||||
bool cursorOnField = _cursorOnField.Payload.AsBool();
|
||||
if (_toolId == WateringCanState.WATERING_CAN_ID
|
||||
&& WateringCanState.GetFillState() > 0)
|
||||
{
|
||||
Vector2I adjustedPosition = GetAdjustedMousePosition();
|
||||
WaterTheField(adjustedPosition);
|
||||
}
|
||||
|
||||
if ( _toolId == 0)
|
||||
{
|
||||
Vector2I adjustedPosition = GetAdjustedMousePosition();
|
||||
@@ -95,21 +84,6 @@ public partial class FarmingControls2D : Node2D
|
||||
WateringCanState.Fill();
|
||||
}
|
||||
}
|
||||
|
||||
private void WaterTheField(Vector2I fieldPosition)
|
||||
{
|
||||
int potentialFieldIndex = FieldService.Instance.PositionToIndex(fieldPosition);
|
||||
FieldBehaviour2D? field = FieldService.Instance.TryGet(_sceneKeyProvider.Payload.AsString(), potentialFieldIndex);
|
||||
if (field == null || field.FieldState == FieldState.Watered)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
field.Water();
|
||||
_wateringParticles.GlobalPosition = new Vector2(field.GlobalPosition.X, field.GlobalPosition.Y + _wateringCanParticlesVerticalOffset);
|
||||
WateringCanState.Water();
|
||||
EmitSignal(SignalName.WateringField);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
using Babushka.scripts.CSharp.Common.Inventory;
|
||||
using Babushka.scripts.CSharp.Low_Code.Events;
|
||||
using Babushka.scripts.CSharp.Low_Code.Variables;
|
||||
using Godot;
|
||||
|
||||
@@ -23,6 +24,8 @@ public partial class FieldBehaviour2D : Sprite2D
|
||||
[Export] public InteractionArea2D FieldInteractionArea;
|
||||
[Export] public VariableResource _sceneKeyProvider;
|
||||
[Export] private VariableNode _fieldIndex;
|
||||
[Export] private CpuParticles2D _wateringParticles;
|
||||
[Export] private EventResource _wateringEvent;
|
||||
|
||||
|
||||
public Vector2 FieldPosition;
|
||||
@@ -30,15 +33,18 @@ public partial class FieldBehaviour2D : Sprite2D
|
||||
private bool _seedsActive;
|
||||
private bool _wateringCanActive;
|
||||
|
||||
private bool _canPlant;
|
||||
private bool _canWater;
|
||||
|
||||
[Signal] public delegate void PlantedEventHandler();
|
||||
|
||||
private void UpdateInteractionArea()
|
||||
{
|
||||
// fieldstate == tilled / watered && samen im Inventar
|
||||
bool canPlant = (FieldState == FieldState.Tilled || FieldState == FieldState.Watered) && _seedsActive;
|
||||
_canPlant = (FieldState == FieldState.Tilled || FieldState == FieldState.Watered) && _seedsActive;
|
||||
// fieldstate == tilled && watering can ausgewählt
|
||||
bool canWater = FieldState == FieldState.Tilled && _wateringCanActive;
|
||||
FieldInteractionArea.IsActive = canPlant || canWater;
|
||||
_canWater = FieldState == FieldState.Tilled && _wateringCanActive;
|
||||
FieldInteractionArea.IsActive = _canPlant || _canWater;
|
||||
}
|
||||
|
||||
public void ActivatedSeedInInventory(bool activated)
|
||||
@@ -97,6 +103,9 @@ public partial class FieldBehaviour2D : Sprite2D
|
||||
public void Water()
|
||||
{
|
||||
UpdateFieldState(FieldState.Watered);
|
||||
_wateringParticles.Emitting = true;
|
||||
WateringCanState.Water();
|
||||
_wateringEvent.Raise();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -104,11 +113,16 @@ public partial class FieldBehaviour2D : Sprite2D
|
||||
/// </summary>
|
||||
public void Farm()
|
||||
{
|
||||
if (TryPlant())
|
||||
if (_canPlant || TryPlant())
|
||||
{
|
||||
EmitSignal(SignalName.Planted);
|
||||
UpdateFieldState(FieldState.Planted);
|
||||
}
|
||||
|
||||
if (_canWater)
|
||||
{
|
||||
Water();
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryPlant()
|
||||
|
||||
Reference in New Issue
Block a user