Add logging functionality to GamePresenter and implement GodotLogger
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using CryptonymThunder.Code.Autoloads;
|
||||
using CryptonymThunder.Code.Factories;
|
||||
@@ -11,6 +12,8 @@ using GameCore.ECS.Interfaces;
|
||||
using GameCore.Events;
|
||||
using GameCore.Input;
|
||||
using GameCore.Inventory;
|
||||
using GameCore.Logging;
|
||||
using GameCore.Logging.Interfaces;
|
||||
using GameCore.Movement;
|
||||
using GameCore.Player;
|
||||
using Godot;
|
||||
@@ -30,6 +33,7 @@ public partial class GamePresenter : Node
|
||||
private GodotInputService _inputService;
|
||||
private GodotWorldQuery _worldQuery;
|
||||
private PresenterFactory _presenterFactory;
|
||||
private ILogger _logger = new NullLogger();
|
||||
|
||||
private readonly Dictionary<int, List<IPresenterComponent>> _presenterComponents = new();
|
||||
private readonly Dictionary<int, IEntityPresenter> _presenters = new();
|
||||
@@ -44,9 +48,17 @@ public partial class GamePresenter : Node
|
||||
if (SimulationConfig != null)
|
||||
{
|
||||
simConfig.GravityStrength = SimulationConfig.GravityStrength;
|
||||
|
||||
if (simConfig.LoggingEnabled)
|
||||
{
|
||||
_logger = new CompositeLogger(
|
||||
new GodotLogger(),
|
||||
new FileLogger("game_log.txt", LogLevel.Info)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
_world = new World(_inputService, _worldQuery, simConfig);
|
||||
_world = new World(_inputService, _worldQuery, simConfig, _logger);
|
||||
|
||||
var effectFactory = new EffectFactory();
|
||||
var componentFactory = new ComponentFactory(effectFactory);
|
||||
@@ -78,15 +90,6 @@ public partial class GamePresenter : Node
|
||||
|
||||
_world.Subscribe<EntityDiedEvent>(OnEntityDied);
|
||||
_world.Subscribe<SpawnEntityEvent>(OnSpawnEntity);
|
||||
_world.Subscribe<EquipWeaponEvent>(OnWeaponEquipped);
|
||||
_world.Subscribe<WeaponFiredEvent>(e =>
|
||||
{
|
||||
GD.Print($"Weapon fired by Entity ID: {e.Owner.Id}");
|
||||
});
|
||||
_world.Subscribe<WeaponFireFailedEvent>(e =>
|
||||
{
|
||||
GD.Print($"Weapon fire failed!");
|
||||
});
|
||||
|
||||
RegisterAllSceneEntities();
|
||||
|
||||
@@ -95,11 +98,6 @@ public partial class GamePresenter : Node
|
||||
_presenterComponents.Add(playerData.Entity.Id, playerData.Components);
|
||||
}
|
||||
|
||||
private void OnWeaponEquipped(EquipWeaponEvent e)
|
||||
{
|
||||
GD.Print($"Weapon equipped: {e.NewWeaponItemId} for Entity ID: {e.Owner.Id}");
|
||||
}
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
_inputService?.HandleInputEvent(@event);
|
||||
@@ -181,4 +179,12 @@ public partial class GamePresenter : Node
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
if (_logger is IDisposable disposableLogger)
|
||||
{
|
||||
disposableLogger.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
35
Code/Services/GodotLogger.cs
Normal file
35
Code/Services/GodotLogger.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using GameCore.Logging.Interfaces;
|
||||
using Godot;
|
||||
|
||||
namespace CryptonymThunder.Code.Services;
|
||||
|
||||
public class GodotLogger : ILogger
|
||||
{
|
||||
public void Debug(string message)
|
||||
{
|
||||
GD.Print($"[DEBUG] {message}");
|
||||
}
|
||||
|
||||
public void Info(string message)
|
||||
{
|
||||
GD.Print($"[INFO] {message}");
|
||||
}
|
||||
|
||||
public void Warn(string message)
|
||||
{
|
||||
GD.PushWarning(message);
|
||||
}
|
||||
|
||||
public void Error(string message, Exception ex = null)
|
||||
{
|
||||
if (ex != null)
|
||||
{
|
||||
GD.PrintErr($"[ERROR] {message} Exception: {ex}");
|
||||
}
|
||||
else
|
||||
{
|
||||
GD.PrintErr($"[ERROR] {message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
1
Code/Services/GodotLogger.cs.uid
Normal file
1
Code/Services/GodotLogger.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bu65qwpq5f8ba
|
||||
Reference in New Issue
Block a user