Files
night-shift/src/Features/Interactions/Godot/InteractionsRegistryController.cs
T

48 lines
1.1 KiB
C#

using Game.Features.Interactions.Contracts;
using Godot;
using GodotNodeArray = Godot.Collections.Array<Godot.Node>;
namespace Game.Features.Interactions.Godot;
public partial class InteractionsRegistryController : Node
{
public const string RegistryGroup = "interactions_registry";
private IInteractionRegistry _registry;
private GodotNodeArray GetInteractionTargetNodesInScene() =>
GetTree().GetNodesInGroup(InteractableController.InteractionGroup);
public override void _EnterTree()
{
AddToGroup(RegistryGroup);
}
public void UseRegistry(IInteractionRegistry registry)
{
_registry = registry;
}
public void RegisterSceneTargets()
{
foreach (Node node in GetInteractionTargetNodesInScene())
{
if (node is InteractableController target)
{
Register(target);
}
}
}
public void Register(InteractableController target)
{
_registry.Register(target);
target.UseRegistry(this);
}
public void Unregister(InteractionTargetId targetId)
{
_registry.Unregister(targetId);
}
}