Skip to content

Commit

Permalink
Prevent crash when a game does not have categories yet
Browse files Browse the repository at this point in the history
  • Loading branch information
Heufneutje committed Sep 28, 2024
1 parent 238b99e commit a3aa2db
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions SpeedrunTracker/ViewModels/GameDetailViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,19 +214,27 @@ public async Task LoadLeaderboardAsync()
LeaderboardEntries.Clear();

List<string> variableValues = new();
foreach (VariableViewModel vm in Variables)
variableValues.Add($"var-{vm.VariableId}={vm.SelectedValue.Id}");
string variables = string.Join('&', variableValues);
string variables = string.Empty;

if (!string.IsNullOrEmpty(variables))
variables = $"&{variables}";
if (Variables != null)
{
foreach (VariableViewModel vm in Variables)
variableValues.Add($"var-{vm.VariableId}={vm.SelectedValue.Id}");
variables = string.Join('&', variableValues);
}

_leaderboard = string.IsNullOrEmpty(SelectedLevel.Id) ?
await ExecuteNetworkTask(_leaderboardService.GetFullGameLeaderboardAsync(Game.Id, SelectedCategory.Id, variables, _settingsService.UserSettings.MaxLeaderboardResults)) :
await ExecuteNetworkTask(_leaderboardService.GetLevelLeaderboardAsync(Game.Id, SelectedLevel.Id, SelectedCategory.Id, variables, _settingsService.UserSettings.MaxLeaderboardResults));
if (SelectedCategory != null)
{
if (!string.IsNullOrEmpty(variables))
variables = $"&{variables}";

if (_leaderboard != null)
DisplayLeaderboardEntries();
_leaderboard = string.IsNullOrEmpty(SelectedLevel.Id) ?
await ExecuteNetworkTask(_leaderboardService.GetFullGameLeaderboardAsync(Game.Id, SelectedCategory.Id, variables, _settingsService.UserSettings.MaxLeaderboardResults)) :
await ExecuteNetworkTask(_leaderboardService.GetLevelLeaderboardAsync(Game.Id, SelectedLevel.Id, SelectedCategory.Id, variables, _settingsService.UserSettings.MaxLeaderboardResults));

if (_leaderboard != null)
DisplayLeaderboardEntries();
}

IsLoadingLeaderboard = false;
}
Expand Down

0 comments on commit a3aa2db

Please sign in to comment.