diff --git a/Stars Assistant/Model/Game.cs b/Stars Assistant/Model/Game.cs new file mode 100644 index 0000000..0222ce9 --- /dev/null +++ b/Stars Assistant/Model/Game.cs @@ -0,0 +1,34 @@ +using System.ComponentModel.DataAnnotations; +using System.Globalization; + +namespace StarsAssistant.Model; + +public class Game (string gamePath, string baseName) +{ + /// + /// The base path in which all game files reside. + /// + public string GamePath { get; private set; } = gamePath; + + /// + /// The base name without extensions of your game, inside the GamePath folder. + /// All dependant files are resolved using this name. + /// + public string BaseName { get; private set; } = baseName; + + /// + /// The number of the player, for example identifying the pxx planet file. + /// + public int PlayerId { get; private set; } + + /// + /// Combine into the DatabaseName + /// + public string DatabaseName => Path.Combine(GamePath, $"{BaseName}.sqlite"); + + /// + /// Search for Planet files using this pattern, will give you all pxx files. + /// + public string PlanetFileSearchPattern => Path.Combine(GamePath, $"{BaseName}.p*"); + +} diff --git a/Stars Assistant/Model/StarsDatabase.cs b/Stars Assistant/Model/StarsDatabase.cs index 9f0e990..58bc17d 100644 --- a/Stars Assistant/Model/StarsDatabase.cs +++ b/Stars Assistant/Model/StarsDatabase.cs @@ -34,5 +34,10 @@ public class StarsDatabase(string DbPath) : DbContext /// public DbSet Race { get; set; } + /// + /// The record with all game metadata, will only contain a single line at all times. + /// + public DbSet Game { get; set; } + #endregion } \ No newline at end of file diff --git a/Stars Assistant/Program.cs b/Stars Assistant/Program.cs index 4f905f3..22a9089 100644 --- a/Stars Assistant/Program.cs +++ b/Stars Assistant/Program.cs @@ -21,6 +21,7 @@ sealed class Program public static void Main(string[] args) { ModeDetector.OverrideModeDetector(Splat.ModeDetection.Mode.Run); + Locator.CurrentMutable.Register( () => new StarsDatabase("stars.sqlite"), typeof(StarsDatabase) diff --git a/Stars Assistant/Services/CSVDataLoader.cs b/Stars Assistant/Services/CSVDataLoader.cs new file mode 100644 index 0000000..14d512e --- /dev/null +++ b/Stars Assistant/Services/CSVDataLoader.cs @@ -0,0 +1,20 @@ +using System; +using CsvHelper.Configuration; +using CsvHelper; +using Splat; + +namespace StarsAssistant.Services; + + +public class CSVDataLoader +{ + /// + /// Reference to the game metadata, retrieved by DI + /// + protected Model.Game game; + + public CSVDataLoader() + { + game = Locator.Current.GetService()!; + } +} diff --git a/Stars Assistant/ViewModels/MainWindowViewModel.cs b/Stars Assistant/ViewModels/MainWindowViewModel.cs index 81c8068..fbed864 100644 --- a/Stars Assistant/ViewModels/MainWindowViewModel.cs +++ b/Stars Assistant/ViewModels/MainWindowViewModel.cs @@ -3,6 +3,8 @@ using System.Reactive.Disposables; using System.Reactive.Linq; using ReactiveUI; using ReactiveUI.SourceGenerators; +using Splat; +using StarsAssistant.Model; namespace StarsAssistant.ViewModels; @@ -11,13 +13,13 @@ public partial class MainWindowViewModel : ViewModelBase, IActivatableViewModel public ViewModelActivator Activator { get; } = new ViewModelActivator(); [ObservableAsProperty] - private string _welcomeMessage; + private string _dbPath = ""; public MainWindowViewModel() { - _welcomeMessage = "Lorem Ipsum"; - _welcomeMessageHelper = Observable.Return("Dolor sit amet") - .ToProperty(this, x => x.WelcomeMessage); + using var db = Locator.Current.GetService()!; + _dbPathHelper = Observable.Return(Path.GetFullPath(db.DbPath)) + .ToProperty(this, x => x.DbPath); this.WhenActivated((CompositeDisposable disposables) => { diff --git a/Stars Assistant/ViewModels/PlanetViewModel.cs b/Stars Assistant/ViewModels/PlanetViewModel.cs index b53f45b..e1a3dfc 100644 --- a/Stars Assistant/ViewModels/PlanetViewModel.cs +++ b/Stars Assistant/ViewModels/PlanetViewModel.cs @@ -7,7 +7,8 @@ namespace StarsAssistant.ViewModels; public partial class PlanetViewModel(Planet planet) : ViewModelBase { - public static ObservableCollection LoadAll() { + public static ObservableCollection LoadAll() + { using var db = Locator.Current.GetService()!; var result = new ObservableCollection(); foreach (Planet planet in db.Planet.Where(p => p.OwnerId == "Atlantis").ToList()) diff --git a/Stars Assistant/Views/MainWindow.axaml b/Stars Assistant/Views/MainWindow.axaml index 1f2e8a9..bcaadb7 100644 --- a/Stars Assistant/Views/MainWindow.axaml +++ b/Stars Assistant/Views/MainWindow.axaml @@ -18,31 +18,24 @@ - - Hi + + + + + + + + + - - - - - - - - - - - - - - - diff --git a/Stars Assistant/Views/MainWindow.axaml.cs b/Stars Assistant/Views/MainWindow.axaml.cs index 0d7ff77..1e6100e 100644 --- a/Stars Assistant/Views/MainWindow.axaml.cs +++ b/Stars Assistant/Views/MainWindow.axaml.cs @@ -13,19 +13,11 @@ public partial class MainWindow : ReactiveWindow { public MainWindow() { - this.WhenActivated( - - disposables => { - this.OneWayBind(ViewModel, - viewModel => viewModel.Planets, - view => view.PlanetsGrid.ItemsSource) - .DisposeWith(disposables); - this.OneWayBind(ViewModel, - vm => vm.WelcomeMessage, - v => v.WelcomeText.Text) - .DisposeWith(disposables); - } - ); + this.WhenActivated(disposables => + { + this.OneWayBind(ViewModel, vm => vm.DbPath, v => v.DbPath.Text) + .DisposeWith(disposables); + }); InitializeComponent(); }