feat: hooking observability.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Godot;
|
||||
using GodotHostTest.AetherBind;
|
||||
using GodotHostTest.Game.Target;
|
||||
@@ -19,8 +21,13 @@ public partial class LevelServiceSource : ServiceSource
|
||||
|
||||
[WithProvider]
|
||||
private void OnScopeCreated(IValueSetter<ITargetCollector> targetCollector,
|
||||
IValueSetter<ITargetSpawner> targetSpawner)
|
||||
IValueSetter<ITargetSpawner> targetSpawner, ActivitySource activitySource, IValueSetter<Activity> activity)
|
||||
{
|
||||
// ReSharper disable once ExplicitCallerInfoArgument - the caller name is not significant in this case
|
||||
var activityValue = activitySource.StartActivity("Level") ??
|
||||
throw new InvalidOperationException(
|
||||
"No listeners for the activity - is OpenTelemetry running?");
|
||||
activity.Set(activityValue);
|
||||
targetCollector.Set(_targetSpawner);
|
||||
targetSpawner.Set(_targetSpawner);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Diagnostics;
|
||||
using GodotHostTest.AetherBind;
|
||||
using GodotHostTest.Interfaces;
|
||||
using OwofGames.GodotLume;
|
||||
@@ -12,6 +13,8 @@ public static class LevelServices
|
||||
// current level / level data management
|
||||
.AddSingleton<ICurrentLevel, CurrentLevel>()
|
||||
.AddInstance<ILevelDataProvider, LevelsData>(levelsData)
|
||||
// value provider for activity
|
||||
.AddValueProvider<Activity, LevelScope>()
|
||||
// value providers to send data into level scope
|
||||
.AddValueProvider<ILevel, RootScope, LevelScope>()
|
||||
// value provider for level scope setup
|
||||
|
||||
@@ -3,6 +3,8 @@ using GodotHostTest.Game.Level;
|
||||
using GodotHostTest.Game.Score;
|
||||
using GodotHostTest.Game.Target;
|
||||
using GodotHostTest.Interfaces;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using OwofGames.AetherBind.Observability;
|
||||
using OwofGames.GodotLume;
|
||||
using RootServiceSource = GodotHostTest.AetherBind.RootServiceSource;
|
||||
|
||||
@@ -19,4 +21,9 @@ public partial class GameServiceSource : RootServiceSource
|
||||
.AddSingleton<IScore, TotalScore>()
|
||||
.AddLevelServices(_levelsData);
|
||||
}
|
||||
|
||||
protected override void ConfigureServices(IServiceCollection serviceCollection)
|
||||
{
|
||||
serviceCollection.AddObservability();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using Godot;
|
||||
using GodotHostTest.AetherBind;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OwofGames.AetherBind;
|
||||
|
||||
namespace GodotHostTest.Game.Turret;
|
||||
@@ -7,10 +8,12 @@ namespace GodotHostTest.Game.Turret;
|
||||
public partial class Turret : Sprite2D
|
||||
{
|
||||
[Export] private Node2D _launcher = null!;
|
||||
[Inject] private ILogger<Turret> _logger = null!;
|
||||
[Export] private PackedScene _projectilePackedScene = null!;
|
||||
|
||||
private double _rotationDirection;
|
||||
[Export] private double _rotationSpeed = 6;
|
||||
|
||||
[Inject] private ISceneInstantiator _sceneInstantiator = null!;
|
||||
|
||||
private void OnTimerTimeout()
|
||||
@@ -18,6 +21,7 @@ public partial class Turret : Sprite2D
|
||||
var projectile = _sceneInstantiator.Instantiate<Node2D>(_projectilePackedScene);
|
||||
projectile.Rotation = _launcher.Rotation;
|
||||
AddChild(projectile);
|
||||
_logger.LogInformation("Projectile launched.");
|
||||
}
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
|
||||
Reference in New Issue
Block a user