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);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user