1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 16:32:54 +08:00

Fire initial match user states in TestMultiplayerClient

This commit is contained in:
Dean Herbert 2021-08-03 17:08:19 +09:00
parent a0119f8cd6
commit 75426f84f1
3 changed files with 62 additions and 16 deletions

View File

@ -11,6 +11,7 @@ using osu.Framework.Testing;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Online.Multiplayer; using osu.Game.Online.Multiplayer;
using osu.Game.Online.Multiplayer.MatchTypes.TeamVersus;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu;
@ -72,6 +73,27 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddUntilStep("wait for lounge to load", () => this.ChildrenOfType<MultiplayerLoungeSubScreen>().FirstOrDefault()?.IsLoaded == true); AddUntilStep("wait for lounge to load", () => this.ChildrenOfType<MultiplayerLoungeSubScreen>().FirstOrDefault()?.IsLoaded == true);
} }
[Test]
public void TestCreateWithType()
{
createRoom(() => new Room
{
Name = { Value = "Test Room" },
Type = { Value = MatchType.TeamVersus },
Playlist =
{
new PlaylistItem
{
Beatmap = { Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.RulesetID == 0)).BeatmapInfo },
Ruleset = { Value = new OsuRuleset().RulesetInfo },
}
}
});
AddAssert("room type is team vs", () => client.Room?.Settings.MatchType == MatchType.TeamVersus);
AddAssert("user state arrived", () => client.Room?.Users.FirstOrDefault()?.MatchState is TeamVersusUserState);
}
[Test] [Test]
public void TestChangeTypeViaMatchSettings() public void TestChangeTypeViaMatchSettings()
{ {

View File

@ -142,6 +142,8 @@ namespace osu.Game.Online.Multiplayer
APIRoom = room; APIRoom = room;
foreach (var user in joinedRoom.Users) foreach (var user in joinedRoom.Users)
updateUserPlayingState(user.UserID, user.State); updateUserPlayingState(user.UserID, user.State);
OnRoomJoined();
}, cancellationSource.Token).ConfigureAwait(false); }, cancellationSource.Token).ConfigureAwait(false);
// Update room settings. // Update room settings.
@ -149,6 +151,13 @@ namespace osu.Game.Online.Multiplayer
}, cancellationSource.Token).ConfigureAwait(false); }, cancellationSource.Token).ConfigureAwait(false);
} }
/// <summary>
/// Fired when the room join sequence is complete
/// </summary>
protected virtual void OnRoomJoined()
{
}
/// <summary> /// <summary>
/// Joins the <see cref="MultiplayerRoom"/> with a given ID. /// Joins the <see cref="MultiplayerRoom"/> with a given ID.
/// </summary> /// </summary>

View File

@ -153,6 +153,14 @@ namespace osu.Game.Tests.Visual.Multiplayer
return Task.FromResult(room); return Task.FromResult(room);
} }
protected override void OnRoomJoined()
{
Debug.Assert(Room != null);
// emulate the server sending this after the join room. scheduler required to make sure the join room event is fired first (in Join).
changeMatchType(Room.Settings.MatchType).Wait();
}
protected override Task LeaveRoomInternal() => Task.CompletedTask; protected override Task LeaveRoomInternal() => Task.CompletedTask;
public override Task TransferHost(int userId) => ((IMultiplayerClient)this).HostChanged(userId); public override Task TransferHost(int userId) => ((IMultiplayerClient)this).HostChanged(userId);
@ -166,22 +174,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
foreach (var user in Room.Users.Where(u => u.State == MultiplayerUserState.Ready)) foreach (var user in Room.Users.Where(u => u.State == MultiplayerUserState.Ready))
ChangeUserState(user.UserID, MultiplayerUserState.Idle); ChangeUserState(user.UserID, MultiplayerUserState.Idle);
switch (settings.MatchType) await changeMatchType(settings.MatchType).ConfigureAwait(false);
{
case MatchType.HeadToHead:
await ((IMultiplayerClient)this).MatchRoomStateChanged(null).ConfigureAwait(false);
foreach (var user in Room.Users)
await ((IMultiplayerClient)this).MatchUserStateChanged(user.UserID, null).ConfigureAwait(false);
break;
case MatchType.TeamVersus:
await ((IMultiplayerClient)this).MatchRoomStateChanged(TeamVersusRoomState.CreateDefault()).ConfigureAwait(false);
foreach (var user in Room.Users)
await ((IMultiplayerClient)this).MatchUserStateChanged(user.UserID, new TeamVersusUserState()).ConfigureAwait(false);
break;
}
} }
public override Task ChangeState(MultiplayerUserState newState) public override Task ChangeState(MultiplayerUserState newState)
@ -260,5 +253,27 @@ namespace osu.Game.Tests.Visual.Multiplayer
return Task.FromResult(set); return Task.FromResult(set);
} }
private async Task changeMatchType(MatchType type)
{
Debug.Assert(Room != null);
switch (type)
{
case MatchType.HeadToHead:
await ((IMultiplayerClient)this).MatchRoomStateChanged(null).ConfigureAwait(false);
foreach (var user in Room.Users)
await ((IMultiplayerClient)this).MatchUserStateChanged(user.UserID, null).ConfigureAwait(false);
break;
case MatchType.TeamVersus:
await ((IMultiplayerClient)this).MatchRoomStateChanged(TeamVersusRoomState.CreateDefault()).ConfigureAwait(false);
foreach (var user in Room.Users)
await ((IMultiplayerClient)this).MatchUserStateChanged(user.UserID, new TeamVersusUserState()).ConfigureAwait(false);
break;
}
}
} }
} }