InteractionAreas are now bound to SpriteSwitchers and farming tool interaction works
This commit is contained in:
@@ -17,11 +17,33 @@ public partial class FarmingControls2D : Node2D
|
||||
private int _toolId = -1;
|
||||
|
||||
#region Tools
|
||||
|
||||
public bool ActivateTool(bool activate, int toolId)
|
||||
|
||||
/// <summary>
|
||||
/// If no tool has been set, then set the current tool to the incoming tool id.
|
||||
/// </summary>
|
||||
/// <param name="toolId">The id of the tool to activate if possible</param>
|
||||
/// <returns>If the tool in question was activated.</returns>
|
||||
public bool TryActivateTool(int toolId)
|
||||
{
|
||||
if(_toolId < 0)
|
||||
return false;
|
||||
bool activate;
|
||||
|
||||
//if our hands are empty, activate
|
||||
if (_toolId == -1)
|
||||
{
|
||||
activate = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//if we're already carrying a tool, deactivate or fail return
|
||||
if (_toolId == toolId)
|
||||
{
|
||||
activate = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
switch (toolId)
|
||||
{
|
||||
@@ -30,14 +52,14 @@ public partial class FarmingControls2D : Node2D
|
||||
break;
|
||||
case 1:
|
||||
_wateringCanSprite.Visible = activate;
|
||||
|
||||
break;
|
||||
default:
|
||||
_toolId = -1;
|
||||
break;
|
||||
}
|
||||
_toolId = toolId;
|
||||
return !activate;
|
||||
|
||||
_toolId = activate ? toolId : -1;
|
||||
return activate;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -8,7 +8,7 @@ public partial class VesnaBehaviour2D : Node
|
||||
[Export] private FieldService2D _fieldParent;
|
||||
[Export] private FarmingControls2D _farmingControls;
|
||||
|
||||
[Signal] public delegate void ToolPickupEventHandler(bool success);
|
||||
[Signal] public delegate void PickedUpToolEventHandler(bool success, int toolId);
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -17,20 +17,10 @@ public partial class VesnaBehaviour2D : Node
|
||||
|
||||
#region Farming
|
||||
|
||||
public void ActivateHoe(bool activate)
|
||||
public void ActivateTool(int toolId)
|
||||
{
|
||||
ActivateTool(activate, 0);
|
||||
}
|
||||
|
||||
public void ActivateWateringCan(bool activate)
|
||||
{
|
||||
ActivateTool(activate, 1);
|
||||
}
|
||||
|
||||
private void ActivateTool(bool activate , int toolId)
|
||||
{
|
||||
bool activated = _farmingControls.ActivateTool(activate, toolId);
|
||||
EmitSignal(SignalName.ToolPickup, activated);
|
||||
bool activated = _farmingControls.TryActivateTool(toolId);
|
||||
EmitSignal(SignalName.PickedUpTool, activated, toolId);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user