mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-08 05:05:55 +00:00
Valves
This commit is contained in:
parent
f9aab9718a
commit
2e8bb70348
13 changed files with 354 additions and 26 deletions
74
Scripts/Interactables/Valve.cs
Normal file
74
Scripts/Interactables/Valve.cs
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
using System;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Interactables;
|
||||
|
||||
public partial class Valve : Interactable
|
||||
{
|
||||
[Export] public Node2D Target { get; set; }
|
||||
|
||||
[Export]
|
||||
private DoorState _activationState = DoorState.Closed;
|
||||
|
||||
private AnimatedSprite2D _animatedSprite;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_animatedSprite = GetNode<AnimatedSprite2D>("AnimatedSprite2D");
|
||||
|
||||
SetState(_activationState);
|
||||
}
|
||||
|
||||
public override bool Activate()
|
||||
{
|
||||
if (MeetsRequirements() && Target is IActivable activatable)
|
||||
{
|
||||
switch (_activationState)
|
||||
{
|
||||
case DoorState.Closed:
|
||||
activatable.Activate(ActivationType.Enable);
|
||||
Open();
|
||||
break;
|
||||
case DoorState.Open:
|
||||
activatable.Activate(ActivationType.Disable);
|
||||
Close();
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Open()
|
||||
{
|
||||
_animatedSprite.Play("Open");
|
||||
_activationState = DoorState.Open;
|
||||
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
_animatedSprite.Play("Closed");
|
||||
_activationState = DoorState.Closed;
|
||||
|
||||
}
|
||||
|
||||
private void SetState(DoorState state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case DoorState.Closed:
|
||||
Close();
|
||||
break;
|
||||
case DoorState.Open:
|
||||
Open();
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue