Merge branch 'master' into match-start-control-test-refactor

This commit is contained in:
Dean Herbert
2022-04-13 22:26:10 +09:00
committed by GitHub
9 changed files with 52 additions and 26 deletions

View File

@ -26,6 +26,8 @@ namespace osu.Game.Tests.Visual.Gameplay
[TestFixture] [TestFixture]
public class TestSceneReplayDownloadButton : OsuManualInputManagerTestScene public class TestSceneReplayDownloadButton : OsuManualInputManagerTestScene
{ {
private const long online_score_id = 2553163309;
[Resolved] [Resolved]
private RulesetStore rulesets { get; set; } private RulesetStore rulesets { get; set; }
@ -43,6 +45,15 @@ namespace osu.Game.Tests.Visual.Gameplay
beatmapManager.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely(); beatmapManager.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();
} }
[SetUpSteps]
public void SetUpSteps()
{
AddStep("delete previous imports", () =>
{
scoreManager.Delete(s => s.OnlineID == online_score_id);
});
}
[Test] [Test]
public void TestDisplayStates() public void TestDisplayStates()
{ {
@ -180,7 +191,7 @@ namespace osu.Game.Tests.Visual.Gameplay
{ {
return new APIScore return new APIScore
{ {
OnlineID = 2553163309, OnlineID = online_score_id,
RulesetID = 0, RulesetID = 0,
Beatmap = CreateAPIBeatmapSet(new OsuRuleset().RulesetInfo).Beatmaps.First(), Beatmap = CreateAPIBeatmapSet(new OsuRuleset().RulesetInfo).Beatmaps.First(),
HasReplay = replayAvailable, HasReplay = replayAvailable,

View File

@ -27,6 +27,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
public abstract class MultiplayerGameplayLeaderboardTestScene : OsuTestScene public abstract class MultiplayerGameplayLeaderboardTestScene : OsuTestScene
{ {
private const int total_users = 16;
protected readonly BindableList<MultiplayerRoomUser> MultiplayerUsers = new BindableList<MultiplayerRoomUser>(); protected readonly BindableList<MultiplayerRoomUser> MultiplayerUsers = new BindableList<MultiplayerRoomUser>();
protected MultiplayerGameplayLeaderboard Leaderboard { get; private set; } protected MultiplayerGameplayLeaderboard Leaderboard { get; private set; }
@ -84,7 +86,11 @@ namespace osu.Game.Tests.Visual.Multiplayer
[SetUpSteps] [SetUpSteps]
public virtual void SetUpSteps() public virtual void SetUpSteps()
{ {
AddStep("reset counts", () => spectatorClient.Invocations.Clear()); AddStep("reset counts", () =>
{
spectatorClient.Invocations.Clear();
lastHeaders.Clear();
});
AddStep("set local user", () => ((DummyAPIAccess)API).LocalUser.Value = new APIUser AddStep("set local user", () => ((DummyAPIAccess)API).LocalUser.Value = new APIUser
{ {
@ -94,7 +100,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddStep("populate users", () => AddStep("populate users", () =>
{ {
MultiplayerUsers.Clear(); MultiplayerUsers.Clear();
for (int i = 0; i < 16; i++) for (int i = 0; i < total_users; i++)
MultiplayerUsers.Add(CreateUser(i)); MultiplayerUsers.Add(CreateUser(i));
}); });

View File

@ -3,7 +3,6 @@
using System.Linq; using System.Linq;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Utils;
using osu.Game.Online.Multiplayer; using osu.Game.Online.Multiplayer;
using osu.Game.Online.Multiplayer.MatchTypes.TeamVersus; using osu.Game.Online.Multiplayer.MatchTypes.TeamVersus;
using osu.Game.Rulesets.Osu.Scoring; using osu.Game.Rulesets.Osu.Scoring;
@ -14,12 +13,14 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
public class TestSceneMultiplayerGameplayLeaderboardTeams : MultiplayerGameplayLeaderboardTestScene public class TestSceneMultiplayerGameplayLeaderboardTeams : MultiplayerGameplayLeaderboardTestScene
{ {
private int team;
protected override MultiplayerRoomUser CreateUser(int userId) protected override MultiplayerRoomUser CreateUser(int userId)
{ {
var user = base.CreateUser(userId); var user = base.CreateUser(userId);
user.MatchState = new TeamVersusUserState user.MatchState = new TeamVersusUserState
{ {
TeamID = RNG.Next(0, 2) TeamID = team++ % 2
}; };
return user; return user;
} }

View File

@ -26,10 +26,10 @@ namespace osu.Game.Tests.Visual.Multiplayer
var beatmapInfo = CreateBeatmap(rulesetInfo).BeatmapInfo; var beatmapInfo = CreateBeatmap(rulesetInfo).BeatmapInfo;
var score = TestResources.CreateTestScoreInfo(beatmapInfo); var score = TestResources.CreateTestScoreInfo(beatmapInfo);
SortedDictionary<int, BindableInt> teamScores = new SortedDictionary<int, BindableInt> SortedDictionary<int, BindableLong> teamScores = new SortedDictionary<int, BindableLong>
{ {
{ 0, new BindableInt(team1Score) }, { 0, new BindableLong(team1Score) },
{ 1, new BindableInt(team2Score) } { 1, new BindableLong(team2Score) }
}; };
Stack.Push(screen = new MultiplayerTeamResultsScreen(score, 1, new PlaylistItem(beatmapInfo), teamScores)); Stack.Push(screen = new MultiplayerTeamResultsScreen(score, 1, new PlaylistItem(beatmapInfo), teamScores));

View File

@ -47,7 +47,10 @@ namespace osu.Game.Online
Downloader.DownloadBegan += downloadBegan; Downloader.DownloadBegan += downloadBegan;
Downloader.DownloadFailed += downloadFailed; Downloader.DownloadFailed += downloadFailed;
realmSubscription = realm.RegisterForNotifications(r => r.All<ScoreInfo>().Where(s => ((s.OnlineID > 0 && s.OnlineID == TrackedItem.OnlineID) || s.Hash == TrackedItem.Hash) && !s.DeletePending), (items, changes, ___) => realmSubscription = realm.RegisterForNotifications(r => r.All<ScoreInfo>().Where(s =>
((s.OnlineID > 0 && s.OnlineID == TrackedItem.OnlineID)
|| (!string.IsNullOrEmpty(s.Hash) && s.Hash == TrackedItem.Hash))
&& !s.DeletePending), (items, changes, ___) =>
{ {
if (items.Any()) if (items.Any())
Schedule(() => UpdateState(DownloadState.LocallyAvailable)); Schedule(() => UpdateState(DownloadState.LocallyAvailable));

View File

@ -24,12 +24,12 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
{ {
public class MultiplayerTeamResultsScreen : MultiplayerResultsScreen public class MultiplayerTeamResultsScreen : MultiplayerResultsScreen
{ {
private readonly SortedDictionary<int, BindableInt> teamScores; private readonly SortedDictionary<int, BindableLong> teamScores;
private Container winnerBackground; private Container winnerBackground;
private Drawable winnerText; private Drawable winnerText;
public MultiplayerTeamResultsScreen(ScoreInfo score, long roomId, PlaylistItem playlistItem, SortedDictionary<int, BindableInt> teamScores) public MultiplayerTeamResultsScreen(ScoreInfo score, long roomId, PlaylistItem playlistItem, SortedDictionary<int, BindableLong> teamScores)
: base(score, roomId, playlistItem) : base(score, roomId, playlistItem)
{ {
if (teamScores.Count != 2) if (teamScores.Count != 2)

View File

@ -19,8 +19,8 @@ namespace osu.Game.Screens.Play.HUD
private const float bar_height = 18; private const float bar_height = 18;
private const float font_size = 50; private const float font_size = 50;
public BindableInt Team1Score = new BindableInt(); public BindableLong Team1Score = new BindableLong();
public BindableInt Team2Score = new BindableInt(); public BindableLong Team2Score = new BindableLong();
protected MatchScoreCounter Score1Text; protected MatchScoreCounter Score1Text;
protected MatchScoreCounter Score2Text; protected MatchScoreCounter Score2Text;
@ -133,7 +133,7 @@ namespace osu.Game.Screens.Play.HUD
var winningBar = Team1Score.Value > Team2Score.Value ? score1Bar : score2Bar; var winningBar = Team1Score.Value > Team2Score.Value ? score1Bar : score2Bar;
var losingBar = Team1Score.Value <= Team2Score.Value ? score1Bar : score2Bar; var losingBar = Team1Score.Value <= Team2Score.Value ? score1Bar : score2Bar;
int diff = Math.Max(Team1Score.Value, Team2Score.Value) - Math.Min(Team1Score.Value, Team2Score.Value); long diff = Math.Max(Team1Score.Value, Team2Score.Value) - Math.Min(Team1Score.Value, Team2Score.Value);
losingBar.ResizeWidthTo(0, 400, Easing.OutQuint); losingBar.ResizeWidthTo(0, 400, Easing.OutQuint);
winningBar.ResizeWidthTo(Math.Min(0.4f, MathF.Pow(diff / 1500000f, 0.5f) / 2), 400, Easing.OutQuint); winningBar.ResizeWidthTo(Math.Min(0.4f, MathF.Pow(diff / 1500000f, 0.5f) / 2), 400, Easing.OutQuint);

View File

@ -29,7 +29,7 @@ namespace osu.Game.Screens.Play.HUD
{ {
protected readonly Dictionary<int, TrackedUserData> UserScores = new Dictionary<int, TrackedUserData>(); protected readonly Dictionary<int, TrackedUserData> UserScores = new Dictionary<int, TrackedUserData>();
public readonly SortedDictionary<int, BindableInt> TeamScores = new SortedDictionary<int, BindableInt>(); public readonly SortedDictionary<int, BindableLong> TeamScores = new SortedDictionary<int, BindableLong>();
[Resolved] [Resolved]
private OsuColour colours { get; set; } private OsuColour colours { get; set; }
@ -75,21 +75,27 @@ namespace osu.Game.Screens.Play.HUD
foreach (var user in playingUsers) foreach (var user in playingUsers)
{ {
var trackedUser = CreateUserData(user, ruleset, scoreProcessor); var trackedUser = CreateUserData(user, ruleset, scoreProcessor);
trackedUser.ScoringMode.BindTo(scoringMode); trackedUser.ScoringMode.BindTo(scoringMode);
trackedUser.Score.BindValueChanged(_ => Scheduler.AddOnce(updateTotals));
UserScores[user.UserID] = trackedUser; UserScores[user.UserID] = trackedUser;
if (trackedUser.Team is int team && !TeamScores.ContainsKey(team)) if (trackedUser.Team is int team && !TeamScores.ContainsKey(team))
TeamScores.Add(team, new BindableInt()); TeamScores.Add(team, new BindableLong());
} }
userLookupCache.GetUsersAsync(playingUsers.Select(u => u.UserID).ToArray()).ContinueWith(task => Schedule(() => userLookupCache.GetUsersAsync(playingUsers.Select(u => u.UserID).ToArray()).ContinueWith(task => Schedule(() =>
{ {
var users = task.GetResultSafely(); var users = task.GetResultSafely();
foreach (var user in users) for (int i = 0; i < users.Length; i++)
{ {
if (user == null) var user = users[i] ?? new APIUser
continue; {
Id = playingUsers[i].UserID,
Username = "Unknown user",
};
var trackedUser = UserScores[user.Id]; var trackedUser = UserScores[user.Id];
@ -175,8 +181,6 @@ namespace osu.Game.Screens.Play.HUD
trackedData.Frames.Add(new TimedFrame(bundle.Frames.First().Time, bundle.Header)); trackedData.Frames.Add(new TimedFrame(bundle.Frames.First().Time, bundle.Header));
trackedData.UpdateScore(); trackedData.UpdateScore();
updateTotals();
}); });
private void updateTotals() private void updateTotals()

View File

@ -351,8 +351,7 @@ namespace osu.Game.Stores
using (var transaction = realm.BeginWrite()) using (var transaction = realm.BeginWrite())
{ {
if (existing.DeletePending) UndeleteForReuse(existing);
UndeleteForReuse(existing);
transaction.Commit(); transaction.Commit();
} }
@ -388,9 +387,7 @@ namespace osu.Game.Stores
{ {
LogForModel(item, @$"Found existing {HumanisedModelName} for {item} (ID {existing.ID}) skipping import."); LogForModel(item, @$"Found existing {HumanisedModelName} for {item} (ID {existing.ID}) skipping import.");
if (existing.DeletePending) UndeleteForReuse(existing);
UndeleteForReuse(existing);
transaction.Commit(); transaction.Commit();
return existing.ToLive(Realm); return existing.ToLive(Realm);
@ -536,6 +533,10 @@ namespace osu.Game.Stores
/// <param name="existing">The existing model.</param> /// <param name="existing">The existing model.</param>
protected virtual void UndeleteForReuse(TModel existing) protected virtual void UndeleteForReuse(TModel existing)
{ {
if (!existing.DeletePending)
return;
LogForModel(existing, $@"Existing {HumanisedModelName}'s deletion flag has been removed to allow for reuse.");
existing.DeletePending = false; existing.DeletePending = false;
} }