Started UI Rework for target game setup, started adding a Game master record and a CSV Loader service
This commit is contained in:
parent
c339ca5d3f
commit
227d8a11d7
34
Stars Assistant/Model/Game.cs
Normal file
34
Stars Assistant/Model/Game.cs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
|
namespace StarsAssistant.Model;
|
||||||
|
|
||||||
|
public class Game (string gamePath, string baseName)
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The base path in which all game files reside.
|
||||||
|
/// </summary>
|
||||||
|
public string GamePath { get; private set; } = gamePath;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The base name without extensions of your game, inside the GamePath folder.
|
||||||
|
/// All dependant files are resolved using this name.
|
||||||
|
/// </summary>
|
||||||
|
public string BaseName { get; private set; } = baseName;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The number of the player, for example identifying the pxx planet file.
|
||||||
|
/// </summary>
|
||||||
|
public int PlayerId { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Combine into the DatabaseName
|
||||||
|
/// </summary>
|
||||||
|
public string DatabaseName => Path.Combine(GamePath, $"{BaseName}.sqlite");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Search for Planet files using this pattern, will give you all pxx files.
|
||||||
|
/// </summary>
|
||||||
|
public string PlanetFileSearchPattern => Path.Combine(GamePath, $"{BaseName}.p*");
|
||||||
|
|
||||||
|
}
|
@ -34,5 +34,10 @@ public class StarsDatabase(string DbPath) : DbContext
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public DbSet<Race> Race { get; set; }
|
public DbSet<Race> Race { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The record with all game metadata, will only contain a single line at all times.
|
||||||
|
/// </summary>
|
||||||
|
public DbSet<Game> Game { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
@ -21,6 +21,7 @@ sealed class Program
|
|||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
ModeDetector.OverrideModeDetector(Splat.ModeDetection.Mode.Run);
|
ModeDetector.OverrideModeDetector(Splat.ModeDetection.Mode.Run);
|
||||||
|
|
||||||
Locator.CurrentMutable.Register(
|
Locator.CurrentMutable.Register(
|
||||||
() => new StarsDatabase("stars.sqlite"),
|
() => new StarsDatabase("stars.sqlite"),
|
||||||
typeof(StarsDatabase)
|
typeof(StarsDatabase)
|
||||||
|
20
Stars Assistant/Services/CSVDataLoader.cs
Normal file
20
Stars Assistant/Services/CSVDataLoader.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using CsvHelper.Configuration;
|
||||||
|
using CsvHelper;
|
||||||
|
using Splat;
|
||||||
|
|
||||||
|
namespace StarsAssistant.Services;
|
||||||
|
|
||||||
|
|
||||||
|
public class CSVDataLoader
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Reference to the game metadata, retrieved by DI
|
||||||
|
/// </summary>
|
||||||
|
protected Model.Game game;
|
||||||
|
|
||||||
|
public CSVDataLoader()
|
||||||
|
{
|
||||||
|
game = Locator.Current.GetService<Model.Game>()!;
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,8 @@ using System.Reactive.Disposables;
|
|||||||
using System.Reactive.Linq;
|
using System.Reactive.Linq;
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
using ReactiveUI.SourceGenerators;
|
using ReactiveUI.SourceGenerators;
|
||||||
|
using Splat;
|
||||||
|
using StarsAssistant.Model;
|
||||||
|
|
||||||
namespace StarsAssistant.ViewModels;
|
namespace StarsAssistant.ViewModels;
|
||||||
|
|
||||||
@ -11,13 +13,13 @@ public partial class MainWindowViewModel : ViewModelBase, IActivatableViewModel
|
|||||||
public ViewModelActivator Activator { get; } = new ViewModelActivator();
|
public ViewModelActivator Activator { get; } = new ViewModelActivator();
|
||||||
|
|
||||||
[ObservableAsProperty]
|
[ObservableAsProperty]
|
||||||
private string _welcomeMessage;
|
private string _dbPath = "";
|
||||||
|
|
||||||
public MainWindowViewModel()
|
public MainWindowViewModel()
|
||||||
{
|
{
|
||||||
_welcomeMessage = "Lorem Ipsum";
|
using var db = Locator.Current.GetService<StarsDatabase>()!;
|
||||||
_welcomeMessageHelper = Observable.Return("Dolor sit amet")
|
_dbPathHelper = Observable.Return(Path.GetFullPath(db.DbPath))
|
||||||
.ToProperty(this, x => x.WelcomeMessage);
|
.ToProperty(this, x => x.DbPath);
|
||||||
|
|
||||||
this.WhenActivated((CompositeDisposable disposables) =>
|
this.WhenActivated((CompositeDisposable disposables) =>
|
||||||
{
|
{
|
||||||
|
@ -7,7 +7,8 @@ namespace StarsAssistant.ViewModels;
|
|||||||
|
|
||||||
public partial class PlanetViewModel(Planet planet) : ViewModelBase
|
public partial class PlanetViewModel(Planet planet) : ViewModelBase
|
||||||
{
|
{
|
||||||
public static ObservableCollection<PlanetViewModel> LoadAll() {
|
public static ObservableCollection<PlanetViewModel> LoadAll()
|
||||||
|
{
|
||||||
using var db = Locator.Current.GetService<StarsDatabase>()!;
|
using var db = Locator.Current.GetService<StarsDatabase>()!;
|
||||||
var result = new ObservableCollection<PlanetViewModel>();
|
var result = new ObservableCollection<PlanetViewModel>();
|
||||||
foreach (Planet planet in db.Planet.Where(p => p.OwnerId == "Atlantis").ToList())
|
foreach (Planet planet in db.Planet.Where(p => p.OwnerId == "Atlantis").ToList())
|
||||||
|
@ -18,31 +18,24 @@
|
|||||||
</Design.DataContext>
|
</Design.DataContext>
|
||||||
|
|
||||||
<TabControl>
|
<TabControl>
|
||||||
<TabItem Header="Home">
|
<TabItem Header="Stars Assistant">
|
||||||
<TextBlock x:Name="WelcomeText">Hi</TextBlock>
|
<Grid ColumnDefinitions="Auto, *" RowDefinitions="Auto, Auto">
|
||||||
|
<Label Grid.Row="0" Grid.Column="0" Margin="0,5,5,5" Padding="3">Database Path:</Label>
|
||||||
|
<TextBlock x:Name="DbPath" Grid.Row="0" Grid.Column="1" Margin="0 5" Padding="3"/>
|
||||||
|
</Grid>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem Header="DataGrid">
|
<TabItem Header="DataGrid">
|
||||||
<DataGrid x:Name="PlanetsGrid"
|
<DataGrid x:Name="PlanetsGrid"
|
||||||
AutoGenerateColumns="True" IsReadOnly="True"
|
ItemsSource="{Binding Planets}"
|
||||||
|
IsReadOnly="True"
|
||||||
GridLinesVisibility="All"
|
GridLinesVisibility="All"
|
||||||
FrozenColumnCount="1"
|
FrozenColumnCount="1"
|
||||||
BorderThickness="1" BorderBrush="Gray">
|
BorderThickness="1" BorderBrush="Gray">
|
||||||
|
<DataGrid.Columns>
|
||||||
|
<DataGridTextColumn Header="Planet" Binding="{Binding Name}" />
|
||||||
|
<DataGridTextColumn Header="Value" Binding="{Binding Value}" />
|
||||||
|
</DataGrid.Columns>
|
||||||
</DataGrid>
|
</DataGrid>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem Header="ScrollViewer">
|
|
||||||
<ScrollViewer>
|
|
||||||
<ItemsControl ItemsSource="{Binding Planets}">
|
|
||||||
<ItemsControl.ItemTemplate>
|
|
||||||
<DataTemplate DataType="vm:PlanetViewModel">
|
|
||||||
<Grid ColumnDefinitions="200, 100, 50">
|
|
||||||
<TextBlock Grid.Column="0" Text="{Binding Name}"/>
|
|
||||||
<TextBlock Grid.Column="1" Text="{Binding Owner}"/>
|
|
||||||
<TextBlock Grid.Column="2" Text="{Binding Value}"/>
|
|
||||||
</Grid>
|
|
||||||
</DataTemplate>
|
|
||||||
</ItemsControl.ItemTemplate>
|
|
||||||
</ItemsControl>
|
|
||||||
</ScrollViewer>
|
|
||||||
</TabItem>
|
|
||||||
</TabControl>
|
</TabControl>
|
||||||
</Window>
|
</Window>
|
||||||
|
@ -13,19 +13,11 @@ public partial class MainWindow : ReactiveWindow<MainWindowViewModel>
|
|||||||
{
|
{
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
this.WhenActivated(
|
this.WhenActivated(disposables =>
|
||||||
|
{
|
||||||
disposables => {
|
this.OneWayBind(ViewModel, vm => vm.DbPath, v => v.DbPath.Text)
|
||||||
this.OneWayBind(ViewModel,
|
.DisposeWith(disposables);
|
||||||
viewModel => viewModel.Planets,
|
});
|
||||||
view => view.PlanetsGrid.ItemsSource)
|
|
||||||
.DisposeWith(disposables);
|
|
||||||
this.OneWayBind(ViewModel,
|
|
||||||
vm => vm.WelcomeMessage,
|
|
||||||
v => v.WelcomeText.Text)
|
|
||||||
.DisposeWith(disposables);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user