Implement BuCol

This commit is contained in:
2024-09-24 22:32:13 +02:00
parent 800dcf23ba
commit efa5d452ea
8 changed files with 188 additions and 35 deletions

View File

@ -21,5 +21,5 @@ public partial class BuColViewModel : ViewModelBase
});
}
public ObservableCollection<PlanetViewModel> Planets { get; } = PlanetViewModel.LoadAll();
public ObservableCollection<PlayerPlanetViewModel> Planets { get; } = PlanetViewModel.LoadAll();
}

View File

@ -9,6 +9,8 @@ namespace StarsAssistant.ViewModels;
public partial class PlanetViewModel : ViewModelBase
{
private readonly Planet Planet;
public PlanetViewModel(Planet planet)
{
Planet = planet;
@ -22,7 +24,6 @@ public partial class PlanetViewModel : ViewModelBase
});
}
private readonly Planet Planet;
public string Name => Planet.Name;
@ -42,13 +43,14 @@ public partial class PlanetViewModel : ViewModelBase
// ### TESTING CODE ###
public static ObservableCollection<PlanetViewModel> LoadAll()
public static ObservableCollection<PlayerPlanetViewModel> LoadAll()
{
using var db = Locator.Current.GetService<StarsDatabase>()!;
var result = new ObservableCollection<PlanetViewModel>();
var result = new ObservableCollection<PlayerPlanetViewModel>();
foreach (Planet planet in db.Planet.Where(p => p.OwnerId == "Atlantis").ToList())
// foreach (Planet planet in db.Planet.Where(p => p.Name == "Saddam").ToList())
{
var vm = new PlanetViewModel(planet);
var vm = new PlayerPlanetViewModel(planet);
result.Add(vm);
}
return result;

View File

@ -0,0 +1,128 @@
using System.Collections.ObjectModel;
using System.Reactive.Disposables;
using Microsoft.EntityFrameworkCore;
using ReactiveUI;
using StarsAssistant.Services;
using Splat;
namespace StarsAssistant.ViewModels;
public partial class PlayerPlanetViewModel : ViewModelBase
{
private readonly Model.Planet Planet;
private Game Game;
public PlayerPlanetViewModel(Model.Planet planet)
{
Game = Locator.Current.GetService<Game>()!;
if (planet.OwnerId != Game.Player.Name)
throw new InvalidOperationException("PlayerPlanet ViewModels can only be created for player planets.");
Planet = planet;
this.WhenActivated((CompositeDisposable disposables) =>
{
// /* handle activation */
// Disposable
// .Create(() => { /* handle deactivation */ })
// .DisposeWith(disposables);
});
}
#region Database Properties
public string Name => Planet.Name;
public string Owner => Planet.OwnerId;
public string StarbaseType => Planet.StarbaseType;
public int Population => Planet.Population ?? 0;
public int Value => Planet.Value ?? 0;
public int Mines => Planet.Mines ?? 0;
public int Factories => Planet.Factories ?? 0;
public decimal DefPercent => Planet.DefPercent ?? 0;
public int SurfaceIronium => Planet.SurfaceIronium ?? 0;
public int SurfaceBoranium => Planet.SurfaceBoranium ?? 0;
public int SurfaceGermanium => Planet.SurfaceGermanium ?? 0;
public int MRIronium => Planet.MRIronium ?? 0;
public int MRBoranium => Planet.MRBoranium ?? 0;
public int MRGermanium => Planet.MRGermanium ?? 0;
public int MCIronium => Planet.MCIronium ?? 0;
public int MCBoranium => Planet.MCBoranium ?? 0;
public int MCGermanium => Planet.MCGermanium ?? 0;
public int Resources => Planet.Resources ?? 0;
public decimal Gravity => Planet.Gravity ?? 0;
public decimal Temperature => Planet.Temperature ?? 0;
public decimal Radiation => Planet.Radiation ?? 0;
public decimal GravityOrig => Planet.GravityOrig ?? 0;
public decimal TemperatureOrig => Planet.TemperatureOrig ?? 0;
public decimal RadiationOrig => Planet.RadiationOrig ?? 0;
public int MaxTerraforming => Planet.MaxTerraforming ?? 0;
public int CapacityPercent => Planet.CapacityPercent ?? 0;
public int ScanRange => Planet.ScanRange ?? 0;
public int PenScanRange => Planet.PenScanRange ?? 0;
public int Driver => Planet.Driver ?? 0;
public int DriverWarp => Planet.DriverWarp ?? 0;
public string RouteTarget => Planet.RouteTarget;
public int GateRange => Planet.GateRange ?? 0;
public int GateMass => Planet.GateMass ?? 0;
public int PctDamage => Planet.PctDamage ?? 0;
#endregion
#region Derived Properties
public int EffectiveValue => GameEngine.EffectivePlanetValue(Value);
public int MaxPopulation => GameEngine.MaxPopOnPlanetForPlayer(Value);
public int PopulationGrowth => GameEngine.PlanetPopGrowthForPlayer(Population, Value);
public int BuildableFactories => GameEngine.MaxBuildableFactoriesForPlayer(Value);
public int BuildableMines => GameEngine.MaxBuildableMinesForPlayer(Value);
public int OperableFactories => GameEngine.MaxOperableFactoriesForPlayer(Population, Value);
public int OperableMines => GameEngine.MaxOperableMinesForPlayer(Population, Value);
public int ResourcesFromPopulation => GameEngine.ResourcesFromPopForPlayer(Population, Value);
public int ResourcesFromFactories => GameEngine.ResourcesFromFactForPlayer(Population, Factories, Value);
#endregion
}