bind fleet summaries, fixup fleet post processing
This commit is contained in:
		| @@ -94,8 +94,8 @@ public partial class CSVDataLoader : IEnableLogger | |||||||
|                 var fleetLoader = new CSV.FleetLoader(); |                 var fleetLoader = new CSV.FleetLoader(); | ||||||
|                 fleetLoader.ImportForRace(Services.Game.Player); |                 fleetLoader.ImportForRace(Services.Game.Player); | ||||||
|  |  | ||||||
|                 FleetManager.PostProcessImportedData();  |  | ||||||
|                 FleetManager fleetManager = Locator.Current.GetService<FleetManager>()!; |                 FleetManager fleetManager = Locator.Current.GetService<FleetManager>()!; | ||||||
|  |                 FleetManager.PostProcessImportedData();  | ||||||
|                 fleetManager.InitFromDatabase(); |                 fleetManager.InitFromDatabase(); | ||||||
|                 break; |                 break; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -144,13 +144,15 @@ public class FleetManager : IEnableLogger, IDisposable | |||||||
|             } |             } | ||||||
|             else |             else | ||||||
|             { |             { | ||||||
|                 flt.TrueDestination = "-- "; |                 flt.TrueDestination = flt.Planet; | ||||||
|             } |             } | ||||||
|              |              | ||||||
|             Match m = shipPattern.Match(flt.FleetName); |             Match m = shipPattern.Match(flt.FleetName); | ||||||
|             if (m.Success) |             if (m.Success) | ||||||
|                 flt.ShipTypeGuess = m.Groups[1].Value; |                 flt.ShipTypeGuess = m.Groups[1].Value; | ||||||
|  |  | ||||||
|  |             flt.Colonists *= 100; | ||||||
|  |  | ||||||
|             db.Update(flt); |             db.Update(flt); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -135,18 +135,17 @@ public class Game | |||||||
|         GameEngine.Game = this; |         GameEngine.Game = this; | ||||||
|         Locator.CurrentMutable.RegisterConstant(new CSVDataLoader(), typeof(CSVDataLoader)); |         Locator.CurrentMutable.RegisterConstant(new CSVDataLoader(), typeof(CSVDataLoader)); | ||||||
|         Locator.CurrentMutable.Register(() => new StarsDatabase(DatabaseFileName), typeof(StarsDatabase)); |         Locator.CurrentMutable.Register(() => new StarsDatabase(DatabaseFileName), typeof(StarsDatabase)); | ||||||
|         PlanetManager PlanetManager = new(); |  | ||||||
|         Locator.CurrentMutable.RegisterConstant(PlanetManager, typeof(Services.PlanetManager)); |  | ||||||
|         FleetManager FleetManager = new(); |         FleetManager FleetManager = new(); | ||||||
|         Locator.CurrentMutable.RegisterConstant(FleetManager, typeof(Services.FleetManager)); |         Locator.CurrentMutable.RegisterConstant(FleetManager, typeof(Services.FleetManager)); | ||||||
|  |         PlanetManager PlanetManager = new(); | ||||||
|  |         Locator.CurrentMutable.RegisterConstant(PlanetManager, typeof(Services.PlanetManager)); | ||||||
|  |  | ||||||
|         // TESTING HELPER |         // TESTING HELPER | ||||||
|         if (__doCreateTestData) |         if (__doCreateTestData) | ||||||
|             __createTestData(); |             __createTestData(); | ||||||
|  |  | ||||||
|         PlanetManager.InitFromDatabase(); |  | ||||||
|         FleetManager.InitFromDatabase(); |         FleetManager.InitFromDatabase(); | ||||||
|         FleetManager.test(); |         PlanetManager.InitFromDatabase(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|   | |||||||
| @@ -9,7 +9,7 @@ using StarsAssistant.ViewModels; | |||||||
|  |  | ||||||
| namespace StarsAssistant.Services; | namespace StarsAssistant.Services; | ||||||
|  |  | ||||||
| public class PlanetManager | public class PlanetManager : IDisposable, IEnableLogger | ||||||
| { | { | ||||||
|     protected Services.Game Game = Locator.Current.GetService<Services.Game>()!; |     protected Services.Game Game = Locator.Current.GetService<Services.Game>()!; | ||||||
|  |  | ||||||
| @@ -27,7 +27,11 @@ public class PlanetManager | |||||||
|                 .Filter(planet => planet.OwnerId == Game.Player.Name) |                 .Filter(planet => planet.OwnerId == Game.Player.Name) | ||||||
|                 .Transform(planet => new PlayerPlanetViewModel(planet)); |                 .Transform(planet => new PlayerPlanetViewModel(planet)); | ||||||
|  |  | ||||||
|     public PlanetManager() {} |     public PlanetManager()  | ||||||
|  |     { | ||||||
|  |         FleetManager fleetManager = Locator.Current.GetService<FleetManager>()!; | ||||||
|  |          | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// Load the planet records from the database and push them into our source cache. |     /// Load the planet records from the database and push them into our source cache. | ||||||
| @@ -47,4 +51,24 @@ public class PlanetManager | |||||||
|             } |             } | ||||||
|         ); |         ); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// Handle disposal of all subscriptions and dependencies. | ||||||
|  |     /// </summary>/ | ||||||
|  |     protected virtual void Dispose(bool disposing) | ||||||
|  |     { | ||||||
|  |         if (disposing) | ||||||
|  |         { | ||||||
|  |             _planets.Dispose(); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /// <summary> | ||||||
|  |     /// Boilerplate disposal | ||||||
|  |     /// </summary> | ||||||
|  |     public void Dispose() | ||||||
|  |     { | ||||||
|  |         Dispose(true); | ||||||
|  |         GC.SuppressFinalize(this); | ||||||
|  |     }     | ||||||
| } | } | ||||||
|   | |||||||
| @@ -2,6 +2,7 @@ using System.Collections.ObjectModel; | |||||||
| using System.Reactive.Disposables; | using System.Reactive.Disposables; | ||||||
| using System.Reactive.Linq; | using System.Reactive.Linq; | ||||||
| using Microsoft.EntityFrameworkCore; | using Microsoft.EntityFrameworkCore; | ||||||
|  | using DynamicData; | ||||||
| using ReactiveUI; | using ReactiveUI; | ||||||
| using ReactiveUI.SourceGenerators; | using ReactiveUI.SourceGenerators; | ||||||
| using StarsAssistant.Services; | using StarsAssistant.Services; | ||||||
| @@ -55,8 +56,24 @@ public partial class PlayerPlanetViewModel : ViewModelBase | |||||||
|             .Select(remMines => Math.Max(0, GameEngine.MaxOperableMinesForPlayer(_populationTarget, Value) - Mines)) |             .Select(remMines => Math.Max(0, GameEngine.MaxOperableMinesForPlayer(_populationTarget, Value) - Mines)) | ||||||
|             .ToProperty(this, vm => vm.RemainingMines); |             .ToProperty(this, vm => vm.RemainingMines); | ||||||
|  |  | ||||||
|  |         FleetManager fm = Locator.Current.GetService<FleetManager>()!; | ||||||
|  |  | ||||||
|  |         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) =>  |         this.WhenActivated((CompositeDisposable disposables) =>  | ||||||
|         { |         { | ||||||
|  |             disposables.Add(_populationEnRouteHelper); | ||||||
|  |  | ||||||
|             // /* handle activation */ |             // /* handle activation */ | ||||||
|             // Disposable |             // Disposable | ||||||
|             //     .Create(() => { /* handle deactivation */ }) |             //     .Create(() => { /* handle deactivation */ }) | ||||||
| @@ -185,6 +202,9 @@ public partial class PlayerPlanetViewModel : ViewModelBase | |||||||
|     [ObservableAsProperty] |     [ObservableAsProperty] | ||||||
|     private int _remainingMines; |     private int _remainingMines; | ||||||
|  |  | ||||||
|  |     [ObservableAsProperty] | ||||||
|  |     private int _populationEnRoute; | ||||||
|  |  | ||||||
|     #endregion |     #endregion | ||||||
|  |  | ||||||
|     #region Helper functions |     #region Helper functions | ||||||
|   | |||||||
| @@ -21,7 +21,7 @@ | |||||||
|         <DataGridTextColumn Header="Pop" Binding="{Binding Population}" /> |         <DataGridTextColumn Header="Pop" Binding="{Binding Population}" /> | ||||||
|         <DataGridTextColumn Header="Pop to Ship" Binding="{Binding PopulationToShip}" /> |         <DataGridTextColumn Header="Pop to Ship" Binding="{Binding PopulationToShip}" /> | ||||||
|         <DataGridTextColumn Header="Growth" Binding="{Binding PopulationGrowth}" /> |         <DataGridTextColumn Header="Growth" Binding="{Binding PopulationGrowth}" /> | ||||||
|         <!-- Pop en route --> |         <DataGridTextColumn Header="Pop T1" Binding="{Binding PopulationEnRoute}" /> | ||||||
|         <DataGridTextColumn Header="Pop T%" Binding="{Binding PopulationTargetPercent}" IsReadOnly="false"/> |         <DataGridTextColumn Header="Pop T%" Binding="{Binding PopulationTargetPercent}" IsReadOnly="false"/> | ||||||
|         <DataGridTextColumn Header="Pop %" Binding="{Binding CapacityPercent}" /> |         <DataGridTextColumn Header="Pop %" Binding="{Binding CapacityPercent}" /> | ||||||
|         <!-- Terra Delta assumed --> |         <!-- Terra Delta assumed --> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user