Add Population Target and more deriveds

This commit is contained in:
2024-09-25 19:01:49 +02:00
parent efa5d452ea
commit cafa45bed3
4 changed files with 47 additions and 13 deletions

View File

@ -1,7 +1,9 @@
using System.Collections.ObjectModel;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using Microsoft.EntityFrameworkCore;
using ReactiveUI;
using ReactiveUI.SourceGenerators;
using StarsAssistant.Services;
using Splat;
@ -21,6 +23,12 @@ public partial class PlayerPlanetViewModel : ViewModelBase
throw new InvalidOperationException("PlayerPlanet ViewModels can only be created for player planets.");
Planet = planet;
PopulationTargetPercent = planet.PopulationTargetPercent;
_populationTargetHelper = this
.WhenAnyValue(vm => vm.PopulationTargetPercent)
.Select(popTgt => this.MaxPopulation * popTgt / 10000 * 100)
.ToProperty(this, vm => vm.PopulationTarget);
this.WhenActivated((CompositeDisposable disposables) =>
{
@ -101,6 +109,9 @@ public partial class PlayerPlanetViewModel : ViewModelBase
public int PctDamage => Planet.PctDamage ?? 0;
[Reactive]
private int _populationTargetPercent;
#endregion
#region Derived Properties
@ -123,6 +134,9 @@ public partial class PlayerPlanetViewModel : ViewModelBase
public int ResourcesFromFactories => GameEngine.ResourcesFromFactForPlayer(Population, Factories, Value);
[ObservableAsProperty]
private int _populationTarget;
#endregion
}