bind fleet summaries, fixup fleet post processing
This commit is contained in:
parent
d32ecdcead
commit
5a933d7aea
@ -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>()!;
|
||||
FleetManager.PostProcessImportedData();
|
||||
fleetManager.InitFromDatabase();
|
||||
break;
|
||||
|
||||
|
@ -144,13 +144,15 @@ 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;
|
||||
|
||||
flt.Colonists *= 100;
|
||||
|
||||
db.Update(flt);
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -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<Services.Game>()!;
|
||||
|
||||
@ -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<FleetManager>()!;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.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<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) =>
|
||||
{
|
||||
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
|
||||
|
@ -21,7 +21,7 @@
|
||||
<DataGridTextColumn Header="Pop" Binding="{Binding Population}" />
|
||||
<DataGridTextColumn Header="Pop to Ship" Binding="{Binding PopulationToShip}" />
|
||||
<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 %" Binding="{Binding CapacityPercent}" />
|
||||
<!-- Terra Delta assumed -->
|
||||
|
Loading…
Reference in New Issue
Block a user