Skip to content

Commit 7203f41

Browse files
committed
Merge branch 'master' into qp-add-helpers
2 parents 722cfb7 + 5da132c commit 7203f41

File tree

7 files changed

+93
-21
lines changed

7 files changed

+93
-21
lines changed

osu.Game.Tests/Visual/Matchmaking/TestSceneBeatmapSelectPanel.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
22
// See the LICENCE file in the repository root for full licence text.
33

4+
using System;
45
using NUnit.Framework;
56
using osu.Framework.Allocation;
67
using osu.Framework.Graphics;
78
using osu.Game.Graphics.Cursor;
89
using osu.Game.Online.API;
10+
using osu.Game.Online.API.Requests;
911
using osu.Game.Online.API.Requests.Responses;
1012
using osu.Game.Online.Rooms;
1113
using osu.Game.Overlays;
@@ -62,5 +64,41 @@ public void TestBeatmapPanel()
6264
panel.AllowSelection = value;
6365
});
6466
}
67+
68+
[Test]
69+
public void TestFailedBeatmapLookup()
70+
{
71+
AddStep("setup request handle", () =>
72+
{
73+
var api = (DummyAPIAccess)API;
74+
var handler = api.HandleRequest;
75+
api.HandleRequest = req =>
76+
{
77+
switch (req)
78+
{
79+
case GetBeatmapRequest:
80+
case GetBeatmapsRequest:
81+
req.TriggerFailure(new InvalidOperationException());
82+
return false;
83+
84+
default:
85+
return handler?.Invoke(req) ?? false;
86+
}
87+
};
88+
});
89+
90+
AddStep("add panel", () =>
91+
{
92+
Child = new OsuContextMenuContainer
93+
{
94+
RelativeSizeAxes = Axes.Both,
95+
Child = new BeatmapSelectPanel(new MultiplayerPlaylistItem())
96+
{
97+
Anchor = Anchor.Centre,
98+
Origin = Anchor.Centre,
99+
}
100+
};
101+
});
102+
}
65103
}
66104
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,5 +137,20 @@ public void TestInvalidUser()
137137
MultiplayerClient.ChangeMatchRoomState(state).WaitSafely();
138138
});
139139
}
140+
141+
[Test]
142+
public void TestNoUsers()
143+
{
144+
AddStep("show results with no users", () =>
145+
{
146+
var state = new MatchmakingRoomState
147+
{
148+
CurrentRound = 6,
149+
Stage = MatchmakingStage.Ended
150+
};
151+
152+
MultiplayerClient.ChangeMatchRoomState(state).WaitSafely();
153+
});
154+
}
140155
}
141156
}

osu.Game/Online/Multiplayer/MatchTypes/Matchmaking/MatchmakingUser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class MatchmakingUser
2323
/// The aggregate room placement (1-based).
2424
/// </summary>
2525
[Key(1)]
26-
public int Placement { get; set; }
26+
public int? Placement { get; set; }
2727

2828
/// <summary>
2929
/// The aggregate points.

osu.Game/Screens/OnlinePlay/Matchmaking/Match/BeatmapSelect/BeatmapSelectPanel.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,17 @@ private void load(BeatmapLookupCache lookupCache, OverlayColourProvider colourPr
111111
{
112112
Debug.Assert(card == null);
113113

114-
var beatmap = b.GetResultSafely()!;
114+
APIBeatmap beatmap = b.GetResultSafely() ?? new APIBeatmap
115+
{
116+
BeatmapSet = new APIBeatmapSet
117+
{
118+
Title = "unknown beatmap",
119+
TitleUnicode = "unknown beatmap",
120+
Artist = "unknown artist",
121+
ArtistUnicode = "unknown artist",
122+
}
123+
};
124+
115125
beatmap.StarRating = Item.StarRating;
116126

117127
mainContent.Add(card = new BeatmapCardMatchmaking(beatmap)

osu.Game/Screens/OnlinePlay/Matchmaking/Match/PlayerPanel.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,11 @@ private void onRoomStateChanged(MatchRoomState? state) => Scheduler.Add(() =>
414414
if (!matchmakingState.Users.UserDictionary.TryGetValue(User.Id, out MatchmakingUser? userScore))
415415
return;
416416

417-
rankText.Text = userScore.Placement.Ordinalize(CultureInfo.CurrentCulture);
418-
rankText.FadeColour(SubScreenResults.ColourForPlacement(userScore.Placement));
417+
if (userScore.Placement == null)
418+
return;
419+
420+
rankText.Text = userScore.Placement.Value.Ordinalize(CultureInfo.CurrentCulture);
421+
rankText.FadeColour(SubScreenResults.ColourForPlacement(userScore.Placement.Value));
419422
scoreText.Text = $"{userScore.Points} pts";
420423
});
421424

osu.Game/Screens/OnlinePlay/Matchmaking/Match/PlayerPanelOverlay.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ public void AcquirePanels(PlayerPanel[] panels)
239239
if (client.Room?.MatchState is not MatchmakingRoomState matchmakingState)
240240
continue;
241241

242-
if (matchmakingState.Users.UserDictionary.TryGetValue(panels[i].User.Id, out MatchmakingUser? user))
243-
SetLayoutPosition(Children[i], user.Placement);
242+
if (matchmakingState.Users.UserDictionary.TryGetValue(panels[i].User.Id, out MatchmakingUser? user) && user.Placement != null)
243+
SetLayoutPosition(Children[i], user.Placement.Value);
244244
else
245245
SetLayoutPosition(Children[i], float.MaxValue);
246246
}

osu.Game/Screens/OnlinePlay/Matchmaking/Match/Results/SubScreenResults.cs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,16 @@ private void populateUserStatistics(MatchmakingRoomState state)
203203
return;
204204
}
205205

