Move player to game engine.

This commit is contained in:
2024-09-21 14:40:13 +02:00
parent 63761001fa
commit e01a50ec9c
5 changed files with 30 additions and 21 deletions

View File

@ -53,6 +53,6 @@ public partial class CSVDataLoader : IEnableLogger
this.Log().Debug($"Got file type {type} for player {player}");
var loader = new CSV.PlanetLoader();
loader.ImportForRace(Model.Race.Player);
loader.ImportForRace(Services.Game.Player);
}
}

View File

@ -1,3 +1,4 @@
using System.Reflection.PortableExecutable;
using Splat;
namespace StarsAssistant.Services;
@ -64,6 +65,22 @@ public class Game
/// </summary>
public string PlanetFileSearchPattern => $"{BaseName}.p*";
/// <summary>
/// Internal helper to lazily load the current player from the DB.
/// </summary>
private readonly static Lazy<Model.Race>LazyPlayer = new ( () => {
using var db = Locator.Current.GetService<Model.StarsDatabase>()!;
Model.Race result = db.Race
.Where(r => r.PlayerRace == true)
.First();
return result;
});
/// <summary>
/// Get the Race object for the current player, lazy initialized.
/// </summary>
public static Model.Race Player => LazyPlayer.Value;
/// <summary>
/// Get the name of a planet file for a given race.
/// </summary>