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