InteractionAreas are now bound to SpriteSwitchers and farming tool interaction works
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user