InteractionAreas are now bound to SpriteSwitchers and farming tool interaction works

This commit is contained in:
2025-05-17 16:38:32 +02:00
parent f7684b6c2a
commit 8af825bc18
7 changed files with 88 additions and 65 deletions
+17 -17
View File
@@ -7,30 +7,30 @@ namespace Babushka.scripts.CSharp.Common;
/// </summary>
public partial class SpriteSwitcher2D : Node2D
{
[Export] private Sprite2D _firstSprite;
[Export] private Sprite2D _secondSprite;
[Export] private bool _state = true;
[Signal]
public delegate void SwitchEventHandler(bool state);
[Export] private Sprite2D _activeSprite;
[Export] private Sprite2D _inactiveSprite;
[Export] private bool _active = false;
public override void _Ready()
{
SetState();
SetSprites();
}
public void SwitchState()
/// <summary>
/// Switches the State of the Sprites to the opposite.
/// Emits Switch Signal.
/// </summary>
public void SwitchState(bool state)
{
_state = !_state;
EmitSignal(SignalName.Switch, _state);
SetState();
_active = state;
SetSprites();
}
private void SetState()
private void SetSprites()
{
if(_firstSprite != null)
_firstSprite.Visible = _state;
if(_secondSprite != null)
_secondSprite.Visible = !_state;
if(_activeSprite != null)
_activeSprite.Visible = _active;
if(_inactiveSprite != null)
_inactiveSprite.Visible = !_active;
}
}