Handle ModAutoplay during score construction in the Player

This commit is contained in:
Roman Kapustin 2018-12-03 22:37:26 +03:00
parent b0adab5f96
commit c6c255718b
5 changed files with 13 additions and 12 deletions

View File

@ -23,7 +23,7 @@ namespace osu.Game.Tests.Visual
// Reset the mods // Reset the mods
Beatmap.Value.Mods.Value = Beatmap.Value.Mods.Value.Where(m => !(m is ModAutoplay)); Beatmap.Value.Mods.Value = Beatmap.Value.Mods.Value.Where(m => !(m is ModAutoplay));
return new ReplayPlayer(new Score { Replay = dummyRulesetContainer.Replay }); return new ReplayPlayer(new Score { Replay = dummyRulesetContainer.ReplayScore.Replay });
} }
} }
} }

View File

@ -18,7 +18,7 @@ namespace osu.Game.Rulesets.Mods
public override bool HasImplementation => GetType().GenericTypeArguments.Length == 0; public override bool HasImplementation => GetType().GenericTypeArguments.Length == 0;
public virtual void ApplyToRulesetContainer(RulesetContainer<T> rulesetContainer) => rulesetContainer.SetReplay(CreateReplayScore(rulesetContainer.Beatmap)?.Replay); public virtual void ApplyToRulesetContainer(RulesetContainer<T> rulesetContainer) => rulesetContainer.SetReplayScore(CreateReplayScore(rulesetContainer.Beatmap));
} }
public abstract class ModAutoplay : Mod, IApplicableFailOverride public abstract class ModAutoplay : Mod, IApplicableFailOverride

View File

@ -22,6 +22,7 @@ using osu.Game.Overlays;
using osu.Game.Replays; using osu.Game.Replays;
using osu.Game.Rulesets.Configuration; using osu.Game.Rulesets.Configuration;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
namespace osu.Game.Rulesets.UI namespace osu.Game.Rulesets.UI
{ {
@ -125,7 +126,7 @@ namespace osu.Game.Rulesets.UI
protected virtual ReplayInputHandler CreateReplayInputHandler(Replay replay) => null; protected virtual ReplayInputHandler CreateReplayInputHandler(Replay replay) => null;
public Replay Replay { get; private set; } public Score ReplayScore { get; private set; }
/// <summary> /// <summary>
/// Whether the game is paused. Used to block user input. /// Whether the game is paused. Used to block user input.
@ -135,14 +136,14 @@ namespace osu.Game.Rulesets.UI
/// <summary> /// <summary>
/// Sets a replay to be used, overriding local input. /// Sets a replay to be used, overriding local input.
/// </summary> /// </summary>
/// <param name="replay">The replay, null for local input.</param> /// <param name="replayScore">The replay, null for local input.</param>
public virtual void SetReplay(Replay replay) public virtual void SetReplayScore(Score replayScore)
{ {
if (ReplayInputManager == null) if (ReplayInputManager == null)
throw new InvalidOperationException($"A {nameof(KeyBindingInputManager)} which supports replay loading is not available"); throw new InvalidOperationException($"A {nameof(KeyBindingInputManager)} which supports replay loading is not available");
Replay = replay; ReplayScore = replayScore;
ReplayInputManager.ReplayInputHandler = replay != null ? CreateReplayInputHandler(replay) : null; ReplayInputManager.ReplayInputHandler = replayScore != null ? CreateReplayInputHandler(replayScore.Replay) : null;
HasReplayLoaded.Value = ReplayInputManager.ReplayInputHandler != null; HasReplayLoaded.Value = ReplayInputManager.ReplayInputHandler != null;
} }
@ -291,9 +292,9 @@ namespace osu.Game.Rulesets.UI
mod.ReadFromConfig(config); mod.ReadFromConfig(config);
} }
public override void SetReplay(Replay replay) public override void SetReplayScore(Score replayScore)
{ {
base.SetReplay(replay); base.SetReplayScore(replayScore);
if (ReplayInputManager?.ReplayInputHandler != null) if (ReplayInputManager?.ReplayInputHandler != null)
ReplayInputManager.ReplayInputHandler.GamefieldToScreenSpace = Playfield.GamefieldToScreenSpace; ReplayInputManager.ReplayInputHandler.GamefieldToScreenSpace = Playfield.GamefieldToScreenSpace;

View File

@ -277,7 +277,7 @@ namespace osu.Game.Screens.Play
if (!IsCurrentScreen) return; if (!IsCurrentScreen) return;
var score = CreateScore(); var score = CreateScore();
if (RulesetContainer.Replay == null) if (RulesetContainer.ReplayScore == null)
scoreManager.Import(score, true); scoreManager.Import(score, true);
Push(new Results(score)); Push(new Results(score));
@ -289,7 +289,7 @@ namespace osu.Game.Screens.Play
protected virtual ScoreInfo CreateScore() protected virtual ScoreInfo CreateScore()
{ {
var score = new ScoreInfo var score = RulesetContainer?.ReplayScore?.ScoreInfo ?? new ScoreInfo
{ {
Beatmap = Beatmap.Value.BeatmapInfo, Beatmap = Beatmap.Value.BeatmapInfo,
Ruleset = ruleset, Ruleset = ruleset,

View File

@ -17,7 +17,7 @@ namespace osu.Game.Screens.Play
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
RulesetContainer.SetReplay(score.Replay); RulesetContainer.SetReplayScore(score);
} }
protected override ScoreInfo CreateScore() => score.ScoreInfo; protected override ScoreInfo CreateScore() => score.ScoreInfo;