mirror of
https://github.com/ppy/osu.git
synced 2025-03-31 08:57:19 +08:00
refactor(KeyCounter): address bindables issues
`IsCounting` is back being an auto-property. `countPresses` is now encapsulated and being exposed as an `IBindable<int>` via `CountPresses`
This commit is contained in:
parent
6340730427
commit
ddd6c1a1c6
@ -35,14 +35,14 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
var referenceBeatmap = CreateBeatmap(new OsuRuleset().RulesetInfo);
|
||||
|
||||
AddUntilStep("score above zero", () => Player.ScoreProcessor.TotalScore.Value > 0);
|
||||
AddUntilStep("key counter counted keys", () => Player.HUDOverlay.KeyCounter.Children.Any(kc => kc.CountPresses > 2));
|
||||
AddUntilStep("key counter counted keys", () => Player.HUDOverlay.KeyCounter.Children.Any(kc => kc.CountPresses.Value > 2));
|
||||
|
||||
seekTo(referenceBeatmap.Breaks[0].StartTime);
|
||||
AddAssert("keys not counting", () => !Player.HUDOverlay.KeyCounter.IsCounting);
|
||||
AddAssert("overlay displays 100% accuracy", () => Player.BreakOverlay.ChildrenOfType<BreakInfo>().Single().AccuracyDisplay.Current.Value == 1);
|
||||
|
||||
AddStep("rewind", () => Player.GameplayClockContainer.Seek(-80000));
|
||||
AddUntilStep("key counter reset", () => Player.HUDOverlay.KeyCounter.Children.All(kc => kc.CountPresses == 0));
|
||||
AddUntilStep("key counter reset", () => Player.HUDOverlay.KeyCounter.Children.All(kc => kc.CountPresses.Value == 0));
|
||||
|
||||
seekTo(referenceBeatmap.HitObjects[^1].GetEndTime());
|
||||
AddUntilStep("results displayed", () => getResultsScreen()?.IsLoaded == true);
|
||||
|
@ -31,11 +31,11 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
AddUntilStep("wait for track to start running", () => Beatmap.Value.Track.IsRunning);
|
||||
addSeekStep(3000);
|
||||
AddAssert("all judged", () => Player.DrawableRuleset.Playfield.AllHitObjects.All(h => h.Judged));
|
||||
AddUntilStep("key counter counted keys", () => Player.HUDOverlay.KeyCounter.Children.Select(kc => kc.CountPresses).Sum() == 15);
|
||||
AddUntilStep("key counter counted keys", () => Player.HUDOverlay.KeyCounter.Children.Select(kc => kc.CountPresses.Value).Sum() == 15);
|
||||
AddStep("clear results", () => Player.Results.Clear());
|
||||
addSeekStep(0);
|
||||
AddAssert("none judged", () => Player.DrawableRuleset.Playfield.AllHitObjects.All(h => !h.Judged));
|
||||
AddUntilStep("key counters reset", () => Player.HUDOverlay.KeyCounter.Children.All(kc => kc.CountPresses == 0));
|
||||
AddUntilStep("key counters reset", () => Player.HUDOverlay.KeyCounter.Children.All(kc => kc.CountPresses.Value == 0));
|
||||
AddAssert("no results triggered", () => Player.Results.Count == 0);
|
||||
}
|
||||
|
||||
|
@ -46,12 +46,12 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
}
|
||||
|
||||
addPressKeyStep();
|
||||
AddAssert($"Check {testKey} counter after keypress", () => testCounter.CountPresses == 1);
|
||||
AddAssert($"Check {testKey} counter after keypress", () => testCounter.CountPresses.Value == 1);
|
||||
addPressKeyStep();
|
||||
AddAssert($"Check {testKey} counter after keypress", () => testCounter.CountPresses == 2);
|
||||
AddAssert($"Check {testKey} counter after keypress", () => testCounter.CountPresses.Value == 2);
|
||||
AddStep("Disable counting", () => testCounter.IsCounting = false);
|
||||
addPressKeyStep();
|
||||
AddAssert($"Check {testKey} count has not changed", () => testCounter.CountPresses == 2);
|
||||
AddAssert($"Check {testKey} count has not changed", () => testCounter.CountPresses.Value == 2);
|
||||
|
||||
Add(kc);
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
protected override void AddCheckSteps()
|
||||
{
|
||||
AddUntilStep("score above zero", () => ((ScoreAccessibleReplayPlayer)Player).ScoreProcessor.TotalScore.Value > 0);
|
||||
AddUntilStep("key counter counted keys", () => ((ScoreAccessibleReplayPlayer)Player).HUDOverlay.KeyCounter.Children.Any(kc => kc.CountPresses > 0));
|
||||
AddUntilStep("key counter counted keys", () => ((ScoreAccessibleReplayPlayer)Player).HUDOverlay.KeyCounter.Children.Any(kc => kc.CountPresses.Value > 0));
|
||||
AddAssert("cannot fail", () => !((ScoreAccessibleReplayPlayer)Player).AllowFail);
|
||||
}
|
||||
|
||||
|
@ -69,10 +69,10 @@ namespace osu.Game.Tests.Visual.Navigation
|
||||
AddUntilStep("wait for gameplay", () => player?.IsBreakTime.Value == false);
|
||||
|
||||
AddStep("press 'z'", () => InputManager.Key(Key.Z));
|
||||
AddAssert("key counter didn't increase", () => keyCounter.CountPresses == 0);
|
||||
AddAssert("key counter didn't increase", () => keyCounter.CountPresses.Value == 0);
|
||||
|
||||
AddStep("press 's'", () => InputManager.Key(Key.S));
|
||||
AddAssert("key counter did increase", () => keyCounter.CountPresses == 1);
|
||||
AddAssert("key counter did increase", () => keyCounter.CountPresses.Value == 1);
|
||||
}
|
||||
|
||||
private KeyBindingsSubsection osuBindingSubsection => keyBindingPanel
|
||||
|
@ -67,7 +67,7 @@ namespace osu.Game.Screens.Play
|
||||
},
|
||||
countSpriteText = new OsuSpriteText
|
||||
{
|
||||
Text = CountPresses.ToString(@"#,0"),
|
||||
Text = CountPresses.Value.ToString(@"#,0"),
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
RelativePositionAxes = Axes.Both,
|
||||
@ -83,7 +83,7 @@ namespace osu.Game.Screens.Play
|
||||
Width = buttonSprite.DrawWidth;
|
||||
|
||||
IsLit.BindValueChanged(e => updateGlowSprite(e.NewValue), true);
|
||||
PressesCount.BindValueChanged(e => countSpriteText.Text = e.NewValue.ToString(@"#,0"), true);
|
||||
CountPresses.BindValueChanged(e => countSpriteText.Text = e.NewValue.ToString(@"#,0"), true);
|
||||
}
|
||||
|
||||
private void updateGlowSprite(bool show)
|
||||
|
@ -12,28 +12,18 @@ namespace osu.Game.Screens.Play
|
||||
{
|
||||
public readonly InputTrigger Trigger;
|
||||
|
||||
protected Bindable<bool> IsCountingBindable = new BindableBool(true);
|
||||
|
||||
private readonly Container content;
|
||||
|
||||
protected override Container<Drawable> Content => content;
|
||||
|
||||
protected Bindable<int> PressesCount = new BindableInt
|
||||
private readonly Bindable<int> countPresses = new BindableInt
|
||||
{
|
||||
MinValue = 0
|
||||
};
|
||||
|
||||
public bool IsCounting
|
||||
{
|
||||
get => IsCountingBindable.Value;
|
||||
set => IsCountingBindable.Value = value;
|
||||
}
|
||||
public bool IsCounting { get; set; } = true;
|
||||
|
||||
public int CountPresses
|
||||
{
|
||||
get => PressesCount.Value;
|
||||
private set => PressesCount.Value = value;
|
||||
}
|
||||
public IBindable<int> CountPresses => countPresses;
|
||||
|
||||
protected KeyCounter(InputTrigger trigger)
|
||||
{
|
||||
@ -59,7 +49,7 @@ namespace osu.Game.Screens.Play
|
||||
if (!IsCounting)
|
||||
return;
|
||||
|
||||
CountPresses++;
|
||||
countPresses.Value++;
|
||||
}
|
||||
|
||||
public void Decrement()
|
||||
@ -67,7 +57,7 @@ namespace osu.Game.Screens.Play
|
||||
if (!IsCounting)
|
||||
return;
|
||||
|
||||
CountPresses--;
|
||||
countPresses.Value--;
|
||||
}
|
||||
|
||||
protected virtual void LightUp(bool increment = true)
|
||||
|
Loading…
x
Reference in New Issue
Block a user