diff --git a/SMB3Explorer/AppConfig/Models/ConfigOptions.cs b/SMB3Explorer/AppConfig/Models/ConfigOptions.cs index 3c2ecf4..7977ea5 100644 --- a/SMB3Explorer/AppConfig/Models/ConfigOptions.cs +++ b/SMB3Explorer/AppConfig/Models/ConfigOptions.cs @@ -1,10 +1,14 @@ using System.Collections.Generic; using Newtonsoft.Json; +using SMB3Explorer.Enums; namespace SMB3Explorer.AppConfig.Models; public class ConfigOptions { + [JsonProperty("gamePreference")] + public SelectedGame GamePreference { get; set; } = SelectedGame.Smb4; + [JsonProperty("smb4Leagues")] public List Leagues { get; set; } = new(); } \ No newline at end of file diff --git a/SMB3Explorer/Models/Exports/BattingMostRecentSeasonStatistic.cs b/SMB3Explorer/Models/Exports/BattingMostRecentSeasonStatistic.cs index d21852d..d843e44 100644 --- a/SMB3Explorer/Models/Exports/BattingMostRecentSeasonStatistic.cs +++ b/SMB3Explorer/Models/Exports/BattingMostRecentSeasonStatistic.cs @@ -5,9 +5,9 @@ namespace SMB3Explorer.Models.Exports; public class BattingMostRecentSeasonStatistic : BattingStatistic { - [Ignore] - public new Guid PlayerId { get; set; } - [Name("OPS+"), Index(44)] public double? OnBasePercentagePlus { get; set; } + + [Name("PlayerId"), Index(45)] + public new Guid PlayerId { get; set; } } \ No newline at end of file diff --git a/SMB3Explorer/Models/Exports/PitchingMostRecentSeasonStatistic.cs b/SMB3Explorer/Models/Exports/PitchingMostRecentSeasonStatistic.cs index b7e3ec8..54f44ca 100644 --- a/SMB3Explorer/Models/Exports/PitchingMostRecentSeasonStatistic.cs +++ b/SMB3Explorer/Models/Exports/PitchingMostRecentSeasonStatistic.cs @@ -7,12 +7,12 @@ namespace SMB3Explorer.Models.Exports; public class PitchingMostRecentSeasonStatistic : PitchingStatistic { - [Ignore] - public new Guid PlayerId { get; set; } - [Name("ERA-"), Index(40)] public double EarnedRunsAllowedMinus { get; set; } [Name("FIP-"), Index(41)] public double FieldingIndependentPitchingMinus { get; set; } + + [Name("PlayerId"), Index(42)] + public new Guid PlayerId { get; set; } } \ No newline at end of file diff --git a/SMB3Explorer/ViewModels/LandingViewModel.cs b/SMB3Explorer/ViewModels/LandingViewModel.cs index d39f697..f45212e 100644 --- a/SMB3Explorer/ViewModels/LandingViewModel.cs +++ b/SMB3Explorer/ViewModels/LandingViewModel.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using System.Threading.Tasks; using System.Windows; @@ -24,13 +23,13 @@ namespace SMB3Explorer.ViewModels; public partial class LandingViewModel : ViewModelBase { - private readonly IApplicationContext _applicationContext; private readonly IApplicationConfig _applicationConfig; + private readonly IApplicationContext _applicationContext; private readonly IDataService _dataService; private readonly INavigationService _navigationService; private readonly ISystemIoWrapper _systemIoWrapper; - private SelectedGame _selectedGame; private Smb4LeagueSelection? _selectedExistingLeague; + private SelectedGame _selectedGame; public LandingViewModel(IDataService dataService, INavigationService navigationService, ISystemIoWrapper systemIoWrapper, IApplicationContext applicationContext, IApplicationConfig applicationConfig) @@ -43,7 +42,7 @@ public LandingViewModel(IDataService dataService, INavigationService navigationS Log.Information("Initializing LandingViewModel"); - var configResult = applicationConfig.GetConfigOptions(); + var configResult = _applicationConfig.GetConfigOptions(); if (configResult.TryPickT1(out var error, out var configOptions)) { Log.Error("Could not retrieve config options for previously selected leagues: {Error}", error); @@ -54,6 +53,7 @@ public LandingViewModel(IDataService dataService, INavigationService navigationS Smb4LeagueSelections = configOptions.Leagues .Select(league => new Smb4LeagueSelection(league.Name, league.Id)) .ToList(); + SelectedGame = configOptions.GamePreference; _dataService.ConnectionChanged += DataServiceOnConnectionChanged; } @@ -70,6 +70,17 @@ public SelectedGame SelectedGame SetField(ref _selectedGame, value); _applicationContext.SelectedGame = value; + + var configResult = _applicationConfig.GetConfigOptions(); + if (configResult.TryPickT0(out var configOptions, out _)) + { + if (configOptions.GamePreference != value) + { + configOptions.GamePreference = value; + _applicationConfig.SaveConfigOptions(configOptions); + } + } + OnPropertyChanged(nameof(Smb3ButtonVisibility)); OnPropertyChanged(nameof(Smb4ButtonVisibility)); } @@ -116,7 +127,7 @@ private bool CanSelectSaveFile() { return !_dataService.IsConnected; } - + private bool CanConnectToExistingLeague() { return SelectedExistingLeague is not null; @@ -138,12 +149,12 @@ private async Task ConnectToPreviouslyConnectedSaveGame() var filePathResult = SaveFile.GetSmb4ExistingSaveFilePath(_systemIoWrapper, SelectedExistingLeague.LeagueId); if (filePathResult.TryPickT1(out var error, out var filePath) || string.IsNullOrEmpty(filePath)) { - DefaultExceptionHandler.HandleException(_systemIoWrapper, $"Could not get save file path", + DefaultExceptionHandler.HandleException(_systemIoWrapper, "Could not get save file path", new Exception(error.Value)); Mouse.OverrideCursor = Cursors.Arrow; return; } - + var connectionResult = await EstablishDbConnection(filePath); HandleDatabaseConnection(connectionResult); } diff --git a/SMB3Explorer/ViewModels/MainWindowViewModel.cs b/SMB3Explorer/ViewModels/MainWindowViewModel.cs index 05cd38e..7606f4a 100644 --- a/SMB3Explorer/ViewModels/MainWindowViewModel.cs +++ b/SMB3Explorer/ViewModels/MainWindowViewModel.cs @@ -19,16 +19,14 @@ namespace SMB3Explorer.ViewModels; public partial class MainWindowViewModel : ViewModelBase { - public INavigationService NavigationService { get; } - - private readonly ISystemIoWrapper _systemIoWrapper; private readonly IDataService _dataService; private readonly IHttpService _httpService; - private bool _isUpdateAvailable; - private string _updateVersion = string.Empty; + + private readonly ISystemIoWrapper _systemIoWrapper; private AppUpdateResult? _appUpdateResult; - private Visibility _updateAvailableVisibility = Visibility.Collapsed; private Visibility _deselectSaveGameVisibility = Visibility.Collapsed; + private bool _isUpdateAvailable; + private Visibility _updateAvailableVisibility = Visibility.Collapsed; public MainWindowViewModel(INavigationService navigationService, ISystemIoWrapper systemIoWrapper, IDataService dataService, IHttpService httpService) @@ -43,19 +41,7 @@ public MainWindowViewModel(INavigationService navigationService, ISystemIoWrappe _dataService.ConnectionChanged += DataServiceOnConnectionChanged; } - private void DataServiceOnConnectionChanged(object? sender, EventArgs e) - { - DeselectSaveGameVisibility = _dataService.IsConnected - ? Visibility.Visible - : Visibility.Collapsed; - } - - public Task Initialize() - { - NavigationService.NavigateTo(); - _ = Task.Run(async () => await CheckForUpdates()); - return Task.CompletedTask; - } + public INavigationService NavigationService { get; } private static Version CurrentVersion { @@ -107,6 +93,20 @@ public Visibility DeselectSaveGameVisibility ? $"Update Available: {AppUpdateResult?.Version.ToString()}" : "No Updates Available"; + private void DataServiceOnConnectionChanged(object? sender, EventArgs e) + { + DeselectSaveGameVisibility = _dataService.IsConnected + ? Visibility.Visible + : Visibility.Collapsed; + } + + public Task Initialize() + { + NavigationService.NavigateTo(); + _ = Task.Run(async () => await CheckForUpdates()); + return Task.CompletedTask; + } + [RelayCommand] private Task OpenExportsFolder() { @@ -141,7 +141,7 @@ private Task OpenWiki() private Task SubmitFeatureRequest() { Log.Information("Opening feature request page"); - + SafeProcess.Start(FeatureRequestUrl, _systemIoWrapper); Log.Information("Opened feature request page"); @@ -153,7 +153,7 @@ private Task OpenDiscussions() { Log.Information("Opening discussions page"); - + SafeProcess.Start(DiscussionsUrl, _systemIoWrapper); Log.Information("Opened discussions page"); @@ -165,7 +165,7 @@ private Task OpenIssues() { Log.Information("Opening issues page"); - + SafeProcess.Start(IssuesUrl, _systemIoWrapper); Log.Information("Opened issues page"); @@ -188,7 +188,7 @@ private Task OpenGithubRepo() { Log.Information("Opening github repo"); - + SafeProcess.Start(RepoUrl, _systemIoWrapper); Log.Information("Opened github repo"); diff --git a/SMB3Explorer/Views/LandingView.xaml b/SMB3Explorer/Views/LandingView.xaml index 3ea3a4b..dde42c4 100644 --- a/SMB3Explorer/Views/LandingView.xaml +++ b/SMB3Explorer/Views/LandingView.xaml @@ -28,7 +28,8 @@ + Content="SMB3" + Margin="5"> + Content="SMB4" + Margin="5">