206-
int overallPlacement = localUserState.Placement;
206+
int? overallPlacement = localUserState.Placement;
207207

208-
placementText.Text = overallPlacement.Ordinalize(CultureInfo.CurrentCulture);
209-
placementText.Colour = ColourForPlacement(overallPlacement);
208+
if (overallPlacement != null)
209+
{
210+
placementText.Text = overallPlacement.Value.Ordinalize(CultureInfo.CurrentCulture);
211+
placementText.Colour = ColourForPlacement(overallPlacement.Value);
210212

211-
int overallPoints = localUserState.Points;
212-
addStatistic(overallPlacement, $"Overall position ({overallPoints} points)");
213+
int overallPoints = localUserState.Points;
214+
addStatistic(overallPlacement.Value, $"Overall position ({overallPoints} points)");
215+
}
213216

214217
var accuracyOrderedUsers = state.Users.Select(u => (user: u, avgAcc: u.Rounds.Select(r => r.Accuracy).DefaultIfEmpty(0).Average()))
215218
.OrderByDescending(t => t.avgAcc)
@@ -257,27 +260,27 @@ private void populateRoomStatistics(MatchmakingRoomState state)
257260
roomAwards.Clear();
258261

259262
long maxScore = long.MinValue;
260-
int maxScoreUserId = 0;
263+
int maxScoreUserId = -1;
261264

262265
double maxAccuracy = double.MinValue;
263-
int maxAccuracyUserId = 0;
266+
int maxAccuracyUserId = -1;
264267

265268
int maxCombo = int.MinValue;
266-
int maxComboUserId = 0;
269+
int maxComboUserId = -1;
267270

268271
long maxBonusScore = 0;
269-
int maxBonusScoreUserId = 0;
272+
int maxBonusScoreUserId = -1;
270273

271274
long largestScoreDifference = long.MinValue;
272-
int largestScoreDifferenceUserId = 0;
275+
int largestScoreDifferenceUserId = -1;
273276

274277
long smallestScoreDifference = long.MaxValue;
275-
int smallestScoreDifferenceUserId = 0;
278+
int smallestScoreDifferenceUserId = -1;
276279

277280
for (int round = 1; round <= state.CurrentRound; round++)
278281
{
279282
long roundHighestScore = long.MinValue;
280-
int roundHighestScoreUserId = 0;
283+
int roundHighestScoreUserId = -1;
281284

282285
long roundLowestScore = long.MaxValue;
283286

@@ -346,11 +349,14 @@ private void populateRoomStatistics(MatchmakingRoomState state)
346349
}
347350
}
348351

349-
addAward(maxScoreUserId, "Score champ", "Highest score in a single round");
352+
if (maxScoreUserId > 0)
353+
addAward(maxScoreUserId, "Score champ", "Highest score in a single round");
350354

351-
addAward(maxAccuracyUserId, "Most accurate", "Highest accuracy in a single round");
355+
if (maxAccuracyUserId > 0)
356+
addAward(maxAccuracyUserId, "Most accurate", "Highest accuracy in a single round");
352357

353-
addAward(maxComboUserId, "Top combo", "Highest combo in a single round");
358+
if (maxComboUserId > 0)
359+
addAward(maxComboUserId, "Top combo", "Highest combo in a single round");
354360

355361
if (maxBonusScoreUserId > 0)
356362
addAward(maxBonusScoreUserId, "Biggest bonus", "Biggest bonus score across all rounds");

0 commit comments

Comments
 (0)