Skip to content

Commit

Permalink
Fixed vehicle services scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
benvalkin committed Dec 11, 2024
1 parent 3bf3c3f commit 16c1292
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
26 changes: 8 additions & 18 deletions UncreatedWarfare/Vehicles/Spawners/VehicleSpawnerStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Uncreated.Warfare.Vehicles;
/// <remarks>Decided to go with raw binary instead of SQL since this kind of relies on other level savedata and the map, plus it was easier.</remarks>

[Priority(-1 /* load after BuildableSaver and VehicleInfoStore */)]
public class VehicleSpawnerStore : ILayoutHostedService
public class VehicleSpawnerStore : ILayoutHostedService, IDisposable
{
private YamlDataStore<List<VehicleSpawnInfo>> _dataStore;
private readonly WarfareModule _warfare;
Expand Down Expand Up @@ -56,31 +56,16 @@ public VehicleSpawnerStore(WarfareModule warfare, IConfiguration configuration,

UniTask ILayoutHostedService.StartAsync(CancellationToken token)
{
if (Level.isLoaded)
{
OnLevelLoaded(Level.BUILD_INDEX_GAME);
}
else
{
Level.onLevelLoaded += OnLevelLoaded;
}

ReloadSpawners();
return UniTask.CompletedTask;
}

UniTask ILayoutHostedService.StopAsync(CancellationToken token)
{
Level.onLevelLoaded -= OnLevelLoaded;
_dataStore?.Dispose();
return UniTask.CompletedTask;
}
private void OnLevelLoaded(int level)
private void ReloadSpawners()
{
if (level != Level.BUILD_INDEX_GAME)
return;

Level.onLevelLoaded -= OnLevelLoaded;

_dataStore.Reload();
OnSpawnsReloaded?.Invoke();
}
Expand Down Expand Up @@ -144,4 +129,9 @@ public async UniTask SaveAsync(CancellationToken token = default)

_dataStore.Save(); // todo: make an async Save() function
}

public void Dispose()
{
_dataStore.Dispose();
}
}
6 changes: 3 additions & 3 deletions UncreatedWarfare/WarfareModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -519,11 +519,11 @@ private void ConfigureServices(ContainerBuilder bldr)

bldr.RegisterType<VehicleRequestService>()
.AsImplementedInterfaces().AsSelf()
.InstancePerMatchingLifetimeScope(LifetimeScopeTags.Session);
.SingleInstance();

bldr.RegisterType<VehicleSpawnerStore>()
.AsImplementedInterfaces().AsSelf()
.InstancePerMatchingLifetimeScope(LifetimeScopeTags.Session);
.SingleInstance();

bldr.RegisterType<VehicleSpawnerService>()
.AsImplementedInterfaces().AsSelf()
Expand Down

0 comments on commit 16c1292

Please sign in to comment.