diff --git a/src/Features/Interactions/Godot/PlayerInteractionController.cs b/src/Features/Interactions/Godot/PlayerInteractionController.cs index 38c2c9d..0c4f3e1 100644 --- a/src/Features/Interactions/Godot/PlayerInteractionController.cs +++ b/src/Features/Interactions/Godot/PlayerInteractionController.cs @@ -3,9 +3,9 @@ using Game.Features.Interactions.Application; using Game.Features.Interactions.Contracts; using Game.Features.Interactions.Domain; using Game.Features.Items.Contracts; -using Game.Features.Logging.Contracts; using Game.Features.Players.Contracts; using Game.Godot; +using Game.Godot.Exceptions; using Game.Godot.Extensions; using Game.Godot.Mappings; using Godot; @@ -35,10 +35,8 @@ public partial class PlayerInteractionController : Node, IItemSpawnPoint [Export] public Node3D RightHandAnchor; - private const string LogCategory = "PlayerInteraction"; private IItemInteractionService _items; private IInteractionHandler _interactions; - private ILogger _logger; private PlayerId _playerId; private readonly HashSet _dropActions = []; private readonly ResolvePickupAvailability _resolvePickupAvailability = new(); @@ -158,14 +156,12 @@ public partial class PlayerInteractionController : Node, IItemSpawnPoint public void Initialize( PlayerId playerId, IItemInteractionService items, - IInteractionHandler interactions, - ILogger logger + IInteractionHandler interactions ) { _playerId = playerId; _items = items; _interactions = interactions; - _logger = logger; } public Vector3 GetItemSpawnPosition() => CalculateDropPosition(); @@ -179,9 +175,7 @@ public partial class PlayerInteractionController : Node, IItemSpawnPoint { if (_items is null || _interactions is null) { - _logger?.Warning(LogCategory, "Skipped frame: controller not yet initialized."); - PromptController.Clear(); - return; + throw new ControllerNotInitializedException(Name); } if (GamePause.IsPaused || !MouseCapture.IsCaptured) @@ -197,8 +191,7 @@ public partial class PlayerInteractionController : Node, IItemSpawnPoint { if (_items is null || _interactions is null) { - _logger?.Warning(LogCategory, "Ignored input: controller not yet initialized."); - return; + throw new ControllerNotInitializedException(Name); } if (GamePause.IsPaused || !MouseCapture.IsCaptured) diff --git a/src/Godot/Exceptions/ControllerNotInitializedException.cs b/src/Godot/Exceptions/ControllerNotInitializedException.cs new file mode 100644 index 0000000..1e4ea18 --- /dev/null +++ b/src/Godot/Exceptions/ControllerNotInitializedException.cs @@ -0,0 +1,15 @@ +using System; + +namespace Game.Godot.Exceptions; + +/// +/// Thrown when a controller is used before it has been initialized. +/// +public sealed class ControllerNotInitializedException(string nodeName) + : Exception(BuildMessage(nodeName)) +{ + public string NodeName { get; } = nodeName; + + private static string BuildMessage(string nodeName) + => $"{nodeName}: controller was used before it was initialized."; +} diff --git a/src/Godot/GameBootstrap.cs b/src/Godot/GameBootstrap.cs index 5ec8a39..b12290c 100644 --- a/src/Godot/GameBootstrap.cs +++ b/src/Godot/GameBootstrap.cs @@ -82,7 +82,7 @@ public partial class GameBootstrap : Node ); ItemInteractionService itemInteractions = new(new HandsInventory(), ItemWorld, presenter); Interact interactions = new(interactionRegistry); - PlayerInteraction.Initialize(new PlayerId(Guid.NewGuid()), itemInteractions, interactions, _logger); + PlayerInteraction.Initialize(new PlayerId(Guid.NewGuid()), itemInteractions, interactions); } public override void _Ready()