53 lines
1.4 KiB
C#
53 lines
1.4 KiB
C#
using System;
|
|
using Game.Features.Interactions.Contracts;
|
|
using Game.Features.Players.Contracts;
|
|
using Godot;
|
|
|
|
namespace Game.Features.Interactions.Godot;
|
|
|
|
public abstract partial class WorldInteractionController : Node3D, IInteractionTarget
|
|
{
|
|
public const string InteractionGroup = "world_interactions";
|
|
|
|
[Export] public string InstanceId;
|
|
[Export] public string PromptText = "Wejdź w interakcję";
|
|
|
|
public InteractionTargetId Id { get; private set; }
|
|
public virtual bool CanInteract => true;
|
|
public InteractionPrompt Prompt => new(PromptText);
|
|
|
|
private InteractionWorldController _registry;
|
|
|
|
public override void _Ready()
|
|
{
|
|
Guid id = string.IsNullOrWhiteSpace(InstanceId) ? Guid.NewGuid() : Guid.Parse(InstanceId);
|
|
Id = new InteractionTargetId(id);
|
|
AddToGroup(InteractionGroup);
|
|
RegisterWithAvailableWorld();
|
|
}
|
|
|
|
public override void _ExitTree()
|
|
{
|
|
_registry?.Unregister(Id);
|
|
}
|
|
|
|
public void RegisterWith(InteractionWorldController registry)
|
|
{
|
|
_registry = registry;
|
|
}
|
|
|
|
public abstract InteractionResult Execute(PlayerId playerId);
|
|
|
|
private void RegisterWithAvailableWorld()
|
|
{
|
|
foreach (Node node in GetTree().GetNodesInGroup(InteractionWorldController.RegistryGroup))
|
|
{
|
|
if (node is InteractionWorldController registry)
|
|
{
|
|
registry.Register(this);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|