diff --git a/Stars Assistant/Services/CSVDataLoader.cs b/Stars Assistant/Services/CSVDataLoader.cs index c844293..9dae7fd 100644 --- a/Stars Assistant/Services/CSVDataLoader.cs +++ b/Stars Assistant/Services/CSVDataLoader.cs @@ -94,8 +94,8 @@ public partial class CSVDataLoader : IEnableLogger var fleetLoader = new CSV.FleetLoader(); fleetLoader.ImportForRace(Services.Game.Player); - FleetManager.PostProcessImportedData(); FleetManager fleetManager = Locator.Current.GetService()!; + FleetManager.PostProcessImportedData(); fleetManager.InitFromDatabase(); break; diff --git a/Stars Assistant/Services/FleetManager.cs b/Stars Assistant/Services/FleetManager.cs index ca04f4c..02c6903 100644 --- a/Stars Assistant/Services/FleetManager.cs +++ b/Stars Assistant/Services/FleetManager.cs @@ -144,14 +144,16 @@ public class FleetManager : IEnableLogger, IDisposable } else { - flt.TrueDestination = "-- "; + flt.TrueDestination = flt.Planet; } Match m = shipPattern.Match(flt.FleetName); if (m.Success) flt.ShipTypeGuess = m.Groups[1].Value; - db.Update(flt); + flt.Colonists *= 100; + + db.Update(flt); } db.SaveChanges(); diff --git a/Stars Assistant/Services/Game.cs b/Stars Assistant/Services/Game.cs index dd8c5e5..0600601 100644 --- a/Stars Assistant/Services/Game.cs +++ b/Stars Assistant/Services/Game.cs @@ -135,18 +135,17 @@ public class Game GameEngine.Game = this; Locator.CurrentMutable.RegisterConstant(new CSVDataLoader(), typeof(CSVDataLoader)); Locator.CurrentMutable.Register(() => new StarsDatabase(DatabaseFileName), typeof(StarsDatabase)); - PlanetManager PlanetManager = new(); - Locator.CurrentMutable.RegisterConstant(PlanetManager, typeof(Services.PlanetManager)); FleetManager FleetManager = new(); Locator.CurrentMutable.RegisterConstant(FleetManager, typeof(Services.FleetManager)); + PlanetManager PlanetManager = new(); + Locator.CurrentMutable.RegisterConstant(PlanetManager, typeof(Services.PlanetManager)); // TESTING HELPER if (__doCreateTestData) __createTestData(); - PlanetManager.InitFromDatabase(); FleetManager.InitFromDatabase(); - FleetManager.test(); + PlanetManager.InitFromDatabase(); } /// diff --git a/Stars Assistant/Services/PlanetManager.cs b/Stars Assistant/Services/PlanetManager.cs index 19605da..e532f20 100644 --- a/Stars Assistant/Services/PlanetManager.cs +++ b/Stars Assistant/Services/PlanetManager.cs @@ -9,7 +9,7 @@ using StarsAssistant.ViewModels; namespace StarsAssistant.Services; -public class PlanetManager +public class PlanetManager : IDisposable, IEnableLogger { protected Services.Game Game = Locator.Current.GetService()!; @@ -27,7 +27,11 @@ public class PlanetManager .Filter(planet => planet.OwnerId == Game.Player.Name) .Transform(planet => new PlayerPlanetViewModel(planet)); - public PlanetManager() {} + public PlanetManager() + { + FleetManager fleetManager = Locator.Current.GetService()!; + + } /// /// Load the planet records from the database and push them into our source cache. @@ -47,4 +51,24 @@ public class PlanetManager } ); } + + /// + /// Handle disposal of all subscriptions and dependencies. + /// / + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + _planets.Dispose(); + } + } + + /// + /// Boilerplate disposal + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } } diff --git a/Stars Assistant/ViewModels/PlayerPlanetViewModel.cs b/Stars Assistant/ViewModels/PlayerPlanetViewModel.cs index ff75c90..3df2c8c 100644 --- a/Stars Assistant/ViewModels/PlayerPlanetViewModel.cs +++ b/Stars Assistant/ViewModels/PlayerPlanetViewModel.cs @@ -2,6 +2,7 @@ using System.Collections.ObjectModel; using System.Reactive.Disposables; using System.Reactive.Linq; using Microsoft.EntityFrameworkCore; +using DynamicData; using ReactiveUI; using ReactiveUI.SourceGenerators; using StarsAssistant.Services; @@ -55,8 +56,24 @@ public partial class PlayerPlanetViewModel : ViewModelBase .Select(remMines => Math.Max(0, GameEngine.MaxOperableMinesForPlayer(_populationTarget, Value) - Mines)) .ToProperty(this, vm => vm.RemainingMines); + FleetManager fm = Locator.Current.GetService()!; + + var fleetSummaryChanges = fm.FleetSummaries + .Connect() + .Watch(Name) + .Log(this, "fleetSummaryChange", change => $"{Name}: {change.Reason}: {change.Previous} => {change.Current}") + ; + + _populationEnRouteHelper = fleetSummaryChanges + .Select(change => change.Reason != ChangeReason.Remove ? change.Current.TotalColonists : 0) + .Log(this, "PopulationEnRoute", pop => $"{Name}: {pop}") + .ToProperty(this, vm => vm.PopulationEnRoute) + ; + this.WhenActivated((CompositeDisposable disposables) => { + disposables.Add(_populationEnRouteHelper); + // /* handle activation */ // Disposable // .Create(() => { /* handle deactivation */ }) @@ -185,6 +202,9 @@ public partial class PlayerPlanetViewModel : ViewModelBase [ObservableAsProperty] private int _remainingMines; + [ObservableAsProperty] + private int _populationEnRoute; + #endregion #region Helper functions diff --git a/Stars Assistant/Views/BuColView.axaml b/Stars Assistant/Views/BuColView.axaml index 31e7392..341e4ee 100644 --- a/Stars Assistant/Views/BuColView.axaml +++ b/Stars Assistant/Views/BuColView.axaml @@ -21,7 +21,7 @@ - +