Skip to content

Fix leaderboard API loading #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ async public Task<LeaderboardResponse> GetLeaderboard(int page, int pageSize, st
using (WebClient webClient = new WebClient())
{
string json = await webClient.DownloadStringTaskAsync($"{this._functionUrl}?page={page}&pageSize={pageSize}&mode={mode}&region={region}");
return JsonSerializer.Deserialize<LeaderboardResponse>(json);
var leaderboardResponse = JsonSerializer.Deserialize<LeaderboardResponse>(json, new JsonSerializerOptions { IncludeFields = true });
return leaderboardResponse;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;
using TailSpin.SpaceGame.Web.Models;

namespace TailSpin.SpaceGame.Web
{
public class LeaderboardResponse
{
// The game mode selected in the view.
[JsonPropertyName("selectedMode")]
public string SelectedMode { get; set; }

// The game region (map) selected in the view.
[JsonPropertyName("selectedRegion")]
public string SelectedRegion { get; set; }
// The current page to be shown in the view.
[JsonPropertyName("page")]
public int Page { get; set; }
// The number of items to show per page in the view.
[JsonPropertyName("pageSize")]
public int PageSize { get; set; }

// The scores to display in the view.
[JsonPropertyName("scores")]
public IEnumerable<ScoreProfile> Scores { get; set; }
// The total number of results for the selected game mode and region in the view.
[JsonPropertyName("totalResults")]
public int TotalResults { get; set; }
}
}
3 changes: 3 additions & 0 deletions Tailspin.SpaceGame.Web/Models/LeaderboardViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace TailSpin.SpaceGame.Web.Models
{
Expand Down Expand Up @@ -44,8 +45,10 @@ public LeaderboardViewModel()
public struct ScoreProfile
{
// The player's score.
[JsonPropertyName("score")]
public Score Score;
// The player's profile.
[JsonPropertyName("profile")]
public Profile Profile;
}
}