Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions SMB3Explorer/AppConfig/Models/ConfigOptions.cs
Original file line number Diff line number Diff line change
@@ -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<League> Leagues { get; set; } = new();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
25 changes: 18 additions & 7 deletions SMB3Explorer/ViewModels/LandingViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
Expand All @@ -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)
Expand All @@ -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);
Expand All @@ -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;
}
Expand All @@ -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));
}
Expand Down Expand Up @@ -116,7 +127,7 @@ private bool CanSelectSaveFile()
{
return !_dataService.IsConnected;
}

private bool CanConnectToExistingLeague()
{
return SelectedExistingLeague is not null;
Expand All @@ -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);
}
Expand Down
46 changes: 23 additions & 23 deletions SMB3Explorer/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<LandingViewModel>();
_ = Task.Run(async () => await CheckForUpdates());
return Task.CompletedTask;
}
public INavigationService NavigationService { get; }

private static Version CurrentVersion
{
Expand Down Expand Up @@ -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<LandingViewModel>();
_ = Task.Run(async () => await CheckForUpdates());
return Task.CompletedTask;
}

[RelayCommand]
private Task OpenExportsFolder()
{
Expand Down Expand Up @@ -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");
Expand All @@ -153,7 +153,7 @@ private Task OpenDiscussions()
{
Log.Information("Opening discussions page");


SafeProcess.Start(DiscussionsUrl, _systemIoWrapper);

Log.Information("Opened discussions page");
Expand All @@ -165,7 +165,7 @@ private Task OpenIssues()
{
Log.Information("Opening issues page");


SafeProcess.Start(IssuesUrl, _systemIoWrapper);

Log.Information("Opened issues page");
Expand All @@ -188,7 +188,7 @@ private Task OpenGithubRepo()
{
Log.Information("Opening github repo");


SafeProcess.Start(RepoUrl, _systemIoWrapper);

Log.Information("Opened github repo");
Expand Down
6 changes: 4 additions & 2 deletions SMB3Explorer/Views/LandingView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
<StackPanel Orientation="Horizontal">
<RadioButton
GroupName="Options"
Content="SMB3">
Content="SMB3"
Margin="5">
<RadioButton.IsChecked>
<Binding
Path="SelectedGame"
Expand All @@ -38,7 +39,8 @@
</RadioButton>
<RadioButton
GroupName="Options"
Content="SMB4">
Content="SMB4"
Margin="5">
<RadioButton.IsChecked>
<Binding
Path="SelectedGame"
Expand Down