Intermediate, add dynamic data, not yet w/o errors/warnings

This commit is contained in:
2024-09-25 22:27:35 +02:00
parent cafa45bed3
commit a394918064
4 changed files with 56 additions and 5 deletions

View File

@ -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)

View 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);
}
}
}