mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 05:42:56 +08:00
Move ready-up operation logic again to client
To salvage ready up button tests.
This commit is contained in:
parent
db52255bbe
commit
e9b0652359
@ -34,6 +34,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
[Cached]
|
||||
private OngoingOperationTracker ongoingOperationTracker = new OngoingOperationTracker();
|
||||
|
||||
private IDisposable toggleReadyOperation;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(GameHost host, AudioManager audio)
|
||||
{
|
||||
@ -61,6 +63,14 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
Beatmap = { Value = beatmap },
|
||||
Ruleset = { Value = beatmap.Ruleset }
|
||||
}
|
||||
},
|
||||
OnToggleReady = async () =>
|
||||
{
|
||||
toggleReadyOperation = ongoingOperationTracker.BeginOperation();
|
||||
|
||||
bool gameplayStarted = await Client.ToggleReady();
|
||||
if (!gameplayStarted)
|
||||
toggleReadyOperation.Dispose();
|
||||
}
|
||||
};
|
||||
});
|
||||
@ -168,15 +178,11 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
|
||||
private void verifyGameplayStartFlow()
|
||||
{
|
||||
IDisposable gameplayStartOperation = null;
|
||||
|
||||
AddStep("hook up tracker", () => button.OnReady = () => gameplayStartOperation = ongoingOperationTracker.BeginOperation());
|
||||
|
||||
addClickButtonStep();
|
||||
AddAssert("user waiting for load", () => Client.Room?.Users[0].State == MultiplayerUserState.WaitingForLoad);
|
||||
AddAssert("ready button disabled", () => !button.ChildrenOfType<OsuButton>().Single().Enabled.Value);
|
||||
|
||||
AddStep("transitioned to gameplay", () => gameplayStartOperation.Dispose());
|
||||
AddStep("transitioned to gameplay", () => toggleReadyOperation.Dispose());
|
||||
AddAssert("ready button enabled", () => button.ChildrenOfType<OsuButton>().Single().Enabled.Value);
|
||||
}
|
||||
}
|
||||
|
@ -183,6 +183,39 @@ namespace osu.Game.Online.Multiplayer
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Toggles the <see cref="LocalUser"/>'s ready state.
|
||||
/// </summary>
|
||||
/// <returns><c>true</c> if this toggle triggered a gameplay start; <c>false</c> otherwise.</returns>
|
||||
/// <exception cref="InvalidOperationException">If a toggle of ready state is not valid at this time.</exception>
|
||||
public async Task<bool> ToggleReady()
|
||||
{
|
||||
var localUser = LocalUser;
|
||||
|
||||
if (localUser == null)
|
||||
return false;
|
||||
|
||||
switch (localUser.State)
|
||||
{
|
||||
case MultiplayerUserState.Idle:
|
||||
await ChangeState(MultiplayerUserState.Ready);
|
||||
return false;
|
||||
|
||||
case MultiplayerUserState.Ready:
|
||||
if (Room?.Host?.Equals(localUser) == true)
|
||||
{
|
||||
await StartMatch();
|
||||
return true;
|
||||
}
|
||||
|
||||
await ChangeState(MultiplayerUserState.Idle);
|
||||
return false;
|
||||
|
||||
default:
|
||||
throw new InvalidOperationException($"Cannot toggle ready when in {localUser.State}");
|
||||
}
|
||||
}
|
||||
|
||||
public abstract Task TransferHost(int userId);
|
||||
|
||||
public abstract Task ChangeSettings(MultiplayerRoomSettings settings);
|
||||
|
@ -20,9 +20,9 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
|
||||
public readonly Bindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
|
||||
|
||||
public Action OnReady
|
||||
public Action OnToggleReady
|
||||
{
|
||||
set => readyButton.OnReady = value;
|
||||
set => readyButton.OnToggleReady = value;
|
||||
}
|
||||
|
||||
private readonly Drawable background;
|
||||
|
@ -23,7 +23,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
{
|
||||
public Bindable<PlaylistItem> SelectedItem => button.SelectedItem;
|
||||
|
||||
public Action OnReady
|
||||
public Action OnToggleReady
|
||||
{
|
||||
set => button.Action = value;
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
new MultiplayerMatchFooter
|
||||
{
|
||||
SelectedItem = { BindTarget = SelectedItem },
|
||||
OnReady = onReady
|
||||
OnToggleReady = onToggleReady
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -209,27 +209,22 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
|
||||
private void onPlaylistChanged(object sender, NotifyCollectionChangedEventArgs e) => SelectedItem.Value = Playlist.FirstOrDefault();
|
||||
|
||||
private void onReady()
|
||||
{
|
||||
var localUser = client.LocalUser;
|
||||
|
||||
if (localUser == null)
|
||||
return;
|
||||
|
||||
if (localUser.State == MultiplayerUserState.Idle)
|
||||
client.ChangeState(MultiplayerUserState.Ready).CatchUnobservedExceptions(true);
|
||||
else
|
||||
{
|
||||
if (client.Room?.Host?.Equals(localUser) == true)
|
||||
private void onToggleReady()
|
||||
{
|
||||
Debug.Assert(gameplayStartOperation == null);
|
||||
gameplayStartOperation = ongoingOperationTracker.BeginOperation();
|
||||
|
||||
client.StartMatch().CatchUnobservedExceptions(true);
|
||||
}
|
||||
else
|
||||
client.ChangeState(MultiplayerUserState.Idle).CatchUnobservedExceptions(true);
|
||||
}
|
||||
client.ToggleReady()
|
||||
.ContinueWith(t =>
|
||||
{
|
||||
// if gameplay was started, the button will be unblocked on load requested.
|
||||
if (t.Result) return;
|
||||
|
||||
// gameplay was not started; unblock button.
|
||||
gameplayStartOperation?.Dispose();
|
||||
gameplayStartOperation = null;
|
||||
})
|
||||
.CatchUnobservedExceptions();
|
||||
}
|
||||
|
||||
private void onLoadRequested()
|
||||
|
Loading…
Reference in New Issue
Block a user