1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 16:12:57 +08:00

Ensure autoplay tests actually increase score above zero

This commit is contained in:
Dean Herbert 2018-05-26 14:46:05 +09:00
parent b0d2af16f1
commit 975ce82177
3 changed files with 28 additions and 12 deletions

View File

@ -5,6 +5,7 @@ using System.ComponentModel;
using System.Linq; using System.Linq;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
namespace osu.Game.Tests.Visual namespace osu.Game.Tests.Visual
@ -15,7 +16,20 @@ namespace osu.Game.Tests.Visual
protected override Player CreatePlayer(WorkingBeatmap beatmap, Ruleset ruleset) protected override Player CreatePlayer(WorkingBeatmap beatmap, Ruleset ruleset)
{ {
beatmap.Mods.Value = beatmap.Mods.Value.Concat(new[] { ruleset.GetAutoplayMod() }); beatmap.Mods.Value = beatmap.Mods.Value.Concat(new[] { ruleset.GetAutoplayMod() });
return base.CreatePlayer(beatmap, ruleset); return new ScoreAccessiblePlayer
{
InitialBeatmap = beatmap,
AllowPause = false,
AllowLeadIn = false,
AllowResults = false,
};
}
protected override bool ContinueCondition(Player player) => base.ContinueCondition(player) && ((ScoreAccessiblePlayer)player).ScoreProcessor.TotalScore > 0;
private class ScoreAccessiblePlayer : Player
{
public new ScoreProcessor ScoreProcessor => base.ScoreProcessor;
} }
} }
} }

View File

@ -70,7 +70,7 @@ namespace osu.Game.Screens.Play
private SampleChannel sampleRestart; private SampleChannel sampleRestart;
private ScoreProcessor scoreProcessor; protected ScoreProcessor ScoreProcessor;
protected RulesetContainer RulesetContainer; protected RulesetContainer RulesetContainer;
private HUDOverlay hudOverlay; private HUDOverlay hudOverlay;
@ -149,7 +149,7 @@ namespace osu.Game.Screens.Play
userAudioOffset.ValueChanged += v => offsetClock.Offset = v; userAudioOffset.ValueChanged += v => offsetClock.Offset = v;
userAudioOffset.TriggerChange(); userAudioOffset.TriggerChange();
scoreProcessor = RulesetContainer.CreateScoreProcessor(); ScoreProcessor = RulesetContainer.CreateScoreProcessor();
Children = new Drawable[] Children = new Drawable[]
{ {
@ -176,7 +176,7 @@ namespace osu.Game.Screens.Play
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Child = RulesetContainer Child = RulesetContainer
}, },
new BreakOverlay(beatmap.BeatmapInfo.LetterboxInBreaks, scoreProcessor) new BreakOverlay(beatmap.BeatmapInfo.LetterboxInBreaks, ScoreProcessor)
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
@ -184,7 +184,7 @@ namespace osu.Game.Screens.Play
Breaks = beatmap.Breaks Breaks = beatmap.Breaks
}, },
RulesetContainer.Cursor?.CreateProxy() ?? new Container(), RulesetContainer.Cursor?.CreateProxy() ?? new Container(),
hudOverlay = new HUDOverlay(scoreProcessor, RulesetContainer, working, offsetClock, adjustableClock) hudOverlay = new HUDOverlay(ScoreProcessor, RulesetContainer, working, offsetClock, adjustableClock)
{ {
Clock = Clock, // hud overlay doesn't want to use the audio clock directly Clock = Clock, // hud overlay doesn't want to use the audio clock directly
ProcessCustomClock = false, ProcessCustomClock = false,
@ -225,11 +225,11 @@ namespace osu.Game.Screens.Play
initializeStoryboard(false); initializeStoryboard(false);
// Bind ScoreProcessor to ourselves // Bind ScoreProcessor to ourselves
scoreProcessor.AllJudged += onCompletion; ScoreProcessor.AllJudged += onCompletion;
scoreProcessor.Failed += onFail; ScoreProcessor.Failed += onFail;
foreach (var mod in Beatmap.Value.Mods.Value.OfType<IApplicableToScoreProcessor>()) foreach (var mod in Beatmap.Value.Mods.Value.OfType<IApplicableToScoreProcessor>())
mod.ApplyToScoreProcessor(scoreProcessor); mod.ApplyToScoreProcessor(ScoreProcessor);
} }
private void applyRateFromMods() private void applyRateFromMods()
@ -254,7 +254,7 @@ namespace osu.Game.Screens.Play
private void onCompletion() private void onCompletion()
{ {
// Only show the completion screen if the player hasn't failed // Only show the completion screen if the player hasn't failed
if (scoreProcessor.HasFailed || onCompletionEvent != null) if (ScoreProcessor.HasFailed || onCompletionEvent != null)
return; return;
ValidForResume = false; ValidForResume = false;
@ -272,7 +272,7 @@ namespace osu.Game.Screens.Play
Beatmap = Beatmap.Value.BeatmapInfo, Beatmap = Beatmap.Value.BeatmapInfo,
Ruleset = ruleset Ruleset = ruleset
}; };
scoreProcessor.PopulateScore(score); ScoreProcessor.PopulateScore(score);
score.User = RulesetContainer.Replay?.User ?? api.LocalUser.Value; score.User = RulesetContainer.Replay?.User ?? api.LocalUser.Value;
Push(new Results(score)); Push(new Results(score));
}); });

View File

@ -44,7 +44,7 @@ namespace osu.Game.Tests.Visual
{ {
Player p = null; Player p = null;
AddStep(ruleset.RulesetInfo.Name, () => p = loadPlayerFor(ruleset)); AddStep(ruleset.RulesetInfo.Name, () => p = loadPlayerFor(ruleset));
AddUntilStep(() => p.IsLoaded); AddUntilStep(() => ContinueCondition(p));
} }
else else
{ {
@ -52,11 +52,13 @@ namespace osu.Game.Tests.Visual
{ {
Player p = null; Player p = null;
AddStep(r.Name, () => p = loadPlayerFor(r)); AddStep(r.Name, () => p = loadPlayerFor(r));
AddUntilStep(() => p.IsLoaded); AddUntilStep(() => ContinueCondition(p));
} }
} }
} }
protected virtual bool ContinueCondition(Player player) => player.IsLoaded;
protected virtual IBeatmap CreateBeatmap(Ruleset ruleset) => new TestBeatmap(ruleset.RulesetInfo); protected virtual IBeatmap CreateBeatmap(Ruleset ruleset) => new TestBeatmap(ruleset.RulesetInfo);
private Player loadPlayerFor(RulesetInfo ri) => loadPlayerFor(ri.CreateInstance()); private Player loadPlayerFor(RulesetInfo ri) => loadPlayerFor(ri.CreateInstance());