mirror of
https://github.com/osukey/osukey.git
synced 2025-05-09 23:57:18 +09:00
Use response params in next page request
This commit is contained in:
parent
9f6446d836
commit
db91d1de50
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using JetBrains.Annotations;
|
||||||
using osu.Framework.IO.Network;
|
using osu.Framework.IO.Network;
|
||||||
using osu.Game.Extensions;
|
using osu.Game.Extensions;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
@ -16,31 +17,31 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
private readonly int roomId;
|
private readonly int roomId;
|
||||||
private readonly int playlistItemId;
|
private readonly int playlistItemId;
|
||||||
private readonly Cursor cursor;
|
private readonly Cursor cursor;
|
||||||
private readonly MultiplayerScoresSort? sort;
|
private readonly IndexScoresParams indexParams;
|
||||||
|
|
||||||
public IndexPlaylistScoresRequest(int roomId, int playlistItemId, Cursor cursor = null, MultiplayerScoresSort? sort = null)
|
public IndexPlaylistScoresRequest(int roomId, int playlistItemId)
|
||||||
{
|
{
|
||||||
this.roomId = roomId;
|
this.roomId = roomId;
|
||||||
this.playlistItemId = playlistItemId;
|
this.playlistItemId = playlistItemId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IndexPlaylistScoresRequest(int roomId, int playlistItemId, [NotNull] Cursor cursor, [NotNull] IndexScoresParams indexParams)
|
||||||
|
: this(roomId, playlistItemId)
|
||||||
|
{
|
||||||
this.cursor = cursor;
|
this.cursor = cursor;
|
||||||
this.sort = sort;
|
this.indexParams = indexParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override WebRequest CreateWebRequest()
|
protected override WebRequest CreateWebRequest()
|
||||||
{
|
{
|
||||||
var req = base.CreateWebRequest();
|
var req = base.CreateWebRequest();
|
||||||
|
|
||||||
req.AddCursor(cursor);
|
if (cursor != null)
|
||||||
|
|
||||||
switch (sort)
|
|
||||||
{
|
{
|
||||||
case MultiplayerScoresSort.Ascending:
|
req.AddCursor(cursor);
|
||||||
req.AddParameter("sort", "score_asc");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MultiplayerScoresSort.Descending:
|
foreach (var (key, value) in indexParams.Properties)
|
||||||
req.AddParameter("sort", "score_desc");
|
req.AddParameter(key, value.ToString());
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return req;
|
return req;
|
||||||
|
20
osu.Game/Online/Multiplayer/IndexScoresParams.cs
Normal file
20
osu.Game/Online/Multiplayer/IndexScoresParams.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
namespace osu.Game.Online.Multiplayer
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A collection of parameters which should be passed to the index endpoint to fetch the next page.
|
||||||
|
/// </summary>
|
||||||
|
public class IndexScoresParams
|
||||||
|
{
|
||||||
|
[UsedImplicitly]
|
||||||
|
[JsonExtensionData]
|
||||||
|
public IDictionary<string, JToken> Properties;
|
||||||
|
}
|
||||||
|
}
|
@ -29,5 +29,11 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("user_score")]
|
[JsonProperty("user_score")]
|
||||||
public MultiplayerScore UserScore { get; set; }
|
public MultiplayerScore UserScore { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The parameters to be used to fetch the next page.
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("params")]
|
||||||
|
public IndexScoresParams Params { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ using osu.Framework.Graphics;
|
|||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.API.Requests;
|
|
||||||
using osu.Game.Online.Multiplayer;
|
using osu.Game.Online.Multiplayer;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
using osu.Game.Screens.Ranking;
|
using osu.Game.Screens.Ranking;
|
||||||
@ -23,8 +22,8 @@ namespace osu.Game.Screens.Multi.Ranking
|
|||||||
private readonly PlaylistItem playlistItem;
|
private readonly PlaylistItem playlistItem;
|
||||||
|
|
||||||
private LoadingSpinner loadingLayer;
|
private LoadingSpinner loadingLayer;
|
||||||
private Cursor higherScoresCursor;
|
private MultiplayerScores higherScores;
|
||||||
private Cursor lowerScoresCursor;
|
private MultiplayerScores lowerScores;
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private IAPIProvider api { get; set; }
|
private IAPIProvider api { get; set; }
|
||||||
@ -52,8 +51,8 @@ namespace osu.Game.Screens.Multi.Ranking
|
|||||||
protected override APIRequest FetchScores(Action<IEnumerable<ScoreInfo>> scoresCallback)
|
protected override APIRequest FetchScores(Action<IEnumerable<ScoreInfo>> scoresCallback)
|
||||||
{
|
{
|
||||||
// This performs two requests:
|
// This performs two requests:
|
||||||
// 1. A request to show the user's score.
|
// 1. A request to show the user's score (and scores around).
|
||||||
// 2. If (1) fails, a request to index the room.
|
// 2. If that fails, a request to index the room starting from the highest score.
|
||||||
|
|
||||||
var userScoreReq = new ShowPlaylistUserScoreRequest(roomId, playlistItem.ID, api.LocalUser.Value.Id);
|
var userScoreReq = new ShowPlaylistUserScoreRequest(roomId, playlistItem.ID, api.LocalUser.Value.Id);
|
||||||
|
|
||||||
@ -64,13 +63,13 @@ namespace osu.Game.Screens.Multi.Ranking
|
|||||||
if (userScore.ScoresAround?.Higher != null)
|
if (userScore.ScoresAround?.Higher != null)
|
||||||
{
|
{
|
||||||
allScores.AddRange(userScore.ScoresAround.Higher.Scores);
|
allScores.AddRange(userScore.ScoresAround.Higher.Scores);
|
||||||
higherScoresCursor = userScore.ScoresAround.Higher.Cursor;
|
higherScores = userScore.ScoresAround.Higher;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userScore.ScoresAround?.Lower != null)
|
if (userScore.ScoresAround?.Lower != null)
|
||||||
{
|
{
|
||||||
allScores.AddRange(userScore.ScoresAround.Lower.Scores);
|
allScores.AddRange(userScore.ScoresAround.Lower.Scores);
|
||||||
lowerScoresCursor = userScore.ScoresAround.Lower.Cursor;
|
lowerScores = userScore.ScoresAround.Lower;
|
||||||
}
|
}
|
||||||
|
|
||||||
performSuccessCallback(scoresCallback, allScores);
|
performSuccessCallback(scoresCallback, allScores);
|
||||||
@ -84,7 +83,7 @@ namespace osu.Game.Screens.Multi.Ranking
|
|||||||
indexReq.Success += r =>
|
indexReq.Success += r =>
|
||||||
{
|
{
|
||||||
performSuccessCallback(scoresCallback, r.Scores);
|
performSuccessCallback(scoresCallback, r.Scores);
|
||||||
lowerScoresCursor = r.Cursor;
|
lowerScores = r;
|
||||||
};
|
};
|
||||||
|
|
||||||
indexReq.Failure += __ => loadingLayer.Hide();
|
indexReq.Failure += __ => loadingLayer.Hide();
|
||||||
@ -99,39 +98,19 @@ namespace osu.Game.Screens.Multi.Ranking
|
|||||||
{
|
{
|
||||||
Debug.Assert(direction == 1 || direction == -1);
|
Debug.Assert(direction == 1 || direction == -1);
|
||||||
|
|
||||||
Cursor cursor;
|
MultiplayerScores pivot = direction == -1 ? higherScores : lowerScores;
|
||||||
MultiplayerScoresSort sort;
|
|
||||||
|
|
||||||
switch (direction)
|
if (pivot?.Cursor == null)
|
||||||
{
|
|
||||||
case -1:
|
|
||||||
cursor = higherScoresCursor;
|
|
||||||
sort = MultiplayerScoresSort.Ascending;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
cursor = lowerScoresCursor;
|
|
||||||
sort = MultiplayerScoresSort.Descending;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cursor == null)
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
var indexReq = new IndexPlaylistScoresRequest(roomId, playlistItem.ID, cursor, sort);
|
var indexReq = new IndexPlaylistScoresRequest(roomId, playlistItem.ID, pivot.Cursor, pivot.Params);
|
||||||
|
|
||||||
indexReq.Success += r =>
|
indexReq.Success += r =>
|
||||||
{
|
{
|
||||||
switch (direction)
|
if (direction == -1)
|
||||||
{
|
higherScores = r;
|
||||||
case -1:
|
else
|
||||||
higherScoresCursor = r.Cursor;
|
lowerScores = r;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
lowerScoresCursor = r.Cursor;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
performSuccessCallback(scoresCallback, r.Scores);
|
performSuccessCallback(scoresCallback, r.Scores);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user