mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-09 03:55:54 +00:00
Valve and music
This commit is contained in:
parent
af44d96c33
commit
ed86ffd184
13 changed files with 197 additions and 15 deletions
100
Scripts/Interactables/3D/AnimatedSwitch3D.cs
Normal file
100
Scripts/Interactables/3D/AnimatedSwitch3D.cs
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Interactables._3D;
|
||||
|
||||
[Tool]
|
||||
public partial class AnimatedSwitch3D : Switch3D
|
||||
{
|
||||
[Export] public DoorState State { get; set; } = DoorState.Closed;
|
||||
|
||||
[Signal]
|
||||
public delegate void OpeningEventHandler();
|
||||
|
||||
[Signal]
|
||||
public delegate void ClosingEventHandler();
|
||||
|
||||
[Signal]
|
||||
public delegate void SetClosedEventHandler();
|
||||
|
||||
[Signal]
|
||||
public delegate void SetOpenEventHandler();
|
||||
|
||||
private bool _isAnimating = false;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
if (Engine.IsEditorHint()) return;
|
||||
base._Ready();
|
||||
|
||||
SyncAnimation();
|
||||
}
|
||||
|
||||
private void SyncAnimation()
|
||||
{
|
||||
if (State is DoorState.Closed)
|
||||
{
|
||||
EmitSignalSetClosed();
|
||||
}
|
||||
else
|
||||
{
|
||||
EmitSignalSetOpen();
|
||||
}
|
||||
}
|
||||
|
||||
public void ClosedAnimationFinished()
|
||||
{
|
||||
State = DoorState.Closed;
|
||||
_isAnimating = false;
|
||||
}
|
||||
|
||||
public void OpenAnimationFinished()
|
||||
{
|
||||
State = DoorState.Open;
|
||||
_isAnimating = false;
|
||||
}
|
||||
|
||||
private void ChangeState(DoorState newState)
|
||||
{
|
||||
if (_isAnimating) return;
|
||||
if (State == newState) return;
|
||||
|
||||
switch (newState)
|
||||
{
|
||||
case DoorState.Open:
|
||||
EmitSignalOpening();
|
||||
break;
|
||||
case DoorState.Closed:
|
||||
EmitSignalClosing();
|
||||
break;
|
||||
}
|
||||
|
||||
_isAnimating = true;
|
||||
}
|
||||
|
||||
public override bool Activate(ActivationType activationType = ActivationType.Toggle)
|
||||
{
|
||||
if (_isAnimating) return false;
|
||||
|
||||
switch (State)
|
||||
{
|
||||
case DoorState.Closed:
|
||||
if (base.Activate(ActivationType.Open))
|
||||
{
|
||||
ChangeState(DoorState.Open);
|
||||
return true;
|
||||
}
|
||||
|
||||
break;
|
||||
case DoorState.Open:
|
||||
if (base.Activate(ActivationType.Close))
|
||||
{
|
||||
ChangeState(DoorState.Closed);
|
||||
return true;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
1
Scripts/Interactables/3D/AnimatedSwitch3D.cs.uid
Normal file
1
Scripts/Interactables/3D/AnimatedSwitch3D.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://qnxswkkn24eo
|
||||
Loading…
Add table
Add a link
Reference in a new issue