This commit is contained in:
Marco 2025-02-14 19:00:31 +01:00
commit 2e8bb70348
13 changed files with 354 additions and 26 deletions

View 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();
}
}
}