🚧 WIP first setup completed (still buggy!)

This commit is contained in:
2025-10-22 19:30:33 +02:00
parent b1335d4b00
commit 0e55394699
12 changed files with 272 additions and 5 deletions
@@ -0,0 +1,63 @@
using Babushka.scripts.CSharp.Common.Services;
using Godot;
namespace Babushka.scripts.CSharp.Common.CharacterControls;
public partial class Detector : Area2D
{
[Export] private bool _active = true;
[Export] private bool _oneAtATime = true;
[Signal] public delegate void InteractableEnteredEventHandler();
[Signal] public delegate void InteractableExitedEventHandler();
private DetectableInteractionArea? _currentInteractionArea;
public bool IsActive
{
get => _active;
set => _active = value;
}
public override void _Ready()
{
AreaEntered += OnEnteredInteractable;
AreaExited += OnExitedInteractable;
}
public void OnEnteredInteractable(Node body)
{
if (!_active || !InputService.Instance.InputEnabled)
return;
GD.Print("Entered Node2D.");
if (body is DetectableInteractionArea interactionArea2D)
{
GD.Print("Entered interactable.");
_currentInteractionArea = interactionArea2D;
interactionArea2D.ActivateInteractionArea(true);
EmitSignal(SignalName.InteractableEntered);
if (_oneAtATime)
_active = false;
}
}
public void OnExitedInteractable(Node body)
{
GD.Print("Exited Node2D.");
if (body is DetectableInteractionArea interactionArea2D)
{
GD.Print("Exited interactable.");
if (_oneAtATime && _currentInteractionArea != interactionArea2D)
return;
interactionArea2D.ActivateInteractionArea(false);
_currentInteractionArea = null;
EmitSignal(SignalName.InteractableExited);
_active = true;
}
}
}