cirnogodot/Scripts/Interactables/StateSwitch.cs

77 lines
2.1 KiB
C#
Raw Permalink Normal View History

2025-03-13 21:11:53 +01:00
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;
2025-03-14 23:04:59 +01:00
switch (CurrentState)
{
case SwitchState.On:
TriggerEnable();
break;
case SwitchState.Off:
TriggerDisable();
break;
case SwitchState.Destroyed:
break;
case SwitchState.Disabled:
break;
}
2025-03-13 21:11:53 +01:00
}
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);
}
}