mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
Boxswitch with state
This commit is contained in:
parent
036a36a80f
commit
87645f2617
14 changed files with 278 additions and 37 deletions
62
Scripts/Interactables/StateSwitch.cs
Normal file
62
Scripts/Interactables/StateSwitch.cs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue