From e79a30824393d0f88e2d9efcb41a0a4608571991 Mon Sep 17 00:00:00 2001 From: Torben Nehmer Date: Sun, 17 Nov 2024 13:19:22 +0100 Subject: [PATCH] Intermediate fleet summaries attempt --- Stars Assistant/Services/FleetManager.cs | 74 --------------- .../ViewModels/PlayerPlanetViewModel.cs | 92 +++++++++++-------- Stars Assistant/Views/BuColView.axaml | 8 +- 3 files changed, 62 insertions(+), 112 deletions(-) diff --git a/Stars Assistant/Services/FleetManager.cs b/Stars Assistant/Services/FleetManager.cs index 47b3904..babd48a 100644 --- a/Stars Assistant/Services/FleetManager.cs +++ b/Stars Assistant/Services/FleetManager.cs @@ -37,84 +37,11 @@ public class FleetManager : IEnableLogger, IDisposable public IObservableCache FleetSummariesByDestination => _fleetSummariesByDestination.AsObservableCache(); - /// - /// Public accessor to the continously updated fleet summaries. - /// - // public IObservableCache FleetSummariesByDestination => _fleetSummaries.AsObservableCache(); - - /// - /// Disposal tracking - /// - // private IDisposable _fleetSummariesSubscription; - public FleetManager() { // CreateFleetSummariesLink(); } - // [MemberNotNull(nameof(_fleetSummariesSubscription))] - // protected void CreateFleetSummariesLink() - // { - // /* - // _fleetSummariesSubscription = _fleets.Connect() - // .Filter(fleet => fleet.TrueDestination != "-- ") - // .Log(this, $"{DateTime.Now.ToLongTimeString()} fleetWatcher filter", fleet => $"{fleet}") - // // .AutoRefreshOnObservable(fleet => fleet.WhenAnyValue( - // // f => f.Ironium, f => f.Boranium, f => f.Germanium, f => f.Colonists)) - // .Log(this, $"{DateTime.Now.ToLongTimeString()} fleetWatcher refresh", fleet => $"{fleet}") - // .GroupOn(fleet => fleet.TrueDestination) - // .Log(this, $"{DateTime.Now.ToLongTimeString()} fleetWatcher group", grp => $"{grp.TotalChanges} detected") - // .Transform(group => new FleetSummaryByDestination - // { - // Destination = group.GroupKey, - // TotalIronium = group.List.Items.Sum(f => f.Ironium), - // TotalBoranium = group.List.Items.Sum(f => f.Boranium), - // TotalGermanium = group.List.Items.Sum(f => f.Germanium), - // TotalColonists = group.List.Items.Sum(f => f.Colonists) - // }) - - // .AddKey(fs => fs.Destination) - // .Log(this, "FleetManager _fleetSummaries update", changes => - // $"{changes.Adds} adds, {changes.Updates} updates, {changes.Removes} removes" - // ) - // .PopulateInto(_fleetSummaries) - // ; - // */ - - // /* - // // Demo only - // var sourceCache = new SourceCache(fs => fs.Destination); - // var tmp = fleetSummaries - // .AddKey(fs => fs.Destination) - // .PopulateInto(sourceCache); - - // _fleetSummaries - // .ObserveOn(RxApp.MainThreadScheduler) - // .Bind(out summaries) - // .DisposeMany() - // .Subscribe(); - - // d1 = summaries - // .Subscribe(Observer.Create(f => - // { - // this.Log().Debug($"FleetSummaryByDestination observed: {f}"); - // } - // )); - - // d2 = _fleetSummaries - // .ObserveOn(RxApp.MainThreadScheduler) - // .Subscribe(x => - // { - // var lst = x.ToList(); - // foreach (var f in lst) - // { - // this.Log().Debug($"Reason {f.Reason}, Type {f.Type}: {f.Item.Current}"); - // } - // } - // ); - // */ - // } - /// /// Load the fleet records from the database and push them into our source cache. /// If the data has been freshly imported, call PostProcessImportedData first. @@ -201,7 +128,6 @@ public class FleetManager : IEnableLogger, IDisposable { if (disposing) { - // _fleetSummariesSubscription.Dispose(); _fleetSummariesByDestination.Dispose(); _fleets.Dispose(); } diff --git a/Stars Assistant/ViewModels/PlayerPlanetViewModel.cs b/Stars Assistant/ViewModels/PlayerPlanetViewModel.cs index 8cbf6e5..0598f80 100644 --- a/Stars Assistant/ViewModels/PlayerPlanetViewModel.cs +++ b/Stars Assistant/ViewModels/PlayerPlanetViewModel.cs @@ -50,7 +50,10 @@ public partial class PlayerPlanetViewModel : ViewModelBase .ToProperty(this, vm => vm.RemainingFactories); _factoryGermaniumDeltaHelper = this - .WhenAnyValue(vm => vm.RemainingFactories) + .WhenAnyValue(vm => vm.RemainingFactories, + vm => vm.EnRouteGermanium, + vm => vm.SurfaceGermanium, + (remFact, gerEnRoute, surGer) => remFact) .Select(gerCost => ComputeFactoryGermaniumDelta()) .ToProperty(this, vm => vm.FactoryGermaniumDelta); @@ -67,15 +70,36 @@ public partial class PlayerPlanetViewModel : ViewModelBase .Log(this, "fleetSummaryChange", change => $"{Name}: {change.Reason}: {change.Previous} => {change.Current}") ; - _populationEnRouteHelper = _fleetSummaryChanges + _enRoutePopulationHelper = _fleetSummaryChanges .Select(change => change.Reason != ChangeReason.Remove ? change.Current.TotalColonists : 0) - .Log(this, "PopulationEnRoute", pop => $"{Name}: {pop}") - .ToProperty(this, vm => vm.PopulationEnRoute) + .Log(this, "EnRoutePopulation", pop => $"{Name}: {pop}") + .ToProperty(this, vm => vm.EnRoutePopulation) ; + _enRouteIroniumHelper = _fleetSummaryChanges + .Select(change => change.Reason != ChangeReason.Remove ? change.Current.TotalIronium : 0) + .Log(this, "EnRouteIronium", ironium => $"{Name}: {ironium}") + .ToProperty(this, vm => vm.EnRouteIronium) + ; + + _enRouteBoraniumHelper = _fleetSummaryChanges + .Select(change => change.Reason != ChangeReason.Remove ? change.Current.TotalBoranium : 0) + .Log(this, "EnRouteBoranium", boranium => $"{Name}: {boranium}") + .ToProperty(this, vm => vm.EnRouteBoranium) + ; + + _enRouteGermaniumHelper = _fleetSummaryChanges + .Select(change => change.Reason != ChangeReason.Remove ? change.Current.TotalGermanium : 0) + .Log(this, "EnRouteGermanium", germanium => $"{Name}: {germanium}") + .ToProperty(this, vm => vm.EnRouteGermanium) + ; + this.WhenActivated((CompositeDisposable disposables) => { - disposables.Add(_populationEnRouteHelper); + disposables.Add(_enRoutePopulationHelper); + disposables.Add(_enRouteIroniumHelper); + disposables.Add(_enRouteBoraniumHelper); + disposables.Add(_enRouteGermaniumHelper); // /* handle activation */ // Disposable @@ -167,7 +191,7 @@ public partial class PlayerPlanetViewModel : ViewModelBase public int PopulationGrowth => GameEngine.PlanetPopGrowthForPlayer(Population, Value); - public int PopulationT1 => Population + PopulationGrowth /* TODO + Pop En Route */; + public int PopulationT1 => Population + PopulationGrowth + EnRoutePopulation; public int BuildableFactories => GameEngine.MaxBuildableFactoriesForPlayer(Value); @@ -187,27 +211,26 @@ public partial class PlayerPlanetViewModel : ViewModelBase public int AvailableGermanium => MRGermanium + SurfaceGermanium; - [ObservableAsProperty] - private int _populationTarget; + [ObservableAsProperty] private int _populationTarget; - [ObservableAsProperty] - private int _populationToShip; + [ObservableAsProperty] private int _populationToShip; - [ObservableAsProperty] - private int _targetFactories; + [ObservableAsProperty] private int _targetFactories; - [ObservableAsProperty] - private int _remainingFactories; + [ObservableAsProperty] private int _remainingFactories; - [ObservableAsProperty] - private int _factoryGermaniumDelta; + [ObservableAsProperty] private int _factoryGermaniumDelta; - [ObservableAsProperty] - private int _remainingMines; + [ObservableAsProperty] private int _remainingMines; - [ObservableAsProperty] - private int _populationEnRoute; + [ObservableAsProperty] private int _enRoutePopulation; + [ObservableAsProperty] private int _enRouteIronium; + + [ObservableAsProperty] private int _enRouteBoranium; + + [ObservableAsProperty] private int _enRouteGermanium; + #endregion #region Helper functions @@ -230,24 +253,19 @@ public partial class PlayerPlanetViewModel : ViewModelBase if (gerReq < AvailableGermanium) return Math.Max(0, SurfaceGermanium - gerReq); - return AvailableGermanium + MRGermanium - gerReq; - // TODO: Extrapolate to T1, so that excess Germanium is visible. - // TODO: Take shipping into account. + // When extrapolating to T1, we take the available Germanium + // this turn (surface + MR), add MR a second time (the mines + // will yield it next turn as well) and add the inbound shipping + // as this will be available next turn as well. That#s the basis + // for the Germanium requirement in the next turn. We will top + // it out at 0, as we don't have any Germanium available this + // turn, and we don't want to show a projected surplus here + // (we can't pull it off the planet in this turn anyway). + return Math.Min( + AvailableGermanium + EnRouteGermanium + MRGermanium - gerReq + , 0); } - - /* - private int ComputePopulationEnRoute() - { - using var db = Locator.Current.GetService()!; - - var enRoute = from flt in db.Fleet - where flt.OwnerFileId == Game.Player.PlayerFileId && flt.TrueDestination == Planet.Name - select new { Colonists = flt.Sum(f => f.Colonists) }; - - return enRoute.Colonists ?? 0; - } - */ - + #endregion } \ No newline at end of file diff --git a/Stars Assistant/Views/BuColView.axaml b/Stars Assistant/Views/BuColView.axaml index 1ee2dbc..7b54092 100644 --- a/Stars Assistant/Views/BuColView.axaml +++ b/Stars Assistant/Views/BuColView.axaml @@ -21,7 +21,7 @@ - + @@ -31,13 +31,19 @@ + + + + + +