Fix calibrating offset from previous non-zero offset not applying adjustment correctly

This commit is contained in:
Dean Herbert 2022-03-04 12:55:35 +09:00
parent 6be031471e
commit e9e92b991e
2 changed files with 33 additions and 3 deletions

View File

@ -48,7 +48,7 @@ namespace osu.Game.Tests.Visual.Gameplay
}
[Test]
public void TestDisplay()
public void TestCalibrationFromZero()
{
const double average_error = -4.5;
@ -70,5 +70,33 @@ namespace osu.Game.Tests.Visual.Gameplay
AddStep("Remove reference score", () => offsetControl.ReferenceScore.Value = null);
AddAssert("No calibration button", () => !offsetControl.ChildrenOfType<SettingsButton>().Any());
}
/// <summary>
/// When a beatmap offset was already set, the calibration should take it into account.
/// </summary>
[Test]
public void TestCalibrationFromNonZero()
{
const double average_error = -4.5;
const double initial_offset = -2;
AddStep("Set offset non-neutral", () => offsetControl.Current.Value = initial_offset);
AddAssert("No calibration button", () => !offsetControl.ChildrenOfType<SettingsButton>().Any());
AddStep("Set reference score", () =>
{
offsetControl.ReferenceScore.Value = new ScoreInfo
{
HitEvents = TestSceneHitEventTimingDistributionGraph.CreateDistributedHitEvents(average_error)
};
});
AddAssert("Has calibration button", () => offsetControl.ChildrenOfType<SettingsButton>().Any());
AddStep("Press button", () => offsetControl.ChildrenOfType<SettingsButton>().Single().TriggerClick());
AddAssert("Offset is adjusted", () => offsetControl.Current.Value == initial_offset - average_error);
AddAssert("Button is disabled", () => !offsetControl.ChildrenOfType<SettingsButton>().Single().Enabled.Value);
AddStep("Remove reference score", () => offsetControl.ReferenceScore.Value = null);
AddAssert("No calibration button", () => !offsetControl.ChildrenOfType<SettingsButton>().Any());
}
}
}

View File

@ -51,6 +51,7 @@ namespace osu.Game.Screens.Play.PlayerSettings
private OsuColour colours { get; set; } = null!;
private double lastPlayAverage;
private double lastPlayBeatmapOffset;
private SettingsButton? useAverageButton;
@ -130,7 +131,7 @@ namespace osu.Game.Screens.Play.PlayerSettings
}
if (useAverageButton != null)
useAverageButton.Enabled.Value = !Precision.AlmostEquals(lastPlayAverage, -Current.Value, Current.Precision / 2);
useAverageButton.Enabled.Value = !Precision.AlmostEquals(lastPlayAverage, -Current.Value + lastPlayBeatmapOffset, Current.Precision / 2);
realmWriteTask = realm.WriteAsync(r =>
{
@ -187,6 +188,7 @@ namespace osu.Game.Screens.Play.PlayerSettings
}
lastPlayAverage = average;
lastPlayBeatmapOffset = Current.Value;
referenceScoreContainer.AddRange(new Drawable[]
{
@ -199,7 +201,7 @@ namespace osu.Game.Screens.Play.PlayerSettings
useAverageButton = new SettingsButton
{
Text = BeatmapOffsetControlStrings.CalibrateUsingLastPlay,
Action = () => Current.Value = -lastPlayAverage
Action = () => Current.Value = lastPlayBeatmapOffset - lastPlayAverage
},
});
}