mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-23 00:24:41 +01:00
fix(settings): the cursor's speed is read and written as the old starter did, its four levels
The old starter (src/uSettings.pas) showed a mousescale as one of four levels - low below 1.3, high above 1.9, very high above 2.7, standard between - and wrote 1.0, 1.5, 2.3 or 3.2 for them, with 0.5 after it, the signs being the inversions. The slider had three whole steps instead, so a 3.2 was the top only by rounding and anything above 3 was cut to 3 on the move to the standard mode.
This commit is contained in:
@@ -492,10 +492,8 @@ public class SettingsStoreTests
|
|||||||
[InlineData("mousescale 1.5 0.5", false, true, "mousescale 1.5 -0.5")]
|
[InlineData("mousescale 1.5 0.5", false, true, "mousescale 1.5 -0.5")]
|
||||||
[InlineData("mousescale 1.5 0.5", true, false, "mousescale -1.5 0.5")]
|
[InlineData("mousescale 1.5 0.5", true, false, "mousescale -1.5 0.5")]
|
||||||
[InlineData("mousescale -1.5 -0.5", false, false, "mousescale 1.5 0.5")]
|
[InlineData("mousescale -1.5 -0.5", false, false, "mousescale 1.5 0.5")]
|
||||||
[InlineData("mousescale 2.5 0.5", false, true, "mousescale 2.5 -0.5")]
|
[InlineData("mousescale 3.2 0.5", true, true, "mousescale -3.2 -0.5")]
|
||||||
// Further than the slider goes.
|
public void An_inverted_axis_is_the_sign_of_its_number(
|
||||||
[InlineData("mousescale 12 0.5", true, false, "mousescale -12 0.5")]
|
|
||||||
public void A_mouse_scale_keeps_its_numbers_when_an_axis_is_inverted(
|
|
||||||
string line, bool invertX, bool invertY, string written)
|
string line, bool invertX, bool invertY, string written)
|
||||||
{
|
{
|
||||||
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, line + "\n"));
|
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, line + "\n"));
|
||||||
@@ -508,10 +506,69 @@ public class SettingsStoreTests
|
|||||||
Assert.Equal(written, LineFor(installation, "mousescale"));
|
Assert.Equal(written, LineFor(installation, "mousescale"));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Theory]
|
||||||
public void A_mouse_scale_nobody_changed_stays_as_the_file_has_it()
|
[InlineData("mousescale 1.0 0.5")]
|
||||||
|
[InlineData("mousescale 1 0.5")]
|
||||||
|
[InlineData("mousescale 1.5 0.5")]
|
||||||
|
[InlineData("mousescale -2.3 0.5")]
|
||||||
|
[InlineData("mousescale 3.2 -0.5")]
|
||||||
|
public void A_mouse_scale_of_the_old_starter_stays_as_the_file_has_it(string line)
|
||||||
{
|
{
|
||||||
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, "mousescale 1.5 0.5\n"));
|
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, line + "\n"));
|
||||||
|
installation.SettingsStore.Load();
|
||||||
|
|
||||||
|
installation.SettingsStore.Save();
|
||||||
|
|
||||||
|
Assert.Equal(line, LineFor(installation, "mousescale"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
// The old starter's four speeds (src/uSettings.pas): low, standard, high, very high.
|
||||||
|
[InlineData(1, "mousescale 1.0 0.5")]
|
||||||
|
[InlineData(2, "mousescale 1.5 0.5")]
|
||||||
|
[InlineData(3, "mousescale 2.3 0.5")]
|
||||||
|
[InlineData(4, "mousescale 3.2 0.5")]
|
||||||
|
public void The_sensitivity_is_written_as_the_old_starter_wrote_it(int level, string written)
|
||||||
|
{
|
||||||
|
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, "mousescale 12 0.5\n"));
|
||||||
|
installation.SettingsStore.Load();
|
||||||
|
installation.SettingsStore.Settings.CursorSensitivity = level;
|
||||||
|
|
||||||
|
installation.SettingsStore.Save();
|
||||||
|
|
||||||
|
Assert.Equal(written, LineFor(installation, "mousescale"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
// Low below 1.3, high above 1.9, very high above 2.7, standard between - whatever the sign.
|
||||||
|
[InlineData("0", 1)]
|
||||||
|
[InlineData("0.2", 1)]
|
||||||
|
[InlineData("1.29", 1)]
|
||||||
|
[InlineData("1.3", 2)]
|
||||||
|
[InlineData("1.5", 2)]
|
||||||
|
[InlineData("1.9", 2)]
|
||||||
|
[InlineData("2", 3)]
|
||||||
|
[InlineData("-2.3", 3)]
|
||||||
|
[InlineData("2.7", 3)]
|
||||||
|
[InlineData("3", 4)]
|
||||||
|
[InlineData("-3.2", 4)]
|
||||||
|
[InlineData("12", 4)]
|
||||||
|
// Not a number the old starter could read: its list stayed at standard.
|
||||||
|
[InlineData("Infinity", 2)]
|
||||||
|
[InlineData("fast", 2)]
|
||||||
|
public void The_sensitivity_is_read_as_the_old_starter_read_it(string x, int level)
|
||||||
|
{
|
||||||
|
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, $"mousescale {x} 0.5\n"));
|
||||||
|
|
||||||
|
installation.SettingsStore.Load();
|
||||||
|
|
||||||
|
Assert.Equal(level, installation.SettingsStore.Settings.CursorSensitivity);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Without_a_mouse_scale_the_old_starters_standard_is_written()
|
||||||
|
{
|
||||||
|
var installation = WithHome();
|
||||||
installation.SettingsStore.Load();
|
installation.SettingsStore.Load();
|
||||||
|
|
||||||
installation.SettingsStore.Save();
|
installation.SettingsStore.Save();
|
||||||
@@ -519,49 +576,28 @@ public class SettingsStoreTests
|
|||||||
Assert.Equal("mousescale 1.5 0.5", LineFor(installation, "mousescale"));
|
Assert.Equal("mousescale 1.5 0.5", LineFor(installation, "mousescale"));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void Moving_the_sensitivity_replaces_the_scale_it_stood_for()
|
|
||||||
{
|
|
||||||
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, "mousescale 1.5 0.5\n"));
|
|
||||||
installation.SettingsStore.Load();
|
|
||||||
Assert.Equal(2, installation.SettingsStore.Settings.CursorSensitivity);
|
|
||||||
installation.SettingsStore.Settings.CursorSensitivity = 3;
|
|
||||||
|
|
||||||
installation.SettingsStore.Save();
|
|
||||||
|
|
||||||
Assert.Equal("mousescale 3 0.5", LineFor(installation, "mousescale"));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void The_default_mouse_scale_is_written_as_before()
|
|
||||||
{
|
|
||||||
var installation = WithHome();
|
|
||||||
installation.SettingsStore.Load();
|
|
||||||
|
|
||||||
installation.SettingsStore.Save();
|
|
||||||
|
|
||||||
Assert.Equal("mousescale 2 0.5", LineFor(installation, "mousescale"));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
// The second number is always 0.5, as the old starter wrote it; its sign is the inversion.
|
// The second number is always 0.5, as the old starter wrote it; its sign is the inversion.
|
||||||
|
[InlineData("mousescale 1.5 0.2", "mousescale 1.5 0.5")]
|
||||||
[InlineData("mousescale 1.5 0.23", "mousescale 1.5 0.5")]
|
[InlineData("mousescale 1.5 0.23", "mousescale 1.5 0.5")]
|
||||||
[InlineData("mousescale 1.5 -0.23", "mousescale 1.5 -0.5")]
|
[InlineData("mousescale 1.5 -0.23", "mousescale 1.5 -0.5")]
|
||||||
[InlineData("mousescale 1.5 -2", "mousescale 1.5 -0.5")]
|
[InlineData("mousescale 1.5 -2", "mousescale 1.5 -0.5")]
|
||||||
// A zero locks that axis in the simulator: the camera turns only left/right.
|
[InlineData("mousescale 1.5 0", "mousescale 1.5 0.5")]
|
||||||
// X goes back to the default.
|
[InlineData("mousescale 1.5 -0", "mousescale 1.5 0.5")]
|
||||||
[InlineData("mousescale 0.5 0", "mousescale 0.5 0.5")]
|
|
||||||
[InlineData("mousescale 0.5 -0", "mousescale 0.5 0.5")]
|
|
||||||
[InlineData("mousescale 0 0.5", "mousescale 2 0.5")]
|
|
||||||
[InlineData("mousescale 0 0", "mousescale 2 0.5")]
|
|
||||||
[InlineData("mousescale 1.5 NaN", "mousescale 1.5 0.5")]
|
[InlineData("mousescale 1.5 NaN", "mousescale 1.5 0.5")]
|
||||||
[InlineData("mousescale Infinity -0.5", "mousescale 2 -0.5")]
|
// A decimal comma: the simulator reads "0,2" as 0.
|
||||||
|
[InlineData("mousescale 1.5 0,2", "mousescale 1.5 0.5")]
|
||||||
|
// The first is one of that starter's four speeds, the one of the level the file's number has.
|
||||||
|
[InlineData("mousescale 0.5 0.5", "mousescale 1.0 0.5")]
|
||||||
|
[InlineData("mousescale 0 0.5", "mousescale 1.0 0.5")]
|
||||||
|
[InlineData("mousescale 2 0.5", "mousescale 2.3 0.5")]
|
||||||
|
[InlineData("mousescale -3 0.5", "mousescale -3.2 0.5")]
|
||||||
|
[InlineData("mousescale 12 0.2", "mousescale 3.2 0.5")]
|
||||||
|
[InlineData("mousescale Infinity -0.5", "mousescale 1.5 -0.5")]
|
||||||
// One number: the simulator takes the next word of the file ("mousecontrol") for Y, and reads it as 0.
|
// One number: the simulator takes the next word of the file ("mousecontrol") for Y, and reads it as 0.
|
||||||
[InlineData("mousescale 1.5", "mousescale 1.5 0.5")]
|
[InlineData("mousescale 1.5", "mousescale 1.5 0.5")]
|
||||||
[InlineData("mousescale 0.5\t// (3.2 0.5) komentarz", "mousescale 0.5 0.5\t// (3.2 0.5) komentarz")]
|
[InlineData("mousescale 0.5\t// (3.2 0.5) komentarz", "mousescale 1.0 0.5\t// (3.2 0.5) komentarz")]
|
||||||
// A decimal comma: the simulator reads "0,2" as 0.
|
public void A_mouse_scale_the_old_starter_would_not_write_goes_on_a_save(string line, string written)
|
||||||
[InlineData("mousescale 0.5 0,2", "mousescale 0.5 0.5")]
|
|
||||||
public void A_mouse_scale_axis_that_would_not_move_gets_the_default(string line, string written)
|
|
||||||
{
|
{
|
||||||
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, line + "\n"));
|
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, line + "\n"));
|
||||||
installation.SettingsStore.Load();
|
installation.SettingsStore.Load();
|
||||||
|
|||||||
@@ -230,10 +230,25 @@ public sealed class SimulatorSettings
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The file's own first mousescale number. The slider takes whole steps: this
|
/// The first mousescale number of each level of <see cref="CursorSensitivity"/>, 1 to 4, as
|
||||||
/// stands for as long as <see cref="CursorSensitivity"/> is the step nearest it.
|
/// the old starter wrote them (MaSzyna-EU07/Starter, src/uSettings.pas): low, standard, high
|
||||||
|
/// and very high, negative with <see cref="InvertMouseHorizontal"/>. Whatever else the file
|
||||||
|
/// has there goes on the next save.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal double MouseScaleXMagnitude { get; set; } = 2;
|
internal static readonly double[] MouseScales = { 1.0, 1.5, 2.3, 3.2 };
|
||||||
|
|
||||||
|
/// <summary>The first mousescale number <paramref name="level"/> stands for.</summary>
|
||||||
|
internal static double MouseScaleOf(int level) => MouseScales[Math.Clamp(level, 1, MouseScales.Length) - 1];
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The level the old starter showed for a first mousescale number: low below 1.3, high
|
||||||
|
/// above 1.9, very high above 2.7 and standard between, whatever its sign.
|
||||||
|
/// </summary>
|
||||||
|
internal static int MouseLevelOf(double scale)
|
||||||
|
{
|
||||||
|
double size = Math.Abs(scale);
|
||||||
|
return size > 2.7 ? 4 : size > 1.9 ? 3 : size < 1.3 ? 1 : 2;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The second mousescale number, as the old starter always wrote it: 0.5, or
|
/// The second mousescale number, as the old starter always wrote it: 0.5, or
|
||||||
|
|||||||
@@ -16,9 +16,6 @@ public static class SliderRanges
|
|||||||
/// <summary>dynamiclights: 1 to 7.</summary>
|
/// <summary>dynamiclights: 1 to 7.</summary>
|
||||||
public const int MinDynamicLights = 1;
|
public const int MinDynamicLights = 1;
|
||||||
|
|
||||||
/// <summary>The cursor's speed: its fastest was a mousescale of 3.2.</summary>
|
|
||||||
public const int MaxCursorSensitivity = 3;
|
|
||||||
|
|
||||||
/// <summary>gfx.reflections.framerate, in updates a second.</summary>
|
/// <summary>gfx.reflections.framerate, in updates a second.</summary>
|
||||||
public static readonly double[] ReflectionUpdates = { 1, 3, 10, 25, 60 };
|
public static readonly double[] ReflectionUpdates = { 1, 3, 10, 25, 60 };
|
||||||
|
|
||||||
|
|||||||
@@ -36,16 +36,14 @@ public sealed class SettingsSerializer
|
|||||||
s.FpsAverage = c.GetDouble("fpsaverage", 0);
|
s.FpsAverage = c.GetDouble("fpsaverage", 0);
|
||||||
s.PauseOnStart = c.GetBool("pause", false);
|
s.PauseOnStart = c.GetBool("pause", false);
|
||||||
|
|
||||||
// A zero (or NaN/Infinity) scale locks that axis in the simulator: the
|
// As the old starter read it (src/uSettings.pas): of X its level and its sign, of Y
|
||||||
// camera then turns only one way. Nothing in the starter writes such a
|
// only the sign. Both are written as that starter wrote them, one of its four speeds
|
||||||
// number on purpose, so X takes the default. Of Y only the sign is read:
|
// and 0.5, whatever the file had. A number that cannot be read leaves the standard level.
|
||||||
// it is written 0.5 or -0.5, as the old starter always wrote it.
|
|
||||||
var mouse = c.GetTokens("mousescale");
|
var mouse = c.GetTokens("mousescale");
|
||||||
if (mouse.Length >= 1 && TryParseMouseScale(mouse[0], out double mx))
|
if (mouse.Length >= 1 && TryParseMouseScale(mouse[0], out double mx))
|
||||||
{
|
{
|
||||||
s.InvertMouseHorizontal = mx < 0;
|
s.InvertMouseHorizontal = mx < 0;
|
||||||
s.MouseScaleXMagnitude = Math.Abs(mx);
|
s.CursorSensitivity = SimulatorSettings.MouseLevelOf(mx);
|
||||||
s.CursorSensitivity = SensitivityStep(mx);
|
|
||||||
}
|
}
|
||||||
if (mouse.Length >= 1)
|
if (mouse.Length >= 1)
|
||||||
s.InvertMouseVertical = mouse.Length >= 2 && TryParseMouseScale(mouse[1], out double my) && my < 0;
|
s.InvertMouseVertical = mouse.Length >= 2 && TryParseMouseScale(mouse[1], out double my) && my < 0;
|
||||||
@@ -243,14 +241,11 @@ public sealed class SettingsSerializer
|
|||||||
c.SetBool("inactivepause", s.PauseWhenInactive);
|
c.SetBool("inactivepause", s.PauseWhenInactive);
|
||||||
c.SetBool("pause", s.PauseOnStart);
|
c.SetBool("pause", s.PauseOnStart);
|
||||||
|
|
||||||
double magnitude = SensitivityStep(s.MouseScaleXMagnitude) == s.CursorSensitivity
|
double mx = SimulatorSettings.MouseScaleOf(s.CursorSensitivity) * (s.InvertMouseHorizontal ? -1 : 1);
|
||||||
? s.MouseScaleXMagnitude
|
|
||||||
: s.CursorSensitivity;
|
|
||||||
double mx = magnitude * (s.InvertMouseHorizontal ? -1 : 1);
|
|
||||||
double my = SimulatorSettings.MouseScaleY * (s.InvertMouseVertical ? -1 : 1);
|
double my = SimulatorSettings.MouseScaleY * (s.InvertMouseVertical ? -1 : 1);
|
||||||
c.Set("mousescale",
|
c.Set("mousescale",
|
||||||
$"{mx.ToString("R", CultureInfo.InvariantCulture)} " +
|
$"{mx.ToString("0.0", CultureInfo.InvariantCulture)} " +
|
||||||
$"{my.ToString("R", CultureInfo.InvariantCulture)}");
|
$"{my.ToString("0.0", CultureInfo.InvariantCulture)}");
|
||||||
|
|
||||||
c.SetBool("input.gamepad", !s.IgnoreGamepad);
|
c.SetBool("input.gamepad", !s.IgnoreGamepad);
|
||||||
c.SetInt("feedbackmode", s.FeedbackMode);
|
c.SetInt("feedbackmode", s.FeedbackMode);
|
||||||
@@ -433,25 +428,23 @@ public sealed class SettingsSerializer
|
|||||||
private static int Clamp(int v, int lo, int hi) => v < lo ? lo : (v > hi ? hi : v);
|
private static int Clamp(int v, int lo, int hi) => v < lo ? lo : (v > hi ? hi : v);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether the file's own mousescale can stay as it is: a first number neither
|
/// Whether the file's own mousescale can stay as it is: one of the old starter's four
|
||||||
/// zero nor NaN/Infinity, and 0.5 or -0.5 after it. Otherwise a save writes the
|
/// speeds, and 0.5 or -0.5 after it. Otherwise a save writes the one the starter holds,
|
||||||
/// one the starter holds.
|
/// as every save of the old starter did.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static bool MouseScaleStands(string? raw)
|
public static bool MouseScaleStands(string? raw)
|
||||||
{
|
{
|
||||||
string[] tokens = (raw ?? "").Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
|
string[] tokens = (raw ?? "").Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
|
||||||
return tokens.Length >= 2 &&
|
return tokens.Length >= 2 &&
|
||||||
TryParseMouseScale(tokens[0], out _) &&
|
TryParseMouseScale(tokens[0], out double x) &&
|
||||||
|
Math.Abs(Math.Abs(x) - SimulatorSettings.MouseScaleOf(SimulatorSettings.MouseLevelOf(x))) < 1e-9 &&
|
||||||
TryParseMouseScale(tokens[1], out double y) &&
|
TryParseMouseScale(tokens[1], out double y) &&
|
||||||
Math.Abs(Math.Abs(y) - SimulatorSettings.MouseScaleY) < 1e-9;
|
Math.Abs(Math.Abs(y) - SimulatorSettings.MouseScaleY) < 1e-9;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool TryParseMouseScale(string token, out double scale) =>
|
private static bool TryParseMouseScale(string token, out double scale) =>
|
||||||
double.TryParse(token, NumberStyles.Float, CultureInfo.InvariantCulture, out scale) &&
|
double.TryParse(token, NumberStyles.Float, CultureInfo.InvariantCulture, out scale) &&
|
||||||
double.IsFinite(scale) && scale != 0;
|
double.IsFinite(scale);
|
||||||
|
|
||||||
private static int SensitivityStep(double mouseScale) =>
|
|
||||||
(int)Math.Clamp(Math.Round(Math.Abs(mouseScale)), 1, 5);
|
|
||||||
private static double ParseDouble(string s, double fallback) =>
|
private static double ParseDouble(string s, double fallback) =>
|
||||||
double.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out double d) ? d : fallback;
|
double.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out double d) ? d : fallback;
|
||||||
|
|
||||||
|
|||||||
@@ -145,8 +145,8 @@
|
|||||||
</ctl:SettingRow>
|
</ctl:SettingRow>
|
||||||
<ctl:SettingRow ConfigKey="mousescale" x:Name="CursorSensitivityRow"
|
<ctl:SettingRow ConfigKey="mousescale" x:Name="CursorSensitivityRow"
|
||||||
Label="{Binding [CursorSensitivity], Source={x:Static starterNg:App.Loc}}">
|
Label="{Binding [CursorSensitivity], Source={x:Static starterNg:App.Loc}}">
|
||||||
<ctl:ReadableSlider x:Name="CursorSensitivitySlider" Minimum="1" Maximum="3" TickFrequency="1"
|
<ctl:ReadableSlider x:Name="CursorSensitivitySlider" Minimum="1" Maximum="4" TickFrequency="1"
|
||||||
IsSnapToTickEnabled="True" Value="3"
|
IsSnapToTickEnabled="True" Value="2"
|
||||||
ValueChanged="QualitySlider_OnValueChanged" />
|
ValueChanged="QualitySlider_OnValueChanged" />
|
||||||
</ctl:SettingRow>
|
</ctl:SettingRow>
|
||||||
<ctl:SettingRow ConfigKey="mousescale">
|
<ctl:SettingRow ConfigKey="mousescale">
|
||||||
|
|||||||
@@ -1766,9 +1766,6 @@ public partial class Settings : UserControl, ISettingsCapture
|
|||||||
DynamicLightsSlider.Minimum = widen
|
DynamicLightsSlider.Minimum = widen
|
||||||
? Math.Min(SliderRanges.MinDynamicLights, s.DynamicLights)
|
? Math.Min(SliderRanges.MinDynamicLights, s.DynamicLights)
|
||||||
: SliderRanges.MinDynamicLights;
|
: SliderRanges.MinDynamicLights;
|
||||||
CursorSensitivitySlider.Maximum = widen
|
|
||||||
? Math.Max(SliderRanges.MaxCursorSensitivity, s.CursorSensitivity)
|
|
||||||
: SliderRanges.MaxCursorSensitivity;
|
|
||||||
foreach (var steps in new[] { _fpsLimit, _reflections, _anisotropy, _drawRangeFactor, _cabShadows })
|
foreach (var steps in new[] { _fpsLimit, _reflections, _anisotropy, _drawRangeFactor, _cabShadows })
|
||||||
steps.Clamps = _clamping;
|
steps.Clamps = _clamping;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user