Skip to content

Commit c4e37a1

Browse files
authored
Merge pull request #32109 from smoogipoo/results-beatmap-lookup
Fix multiplayer results screen displaying same beatmap for all users
2 parents 89b6d7c + 993473c commit c4e37a1

10 files changed

+284
-161
lines changed

osu.Game.Tests/Visual/Playlists/TestScenePlaylistsResultsScreen.cs

+35-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
using System.Net;
88
using Newtonsoft.Json.Linq;
99
using NUnit.Framework;
10+
using osu.Framework.Allocation;
1011
using osu.Framework.Graphics;
1112
using osu.Framework.Graphics.Containers;
1213
using osu.Framework.Testing;
14+
using osu.Framework.Utils;
15+
using osu.Game.Database;
1316
using osu.Game.Graphics.Containers;
1417
using osu.Game.Graphics.UserInterface;
1518
using osu.Game.Online.API;
@@ -32,6 +35,9 @@ public partial class TestScenePlaylistsResultsScreen : ScreenTestScene
3235
private const int scores_per_result = 10;
3336
private const int real_user_position = 200;
3437

38+
[Cached]
39+
private readonly BeatmapLookupCache beatmapLookupCache = new BeatmapLookupCache();
40+
3541
private ResultsScreen resultsScreen = null!;
3642

3743
private int lowestScoreId; // Score ID of the lowest score in the list.
@@ -41,6 +47,11 @@ public partial class TestScenePlaylistsResultsScreen : ScreenTestScene
4147
private int totalCount;
4248
private ScoreInfo userScore = null!;
4349

