Intermediate, fixes a lot of update problems, keeping selection in place when updating planets still broken.

This commit is contained in:
2024-11-27 18:40:14 +01:00
parent e79a308243
commit 4789904284
4 changed files with 45 additions and 10 deletions

View File

@ -1,6 +1,9 @@
using System;
using System.ComponentModel;
using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using DynamicData;
using DynamicData.Binding;
using Splat;
@ -27,10 +30,21 @@ public class PlanetManager : IDisposable, IEnableLogger
.Filter(planet => planet.OwnerId == Game.Player.Name)
.Transform(planet => new PlayerPlanetViewModel(planet));
/// <summary>
/// Observable subject to trigger when we update the planet cache, allows the
/// UI to react to it.
/// </summary>
private readonly Subject<Unit> _planetsReloadedSubject = new();
/// <summary>
/// Exposes _planetReloadedSubject as IObservable.
/// </summary>
public IObservable<Unit> PlanetsReloaded => _planetsReloadedSubject.AsObservable();
public PlanetManager()
{
FleetManager fleetManager = Locator.Current.GetService<FleetManager>()!;
}
/// <summary>
@ -50,6 +64,7 @@ public class PlanetManager : IDisposable, IEnableLogger
innerCache.AddOrUpdate(allPlanets);
}
);
_planetsReloadedSubject.OnNext(Unit.Default);
}
/// <summary>
@ -60,6 +75,7 @@ public class PlanetManager : IDisposable, IEnableLogger
if (disposing)
{
_planets.Dispose();
_planetsReloadedSubject.Dispose();
}
}