Reworking 2D interactions
This commit is contained in:
@@ -13,29 +13,30 @@ public partial class FarmingControls2D : Node2D
|
||||
[Export] private Camera2D _camera;
|
||||
|
||||
public FieldService2D FieldParent;
|
||||
|
||||
private bool _hoeInHand = false;
|
||||
private bool _waterCanInHand = false;
|
||||
|
||||
private int _toolId = -1;
|
||||
|
||||
#region Tools
|
||||
|
||||
public bool ActivateHoe(bool activate)
|
||||
|
||||
public bool ActivateTool(bool activate, int toolId)
|
||||
{
|
||||
bool success = ActivateTool(activate, _hoeSprite);
|
||||
_hoeInHand = success;
|
||||
return success;
|
||||
}
|
||||
|
||||
public bool ActivateWateringCan(bool activate)
|
||||
{
|
||||
bool success = ActivateTool(activate, _wateringCanSprite);
|
||||
_waterCanInHand = success;
|
||||
return success;
|
||||
}
|
||||
|
||||
private bool ActivateTool(bool activate, Sprite2D tool)
|
||||
{
|
||||
tool.Visible = !activate;
|
||||
if(_toolId < 0)
|
||||
return false;
|
||||
|
||||
switch (toolId)
|
||||
{
|
||||
case 0:
|
||||
_hoeSprite.Visible = activate;
|
||||
break;
|
||||
case 1:
|
||||
_wateringCanSprite.Visible = activate;
|
||||
|
||||
break;
|
||||
default:
|
||||
_toolId = -1;
|
||||
break;
|
||||
}
|
||||
_toolId = toolId;
|
||||
return !activate;
|
||||
}
|
||||
|
||||
@@ -47,12 +48,12 @@ public partial class FarmingControls2D : Node2D
|
||||
|
||||
Vector2I adjustedPosition = new Vector2I(AdjustValue(mousePosition.X), AdjustValue(mousePosition.Y));
|
||||
|
||||
if (@event.IsActionPressed("click") && _hoeInHand)
|
||||
if (@event.IsActionPressed("click") && _toolId == 0)
|
||||
{
|
||||
MakeField(adjustedPosition);
|
||||
}
|
||||
|
||||
if (@event.IsActionPressed("click") && _waterCanInHand)
|
||||
if (@event.IsActionPressed("click") && _toolId == 1)
|
||||
{
|
||||
WaterTheField(adjustedPosition);
|
||||
}
|
||||
|
||||
@@ -29,16 +29,8 @@ public partial class VesnaBehaviour2D : Node
|
||||
|
||||
private void ActivateTool(bool activate , int toolId)
|
||||
{
|
||||
bool success = false;
|
||||
if (toolId == 0)
|
||||
{
|
||||
success = _farmingControls.ActivateHoe(activate);
|
||||
}
|
||||
else if (toolId == 1)
|
||||
{
|
||||
success = _farmingControls.ActivateWateringCan(activate);
|
||||
}
|
||||
EmitSignal(SignalName.ToolPickup, success);
|
||||
bool activated = _farmingControls.ActivateTool(activate, toolId);
|
||||
EmitSignal(SignalName.ToolPickup, activated);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user