Intermediate, add dynamic data, not yet w/o errors/warnings
This commit is contained in:
		@@ -123,6 +123,7 @@ public class Game
 | 
			
		||||
        GameEngine.Game = this;
 | 
			
		||||
        Locator.CurrentMutable.RegisterConstant(new CSVDataLoader(), typeof(CSVDataLoader));
 | 
			
		||||
        Locator.CurrentMutable.Register(() => new StarsDatabase(DatabaseFileName), typeof(StarsDatabase));
 | 
			
		||||
        Locator.CurrentMutable.RegisterConstant(new PlanetManager(), typeof(Services.PlanetManager));
 | 
			
		||||
 | 
			
		||||
        // TESTING HELPER
 | 
			
		||||
        if (__doCreateTestData)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										36
									
								
								Stars Assistant/Services/PlanetManager.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								Stars Assistant/Services/PlanetManager.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,36 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.ComponentModel;
 | 
			
		||||
using System.Reactive.Linq;
 | 
			
		||||
using DynamicData;
 | 
			
		||||
using DynamicData.Binding;
 | 
			
		||||
using Splat;
 | 
			
		||||
using StarsAssistant.Model;
 | 
			
		||||
using StarsAssistant.ViewModels;
 | 
			
		||||
 | 
			
		||||
namespace StarsAssistant.Services;
 | 
			
		||||
 | 
			
		||||
public class PlanetManager
 | 
			
		||||
{
 | 
			
		||||
    protected Services.Game Game = Locator.Current.GetService<Services.Game>()!;
 | 
			
		||||
 | 
			
		||||
    private SourceCache<Planet, string> _planets = new(p => p.Name);
 | 
			
		||||
 | 
			
		||||
    public IObservable<IChangeSet<PlayerPlanetViewModel, string>> PlayerPlanetsSource
 | 
			
		||||
        =>  _planets
 | 
			
		||||
                .Connect()
 | 
			
		||||
                .Filter(planet => planet.OwnerId == Game.Player.Name)
 | 
			
		||||
                .Transform(planet => new PlayerPlanetViewModel(planet));
 | 
			
		||||
 | 
			
		||||
    public PlanetManager()
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void __test__Init()
 | 
			
		||||
    {
 | 
			
		||||
        using var db = Locator.Current.GetService<StarsDatabase>()!;
 | 
			
		||||
        {
 | 
			
		||||
            var playerPlanets = db.Planet.ToList();
 | 
			
		||||
            _planets.AddOrUpdate(playerPlanets);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,17 +1,31 @@
 | 
			
		||||
using System.Collections.ObjectModel;
 | 
			
		||||
using System.Reactive.Disposables;
 | 
			
		||||
using System.Reactive.Linq;
 | 
			
		||||
 | 
			
		||||
using DynamicData;
 | 
			
		||||
using ReactiveUI;
 | 
			
		||||
using ReactiveUI.SourceGenerators;
 | 
			
		||||
using Splat;
 | 
			
		||||
using StarsAssistant.Model;
 | 
			
		||||
using StarsAssistant.Services;
 | 
			
		||||
 | 
			
		||||
namespace StarsAssistant.ViewModels;
 | 
			
		||||
 | 
			
		||||
public partial class BuColViewModel : ViewModelBase
 | 
			
		||||
{
 | 
			
		||||
    private readonly ReadOnlyObservableCollection<PlayerPlanetViewModel> _playerPlanetsView;
 | 
			
		||||
    public ReadOnlyObservableCollection<PlayerPlanetViewModel> PlayerPlanets => _playerPlanetsView;
 | 
			
		||||
 | 
			
		||||
    public BuColViewModel()
 | 
			
		||||
    {
 | 
			
		||||
        var PlanetManager = Locator.Current.GetService<PlanetManager>()!;
 | 
			
		||||
        PlanetManager.__test__Init();
 | 
			
		||||
 | 
			
		||||
        PlanetManager.PlayerPlanetsSource
 | 
			
		||||
            .ObserveOn(RxApp.MainThreadScheduler)
 | 
			
		||||
            .Bind(out _playerPlanetsView)
 | 
			
		||||
            .DisposeMany()
 | 
			
		||||
            .Subscribe();
 | 
			
		||||
 | 
			
		||||
        this.WhenActivated((CompositeDisposable disposables) => 
 | 
			
		||||
        {
 | 
			
		||||
            // /* handle activation */
 | 
			
		||||
@@ -21,5 +35,4 @@ public partial class BuColViewModel : ViewModelBase
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ObservableCollection<PlayerPlanetViewModel> Planets { get; } = PlanetViewModel.LoadAll();
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -9,9 +9,10 @@
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  <DataGrid x:Name="PlanetsGrid"
 | 
			
		||||
    ItemsSource="{Binding Planets}"
 | 
			
		||||
    ItemsSource="{Binding PlayerPlanets}"
 | 
			
		||||
    GridLinesVisibility="All"
 | 
			
		||||
    FrozenColumnCount="1"
 | 
			
		||||
    
 | 
			
		||||
    BorderThickness="1" BorderBrush="Gray">
 | 
			
		||||
    <DataGrid.Columns>
 | 
			
		||||
        <DataGridTextColumn Header="Planet" Binding="{Binding Name}" />
 | 
			
		||||
@@ -21,8 +22,8 @@
 | 
			
		||||
        <!-- Pop To Ship -->
 | 
			
		||||
        <DataGridTextColumn Header="Growth" Binding="{Binding PopulationGrowth}" />
 | 
			
		||||
        <!-- Pop en route -->
 | 
			
		||||
        <DataGridTextColumn Header="Pop Tgt %" Binding="{Binding PopulationTargetPercent}" />
 | 
			
		||||
        <DataGridTextColumn Header="Pop%" Binding="{Binding CapacityPercent}" />
 | 
			
		||||
        <DataGridTextColumn Header="Pop T%" Binding="{Binding PopulationTargetPercent}" IsReadOnly="false"/>
 | 
			
		||||
        <DataGridTextColumn Header="Pop %" Binding="{Binding CapacityPercent}" />
 | 
			
		||||
        <!-- Terra Delta assumed -->
 | 
			
		||||
        <DataGridTextColumn Header="Value" Binding="{Binding Value}" />
 | 
			
		||||
        <!-- Effective Value including Terra Delta -->
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user