mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 09:55:35 +00:00
67 lines
No EOL
1.5 KiB
C#
67 lines
No EOL
1.5 KiB
C#
using System;
|
|
using Godot;
|
|
|
|
namespace Cirno.Scripts.Activables;
|
|
|
|
public partial class BlackCover : Sprite2D, IActivable
|
|
{
|
|
[Export]
|
|
public bool StartActive { get; private set; } = true;
|
|
|
|
[Signal]
|
|
public delegate void DisabledEventHandler();
|
|
|
|
private bool _activated;
|
|
|
|
public override void _Ready()
|
|
{
|
|
_activated = StartActive;
|
|
UpdateSprite();
|
|
}
|
|
|
|
public bool Activate(ActivationType activationType = ActivationType.Toggle)
|
|
{
|
|
switch (activationType)
|
|
{
|
|
case ActivationType.Use:
|
|
case ActivationType.Toggle:
|
|
_activated = !_activated;
|
|
break;
|
|
case ActivationType.Close:
|
|
case ActivationType.Enable:
|
|
_activated = true;
|
|
break;
|
|
case ActivationType.Open:
|
|
case ActivationType.Disable:
|
|
_activated = false;
|
|
break;
|
|
case ActivationType.Destroy:
|
|
break;
|
|
}
|
|
UpdateSprite();
|
|
return true;
|
|
}
|
|
|
|
private void UpdateSprite()
|
|
{
|
|
if (_activated)
|
|
{
|
|
this.Show();
|
|
}
|
|
else
|
|
{
|
|
EmitSignalDisabled();
|
|
this.Hide();
|
|
}
|
|
}
|
|
|
|
private void OnAreaEntered(Area2D area)
|
|
{
|
|
if (area is not InteractionController interactionController)
|
|
{
|
|
return;
|
|
}
|
|
_activated = false;
|
|
UpdateSprite();
|
|
}
|
|
} |