mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 13:32:54 +08:00
Fire initial match user states in TestMultiplayerClient
This commit is contained in:
parent
a0119f8cd6
commit
75426f84f1
@ -11,6 +11,7 @@ using osu.Framework.Testing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Online.Multiplayer.MatchTypes.TeamVersus;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Rulesets;
|
||||
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);
|
||||
}
|
||||
|
||||
[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]
|
||||
public void TestChangeTypeViaMatchSettings()
|
||||
{
|
||||
|
@ -142,6 +142,8 @@ namespace osu.Game.Online.Multiplayer
|
||||
APIRoom = room;
|
||||
foreach (var user in joinedRoom.Users)
|
||||
updateUserPlayingState(user.UserID, user.State);
|
||||
|
||||
OnRoomJoined();
|
||||
}, cancellationSource.Token).ConfigureAwait(false);
|
||||
|
||||
// Update room settings.
|
||||
@ -149,6 +151,13 @@ namespace osu.Game.Online.Multiplayer
|
||||
}, cancellationSource.Token).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fired when the room join sequence is complete
|
||||
/// </summary>
|
||||
protected virtual void OnRoomJoined()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Joins the <see cref="MultiplayerRoom"/> with a given ID.
|
||||
/// </summary>
|
||||
|
@ -153,6 +153,14 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
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;
|
||||
|
||||
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))
|
||||
ChangeUserState(user.UserID, MultiplayerUserState.Idle);
|
||||
|
||||
switch (settings.MatchType)
|
||||
{
|
||||
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;
|
||||
}
|
||||
await changeMatchType(settings.MatchType).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public override Task ChangeState(MultiplayerUserState newState)
|
||||
@ -260,5 +253,27 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user