Convert remaining two flags to ctor parameters

This commit is contained in:
Dean Herbert 2019-03-26 16:53:44 +09:00
parent 83863d35c3
commit a88f23e555
8 changed files with 41 additions and 39 deletions

View File

@ -330,11 +330,7 @@ private void performTest(List<ReplayFrame> frames)
},
}, Clock);
var p = new ScoreAccessibleReplayPlayer(new Score { Replay = new Replay { Frames = frames } })
{
AllowPause = false,
AllowResults = false
};
var p = new ScoreAccessibleReplayPlayer(new Score { Replay = new Replay { Frames = frames } });
p.OnLoadComplete += _ =>
{
@ -363,7 +359,7 @@ private class ScoreAccessibleReplayPlayer : ReplayPlayer
public new ScoreProcessor ScoreProcessor => base.ScoreProcessor;
public ScoreAccessibleReplayPlayer(Score score)
: base(score)
: base(score, false, false)
{
}
}

View File

@ -257,9 +257,8 @@ private void performFullSetup(bool allowPause = false)
AddStep("Start player loader", () =>
{
songSelect.Push(playerLoader = new TestPlayerLoader(player = new TestPlayer
songSelect.Push(playerLoader = new TestPlayerLoader(player = new TestPlayer(allowPause)
{
AllowPause = allowPause,
Ready = true,
}));
});
@ -357,6 +356,11 @@ protected override UserDimContainer CreateStoryboardContainer()
public readonly Bindable<bool> ReplacesBackground = new Bindable<bool>();
public readonly Bindable<bool> IsPaused = new Bindable<bool>();
public TestPlayer(bool allowPause = true)
: base(allowPause)
{
}
public bool IsStoryboardVisible() => ((TestUserDimContainer)CurrentStoryboardContainer).CurrentAlpha == 1;
public bool IsStoryboardInvisible() => ((TestUserDimContainer)CurrentStoryboardContainer).CurrentAlpha <= 1;

View File

@ -15,11 +15,7 @@ public class TestCaseAutoplay : AllPlayersTestCase
protected override Player CreatePlayer(Ruleset ruleset)
{
Beatmap.Value.Mods.Value = Beatmap.Value.Mods.Value.Concat(new[] { ruleset.GetAutoplayMod() });
return new ScoreAccessiblePlayer
{
AllowPause = false,
AllowResults = false,
};
return new ScoreAccessiblePlayer();
}
protected override void AddCheckSteps()
@ -32,6 +28,11 @@ private class ScoreAccessiblePlayer : Player
{
public new ScoreProcessor ScoreProcessor => base.ScoreProcessor;
public new HUDOverlay HUDOverlay => base.HUDOverlay;
public ScoreAccessiblePlayer()
: base(false, false)
{
}
}
}
}

View File

@ -26,11 +26,7 @@ private void load(OsuGameBase game)
{
Beatmap.Value = new DummyWorkingBeatmap(game);
AddStep("load dummy beatmap", () => stack.Push(loader = new PlayerLoader(() => new Player
{
AllowPause = false,
AllowResults = false,
})));
AddStep("load dummy beatmap", () => stack.Push(loader = new PlayerLoader(() => new Player(false, false))));
AddUntilStep("wait for current", () => loader.IsCurrentScreen());
@ -46,11 +42,7 @@ private void load(OsuGameBase game)
{
SlowLoadPlayer slow = null;
stack.Push(loader = new PlayerLoader(() => slow = new SlowLoadPlayer
{
AllowPause = false,
AllowResults = false,
}));
stack.Push(loader = new PlayerLoader(() => slow = new SlowLoadPlayer(false, false)));
Scheduler.AddDelayed(() => slow.Ready = true, 5000);
});
@ -62,6 +54,11 @@ protected class SlowLoadPlayer : Player
{
public bool Ready;
public SlowLoadPlayer(bool allowPause = true, bool showResults = true)
: base(allowPause, showResults)
{
}
[BackgroundDependencyLoader]
private void load()
{

View File

@ -43,9 +43,6 @@ public class Player : ScreenWithBeatmapBackground
public bool HasFailed { get; private set; }
public bool AllowPause { get; set; } = true;
public bool AllowResults { get; set; } = true;
private Bindable<bool> mouseWheelDisabled;
private readonly Bindable<bool> storyboardReplacesBackground = new Bindable<bool>();
@ -70,6 +67,20 @@ public class Player : ScreenWithBeatmapBackground
protected GameplayClockContainer GameplayClockContainer { get; private set; }
private readonly bool allowPause;
private readonly bool showResults;
/// <summary>
/// Create a new player instance.
/// </summary>
/// <param name="allowPause">Whether pausing should be allowed. If not allowed, attempting to pause will quit.</param>
/// <param name="showResults">Whether results screen should be pushed on completion.</param>
public Player(bool allowPause = true, bool showResults = true)
{
this.allowPause = allowPause;
this.showResults = showResults;
}
[BackgroundDependencyLoader]
private void load(AudioManager audio, IAPIProvider api, OsuConfigManager config)
{
@ -233,7 +244,7 @@ private void onCompletion()
ValidForResume = false;
if (!AllowResults) return;
if (!showResults) return;
using (BeginDelayedSequence(1000))
{
@ -347,7 +358,7 @@ private bool onFail()
private bool canPause =>
// must pass basic screen conditions (beatmap loaded, instance allows pause)
LoadedBeatmapSuccessfully && AllowPause && ValidForResume
LoadedBeatmapSuccessfully && allowPause && ValidForResume
// replays cannot be paused and exit immediately
&& !DrawableRuleset.HasReplayLoaded.Value
// cannot pause if we are already in a fail state

View File

@ -9,7 +9,8 @@ public class ReplayPlayer : Player
{
private readonly Score score;
public ReplayPlayer(Score score)
public ReplayPlayer(Score score, bool allowPause = true, bool showResults = true)
: base(allowPause, showResults)
{
this.score = score;
}

View File

@ -80,10 +80,6 @@ private Player loadPlayerFor(RulesetInfo ri)
return Player;
}
protected virtual Player CreatePlayer(Ruleset ruleset) => new Player
{
AllowPause = false,
AllowResults = false,
};
protected virtual Player CreatePlayer(Ruleset ruleset) => new Player(false, false);
}
}

View File

@ -56,10 +56,6 @@ private void loadPlayer()
LoadScreen(Player);
}
protected virtual Player CreatePlayer(Ruleset ruleset) => new Player
{
AllowPause = false,
AllowResults = false,
};
protected virtual Player CreatePlayer(Ruleset ruleset) => new Player(false, false);
}
}