mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 17:47:29 +08:00
Merge pull request #18345 from frenzibyte/bpm-display-rounding-fix
Fix song select potentially displaying BPM range with equal min/max values
This commit is contained in:
commit
98e5bbd4f9
@ -2,7 +2,6 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
@ -127,6 +126,12 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
AddAssert("check info labels count", () => infoWedge.Info.ChildrenOfType<BeatmapInfoWedge.WedgeInfoText.InfoLabel>().Count() == expectedCount);
|
AddAssert("check info labels count", () => infoWedge.Info.ChildrenOfType<BeatmapInfoWedge.WedgeInfoText.InfoLabel>().Count() == expectedCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[SetUpSteps]
|
||||||
|
public void SetUpSteps()
|
||||||
|
{
|
||||||
|
AddStep("reset mods", () => SelectedMods.SetDefault());
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestNullBeatmap()
|
public void TestNullBeatmap()
|
||||||
{
|
{
|
||||||
@ -147,24 +152,48 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestBPMUpdates()
|
public void TestBPMUpdates()
|
||||||
{
|
{
|
||||||
const float bpm = 120;
|
const double bpm = 120;
|
||||||
IBeatmap beatmap = createTestBeatmap(new OsuRuleset().RulesetInfo);
|
IBeatmap beatmap = createTestBeatmap(new OsuRuleset().RulesetInfo);
|
||||||
beatmap.ControlPointInfo.Add(0, new TimingControlPoint { BeatLength = 60 * 1000 / bpm });
|
beatmap.ControlPointInfo.Add(0, new TimingControlPoint { BeatLength = 60 * 1000 / bpm });
|
||||||
|
|
||||||
OsuModDoubleTime doubleTime = null;
|
OsuModDoubleTime doubleTime = null;
|
||||||
|
|
||||||
selectBeatmap(beatmap);
|
selectBeatmap(beatmap);
|
||||||
checkDisplayedBPM(bpm);
|
checkDisplayedBPM($"{bpm}");
|
||||||
|
|
||||||
AddStep("select DT", () => SelectedMods.Value = new[] { doubleTime = new OsuModDoubleTime() });
|
AddStep("select DT", () => SelectedMods.Value = new[] { doubleTime = new OsuModDoubleTime() });
|
||||||
checkDisplayedBPM(bpm * 1.5f);
|
checkDisplayedBPM($"{bpm * 1.5f}");
|
||||||
|
|
||||||
AddStep("change DT rate", () => doubleTime.SpeedChange.Value = 2);
|
AddStep("change DT rate", () => doubleTime.SpeedChange.Value = 2);
|
||||||
checkDisplayedBPM(bpm * 2);
|
checkDisplayedBPM($"{bpm * 2}");
|
||||||
|
}
|
||||||
|
|
||||||
void checkDisplayedBPM(float target) =>
|
[TestCase(120, 125, null, "120-125 (mostly 120)")]
|
||||||
AddUntilStep($"displayed bpm is {target}", () => this.ChildrenOfType<BeatmapInfoWedge.WedgeInfoText.InfoLabel>().Any(
|
[TestCase(120, 120.6, null, "120-121 (mostly 120)")]
|
||||||
label => label.Statistic.Name == "BPM" && label.Statistic.Content == target.ToString(CultureInfo.InvariantCulture)));
|
[TestCase(120, 120.4, null, "120")]
|
||||||
|
[TestCase(120, 120.6, "DT", "180-182 (mostly 180)")]
|
||||||
|
[TestCase(120, 120.4, "DT", "180")]
|
||||||
|
public void TestVaryingBPM(double commonBpm, double otherBpm, string mod, string expectedDisplay)
|
||||||
|
{
|
||||||
|
IBeatmap beatmap = createTestBeatmap(new OsuRuleset().RulesetInfo);
|
||||||
|
beatmap.ControlPointInfo.Add(0, new TimingControlPoint { BeatLength = 60 * 1000 / commonBpm });
|
||||||
|
beatmap.ControlPointInfo.Add(100, new TimingControlPoint { BeatLength = 60 * 1000 / otherBpm });
|
||||||
|
beatmap.ControlPointInfo.Add(200, new TimingControlPoint { BeatLength = 60 * 1000 / commonBpm });
|
||||||
|
|
||||||
|
if (mod != null)
|
||||||
|
AddStep($"select {mod}", () => SelectedMods.Value = new[] { Ruleset.Value.CreateInstance().CreateModFromAcronym(mod) });
|
||||||
|
|
||||||
|
selectBeatmap(beatmap);
|
||||||
|
checkDisplayedBPM(expectedDisplay);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkDisplayedBPM(string target)
|
||||||
|
{
|
||||||
|
AddUntilStep($"displayed bpm is {target}", () =>
|
||||||
|
{
|
||||||
|
var label = infoWedge.DisplayedContent.ChildrenOfType<BeatmapInfoWedge.WedgeInfoText.InfoLabel>().Single(l => l.Statistic.Name == "BPM");
|
||||||
|
return label.Statistic.Content == target;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setRuleset(RulesetInfo rulesetInfo)
|
private void setRuleset(RulesetInfo rulesetInfo)
|
||||||
|
@ -12,7 +12,6 @@ using osu.Framework.Bindables;
|
|||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Utils;
|
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Beatmaps.Drawables;
|
using osu.Game.Beatmaps.Drawables;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
@ -416,13 +415,13 @@ namespace osu.Game.Screens.Select
|
|||||||
foreach (var mod in mods.Value.OfType<IApplicableToRate>())
|
foreach (var mod in mods.Value.OfType<IApplicableToRate>())
|
||||||
rate = mod.ApplyToRate(0, rate);
|
rate = mod.ApplyToRate(0, rate);
|
||||||
|
|
||||||
double bpmMax = beatmap.ControlPointInfo.BPMMaximum * rate;
|
int bpmMax = (int)Math.Round(Math.Round(beatmap.ControlPointInfo.BPMMaximum) * rate);
|
||||||
double bpmMin = beatmap.ControlPointInfo.BPMMinimum * rate;
|
int bpmMin = (int)Math.Round(Math.Round(beatmap.ControlPointInfo.BPMMinimum) * rate);
|
||||||
double mostCommonBPM = 60000 / beatmap.GetMostCommonBeatLength() * rate;
|
int mostCommonBPM = (int)Math.Round(Math.Round(60000 / beatmap.GetMostCommonBeatLength()) * rate);
|
||||||
|
|
||||||
string labelText = Precision.AlmostEquals(bpmMin, bpmMax)
|
string labelText = bpmMin == bpmMax
|
||||||
? $"{bpmMin:0}"
|
? $"{bpmMin}"
|
||||||
: $"{bpmMin:0}-{bpmMax:0} (mostly {mostCommonBPM:0})";
|
: $"{bpmMin}-{bpmMax} (mostly {mostCommonBPM})";
|
||||||
|
|
||||||
bpmLabelContainer.Child = new InfoLabel(new BeatmapStatistic
|
bpmLabelContainer.Child = new InfoLabel(new BeatmapStatistic
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user