Files
godot-host-test/Game/Level/LevelServiceSource.cs
T
redglow fc1df2f740 .
2026-07-27 19:51:17 +02:00

43 lines
1.5 KiB
C#

using System;
using System.Diagnostics;
using Godot;
using GodotHostTest.AetherBind;
using GodotHostTest.Game.Target;
using GodotHostTest.Interfaces;
using OwofGames.AetherBind;
using OwofGames.GodotHost.Observability;
using OwofGames.GodotLume;
using ServiceSource = GodotHostTest.AetherBind.ServiceSource;
namespace GodotHostTest.Game.Level;
public partial class LevelServiceSource : ServiceSource
{
private Activity? _activityValue;
[Export] private TargetSpawner _targetSpawner = null!;
protected override void OnScopeCreated(IProvider serviceProvider)
{
OnScopeCreatedWithProvider(serviceProvider);
}
[WithProvider]
private void OnScopeCreated(IValueSetter<ITargetCollector> targetCollector,
IValueSetter<ITargetSpawner> targetSpawner, IActivitySourceFactory activitySourceFactory,
IValueSetter<Activity> activity)
{
// ReSharper disable once ExplicitCallerInfoArgument - the caller name is not significant in this case
_activityValue = activitySourceFactory.ActivitySource.StartActivity("Level") ??
throw new InvalidOperationException(
"No listeners for the activity - is OpenTelemetry running?");
activity.Set(_activityValue);
targetCollector.Set(_targetSpawner);
targetSpawner.Set(_targetSpawner);
}
public override void _Ready()
{
// after 3 seconds, dispose the activity for simulation purposes
GetTree().CreateTimer(3).Timeout += _activityValue!.Dispose;
}
}