sa/Stars Assistant/Services/PlanetManager.cs
2024-09-26 22:18:50 +02:00

37 lines
997 B
C#

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 InitFromDatabase()
{
using var db = Locator.Current.GetService<StarsDatabase>()!;
{
var allPlanets = db.Planet.ToList();
_planets.AddOrUpdate(allPlanets);
}
}
}