cirnogodot/Scripts/Interactables/StateSwitch.cs

77 lines
No EOL
2.1 KiB
C#

using System;
using Cirno.Scripts.Enums;
using Godot;
namespace Cirno.Scripts.Interactables;
public partial class StateSwitch : Switch
{
[Export]
public SwitchState StartingState { get; private set; } = SwitchState.Off;
public SwitchState CurrentState { get; private set; }
public override void _Ready()
{
base._Ready();
CurrentState = StartingState;
switch (CurrentState)
{
case SwitchState.On:
TriggerEnable();
break;
case SwitchState.Off:
TriggerDisable();
break;
case SwitchState.Destroyed:
break;
case SwitchState.Disabled:
break;
}
}
public override bool Activate(ActivationType activationType = ActivationType.Toggle)
{
switch (activationType)
{
case ActivationType.Use:
case ActivationType.Toggle:
switch (CurrentState)
{
case SwitchState.On:
return TriggerDisable();
case SwitchState.Off:
return TriggerEnable();
}
break;
case ActivationType.Close:
case ActivationType.Enable:
return TriggerEnable();
case ActivationType.Open:
case ActivationType.Disable:
return TriggerDisable();
case ActivationType.Destroy:
this.CurrentState = SwitchState.Destroyed;
break;
}
return false;
}
protected bool TriggerDisable()
{
CurrentState = SwitchState.Off;
//EmitSignal(Switch.SignalName.OnActivated, (int)ActivationType.Disable);
return base.Activate(ActivationType.Disable);
}
protected bool TriggerEnable()
{
CurrentState = SwitchState.On;
//EmitSignal(Switch.SignalName.OnActivated, (int)ActivationType.Enable);
return base.Activate(ActivationType.Enable);
}
}