50+
public TestScenePlaylistsResultsScreen()
51+
{
52+
Add(beatmapLookupCache);
53+
}
54+
4455
[SetUpSteps]
4556
public override void SetUpSteps()
4657
{
@@ -279,6 +290,25 @@ private void bindHandler(bool delayed = false, ScoreInfo? userScore = null, bool
279290
case IndexPlaylistScoresRequest:
280291
break;
281292

293+
case GetBeatmapsRequest getBeatmaps:
294+
getBeatmaps.TriggerSuccess(new GetBeatmapsResponse
295+
{
296+
Beatmaps = getBeatmaps.BeatmapIds.Select(id => new APIBeatmap
297+
{
298+
OnlineID = id,
299+
StarRating = id,
300+
DifficultyName = $"Beatmap {id}",
301+
BeatmapSet = new APIBeatmapSet
302+
{
303+
Title = $"Title {id}",
304+
Artist = $"Artist {id}",
305+
AuthorString = $"Author {id}"
306+
}
307+
}).ToList()
308+
});
309+
310+
return true;
311+
282312
default:
283313
return false;
284314
}
@@ -346,6 +376,7 @@ private MultiplayerScore createUserResponse(ScoreInfo userScore)
346376
Position = real_user_position,
347377
MaxCombo = userScore.MaxCombo,
348378
User = userScore.User,
379+
BeatmapId = RNG.Next(0, 7),
349380
ScoresAround = new MultiplayerScoresAround
350381
{
351382
Higher = new MultiplayerScores(),
@@ -364,6 +395,7 @@ private MultiplayerScore createUserResponse(ScoreInfo userScore)
364395
Passed = true,
365396
Rank = userScore.Rank,
366397
MaxCombo = userScore.MaxCombo,
398+
BeatmapId = RNG.Next(0, 7),
367399
User = new APIUser
368400
{
369401
Id = 2 + i,
@@ -379,6 +411,7 @@ private MultiplayerScore createUserResponse(ScoreInfo userScore)
379411
Passed = true,
380412
Rank = userScore.Rank,
381413
MaxCombo = userScore.MaxCombo,
414+
BeatmapId = RNG.Next(0, 7),
382415
User = new APIUser
383416
{
384417
Id = 2 + i,
@@ -396,7 +429,7 @@ private MultiplayerScore createUserResponse(ScoreInfo userScore)
396429
return multiplayerUserScore;
397430
}
398431

399-
private IndexedMultiplayerScores createIndexResponse(IndexPlaylistScoresRequest req, bool noScores = false)
432+
private IndexedMultiplayerScores createIndexResponse(IndexPlaylistScoresRequest req, bool noScores)
400433
{
401434
var result = new IndexedMultiplayerScores();
402435

@@ -413,6 +446,7 @@ private IndexedMultiplayerScores createIndexResponse(IndexPlaylistScoresRequest
413446
Passed = true,
414447
Rank = ScoreRank.X,
415448
MaxCombo = 1000,
449+
BeatmapId = RNG.Next(0, 7),
416450
User = new APIUser
417451
{
418452
Id = 2 + i,

osu.Game.Tests/Visual/Ranking/TestSceneResultsScreen.cs

+12-18
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#nullable disable
55

66
using System;
7-
using System.Collections.Generic;
87
using System.Linq;
98
using System.Threading.Tasks;
109
using NUnit.Framework;
@@ -17,7 +16,6 @@
1716
using osu.Game.Beatmaps;
1817
using osu.Game.Database;
1918
using osu.Game.Graphics.UserInterface;
20-
using osu.Game.Online.API;
2119
using osu.Game.Rulesets;
2220
using osu.Game.Rulesets.Difficulty;
2321
using osu.Game.Rulesets.Osu;
@@ -416,21 +414,19 @@ protected override void LoadComplete()
416414
RetryOverlay = InternalChildren.OfType<HotkeyRetryOverlay>().SingleOrDefault();
417415
}
418416

419-
protected override APIRequest FetchScores(Action<IEnumerable<ScoreInfo>> scoresCallback)
417+
protected override Task<ScoreInfo[]> FetchScores()
420418
{
421-
var scores = new List<ScoreInfo>();
419+
var scores = new ScoreInfo[20];
422420

423-
for (int i = 0; i < 20; i++)
421+
for (int i = 0; i < scores.Length; i++)
424422
{
425423
var score = TestResources.CreateTestScoreInfo();
426424
score.TotalScore += 10 - i;
427425
score.HasOnlineReplay = true;
428-
scores.Add(score);
426+
scores[i] = score;
429427
}
430428

431-
scoresCallback.Invoke(scores);
432-
433-
return null;
429+
return Task.FromResult(scores);
434430
}
435431
}
436432

@@ -446,27 +442,25 @@ public DelayedFetchResultsScreen(ScoreInfo score, Task fetchWaitTask = null)
446442
this.fetchWaitTask = fetchWaitTask ?? Task.CompletedTask;
447443
}
448444

449-
protected override APIRequest FetchScores(Action<IEnumerable<ScoreInfo>> scoresCallback)
445+
protected override Task<ScoreInfo[]> FetchScores()
450446
{
451-
Task.Run(async () =>
447+
return Task.Run(async () =>
452448
{
453449
await fetchWaitTask;
454450

455-
var scores = new List<ScoreInfo>();
451+
var scores = new ScoreInfo[20];
456452

457-
for (int i = 0; i < 20; i++)
453+
for (int i = 0; i < scores.Length; i++)
458454
{
459455
var score = TestResources.CreateTestScoreInfo();
460456
score.TotalScore += 10 - i;
461-
scores.Add(score);
457+
scores[i] = score;
462458
}
463459

464-
scoresCallback?.Invoke(scores);
465-
466460
Schedule(() => FetchCompleted = true);
467-
});
468461

469-
return null;
462+
return scores;
463+
});
470464
}
471465
}
472466

osu.Game/Online/Rooms/MultiplayerScore.cs

+3
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ public class MultiplayerScore
8080
[JsonProperty("ruleset_id")]
8181
public int RulesetId { get; set; }
8282

83+
[JsonProperty("beatmap_id")]
84+
public int BeatmapId { get; set; }
85+
8386
public ScoreInfo CreateScoreInfo(ScoreManager scoreManager, RulesetStore rulesets, [NotNull] BeatmapInfo beatmap)
8487
{
8588
var ruleset = rulesets.GetRuleset(RulesetId);

osu.Game/Screens/OnlinePlay/Multiplayer/Spectate/MultiSpectatorResultsScreen.cs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
22
// See the LICENCE file in the repository root for full licence text.
33

4-
using System;
5-
using System.Collections.Generic;
6-
using osu.Game.Online.API;
4+
using System.Threading.Tasks;
75
using osu.Game.Scoring;
86
using osu.Game.Screens.Play;
97

@@ -23,8 +21,8 @@ protected override void LoadComplete()
2321
Scheduler.AddDelayed(() => StatisticsPanel.ToggleVisibility(), 1000);
2422
}
2523

26-
protected override APIRequest? FetchScores(Action<IEnumerable<ScoreInfo>> scoresCallback) => null;
24+
protected override Task<ScoreInfo[]> FetchScores() => Task.FromResult<ScoreInfo[]>([]);
2725

28-
protected override APIRequest? FetchNextPage(int direction, Action<IEnumerable<ScoreInfo>> scoresCallback) => null;
26+
protected override Task<ScoreInfo[]> FetchNextPage(int direction) => Task.FromResult<ScoreInfo[]>([]);
2927
}
3028
}

0 commit comments

Comments
 (0)