1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 12:07:23 +08:00

Externalise autoplay generation

This commit is contained in:
Dean Herbert 2021-05-25 18:37:04 +09:00
parent 7f9318d976
commit 7c89dbcd35
2 changed files with 36 additions and 11 deletions

View File

@ -1,9 +1,13 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Input.Bindings;
using osu.Game.Input.Bindings;
using osu.Game.Rulesets.Mods;
using osu.Game.Scoring;
using osu.Game.Screens.Ranking;
@ -11,15 +15,28 @@ namespace osu.Game.Screens.Play
{
public class ReplayPlayer : Player, IKeyBindingHandler<GlobalAction>
{
protected readonly Score Score;
protected Score Score { get; private set; }
private readonly Func<GameplayBeatmap, IReadOnlyList<Mod>, Score> createScore;
// Disallow replays from failing. (see https://github.com/ppy/osu/issues/6108)
protected override bool CheckModsAllowFailure() => false;
public ReplayPlayer(Score score, PlayerConfiguration configuration = null)
: this((_, __) => score, configuration)
{
}
public ReplayPlayer(Func<GameplayBeatmap, IReadOnlyList<Mod>, Score> createScore, PlayerConfiguration configuration = null)
: base(configuration)
{
Score = score;
this.createScore = createScore;
}
[BackgroundDependencyLoader]
private void load()
{
Score = createScore(GameplayBeatmap, Mods.Value);
}
protected override void PrepareReplay()

View File

@ -21,7 +21,7 @@ namespace osu.Game.Screens.Select
public class PlaySongSelect : SongSelect
{
private bool removeAutoModOnResume;
private OsuScreen player;
private OsuScreen playerLoader;
[Resolved(CanBeNull = true)]
private NotificationOverlay notifications { get; set; }
@ -49,7 +49,7 @@ namespace osu.Game.Screens.Select
{
base.OnResuming(last);
player = null;
playerLoader = null;
if (removeAutoModOnResume)
{
@ -79,14 +79,14 @@ namespace osu.Game.Screens.Select
protected override bool OnStart()
{
if (player != null) return false;
if (playerLoader != null) return false;
// Ctrl+Enter should start map with autoplay enabled.
if (GetContainingInputManager().CurrentState?.Keyboard.ControlPressed == true)
{
var autoplayMod = getAutoplayMod();
var autoInstance = getAutoplayMod();
if (autoplayMod == null)
if (autoInstance == null)
{
notifications?.Post(new SimpleNotification
{
@ -97,18 +97,26 @@ namespace osu.Game.Screens.Select
var mods = Mods.Value;
if (mods.All(m => m.GetType() != autoplayMod.GetType()))
if (mods.All(m => m.GetType() != autoInstance.GetType()))
{
Mods.Value = mods.Append(autoplayMod).ToArray();
Mods.Value = mods.Append(autoInstance).ToArray();
removeAutoModOnResume = true;
}
}
SampleConfirm?.Play();
this.Push(player = new PlayerLoader(() => new SoloPlayer()));
this.Push(playerLoader = new PlayerLoader(createPlayer));
return true;
Player createPlayer()
{
var autoplayMod = Mods.Value.OfType<ModAutoplay>().FirstOrDefault();
if (autoplayMod != null)
return new ReplayPlayer((beatmap, mods) => autoplayMod.CreateReplayScore(beatmap, mods));
return new SoloPlayer();
}
}
}
}