Skip to content

Commit

Permalink
Merge pull request #3813 from UselessToucan/do_not_use_local_user_for…
Browse files Browse the repository at this point in the history
…_autoplay_score

Handle ModAutoplay during score construction in the Player
  • Loading branch information
peppy committed Jan 4, 2019
2 parents 2fc10cb + 7d1163a commit e596d4f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
3 changes: 1 addition & 2 deletions osu.Game.Tests/Visual/TestCaseReplay.cs
Expand Up @@ -5,7 +5,6 @@
using System.Linq;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Scoring;
using osu.Game.Screens.Play;

namespace osu.Game.Tests.Visual
Expand All @@ -23,7 +22,7 @@ protected override Player CreatePlayer(Ruleset ruleset)
// Reset the mods
Beatmap.Value.Mods.Value = Beatmap.Value.Mods.Value.Where(m => !(m is ModAutoplay));

return new ReplayPlayer(new Score { Replay = dummyRulesetContainer.Replay });
return new ReplayPlayer(dummyRulesetContainer.ReplayScore);
}
}
}
2 changes: 1 addition & 1 deletion osu.Game/Rulesets/Mods/ModAutoplay.cs
Expand Up @@ -18,7 +18,7 @@ public abstract class ModAutoplay<T> : ModAutoplay, IApplicableToRulesetContaine

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
Expand Down
15 changes: 8 additions & 7 deletions osu.Game/Rulesets/UI/RulesetContainer.cs
Expand Up @@ -22,6 +22,7 @@
using osu.Game.Replays;
using osu.Game.Rulesets.Configuration;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;

namespace osu.Game.Rulesets.UI
{
Expand Down Expand Up @@ -130,7 +131,7 @@ protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnl

protected virtual ReplayInputHandler CreateReplayInputHandler(Replay replay) => null;

public Replay Replay { get; private set; }
public Score ReplayScore { get; private set; }

/// <summary>
/// Whether the game is paused. Used to block user input.
Expand All @@ -140,14 +141,14 @@ protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnl
/// <summary>
/// Sets a replay to be used, overriding local input.
/// </summary>
/// <param name="replay">The replay, null for local input.</param>
public virtual void SetReplay(Replay replay)
/// <param name="replayScore">The replay, null for local input.</param>
public virtual void SetReplayScore(Score replayScore)
{
if (ReplayInputManager == null)
throw new InvalidOperationException($"A {nameof(KeyBindingInputManager)} which supports replay loading is not available");

Replay = replay;
ReplayInputManager.ReplayInputHandler = replay != null ? CreateReplayInputHandler(replay) : null;
ReplayScore = replayScore;
ReplayInputManager.ReplayInputHandler = replayScore != null ? CreateReplayInputHandler(replayScore.Replay) : null;

HasReplayLoaded.Value = ReplayInputManager.ReplayInputHandler != null;
}
Expand Down Expand Up @@ -302,9 +303,9 @@ private void applyRulesetMods(IEnumerable<Mod> mods, OsuConfigManager 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)
ReplayInputManager.ReplayInputHandler.GamefieldToScreenSpace = Playfield.GamefieldToScreenSpace;
Expand Down
4 changes: 2 additions & 2 deletions osu.Game/Screens/Play/Player.cs
Expand Up @@ -285,7 +285,7 @@ private void onCompletion()
if (!IsCurrentScreen) return;

var score = CreateScore();
if (RulesetContainer.Replay == null)
if (RulesetContainer.ReplayScore == null)
scoreManager.Import(score, true);

Push(CreateResults(score));
Expand All @@ -297,7 +297,7 @@ private void onCompletion()

protected virtual ScoreInfo CreateScore()
{
var score = new ScoreInfo
var score = RulesetContainer.ReplayScore?.ScoreInfo ?? new ScoreInfo
{
Beatmap = Beatmap.Value.BeatmapInfo,
Ruleset = ruleset,
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Screens/Play/ReplayPlayer.cs
Expand Up @@ -17,7 +17,7 @@ public ReplayPlayer(Score score)
protected override void LoadComplete()
{
base.LoadComplete();
RulesetContainer.SetReplay(score.Replay);
RulesetContainer.SetReplayScore(score);
}

protected override ScoreInfo CreateScore() => score.ScoreInfo;
Expand Down

0 comments on commit e596d4f

Please sign in to comment.