refactor: restructure interaction system into clean layers
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user