fix(settings): the move to the standard mode puts the render scale back with the frame buffer

The row of the render scale, which only the advanced mode shows, has the keys of the frame buffer's size, while the scale itself is read from starter.bufferscale: put back without it, the two came out as they were, and a player moved to the standard mode kept a blurred picture with no setting for it on the screen. The percent now goes wherever the buffer's size does, on the move, on leaving the advanced mode and on a section put back.
This commit is contained in:
maj00r
2026-11-22 14:51:59 +01:00
parent 77b0c23cea
commit f7a58e8431
3 changed files with 40 additions and 0 deletions

View File

@@ -1246,6 +1246,28 @@ public class SettingsStoreTests
Assert.Equal(60, store.Settings.FieldOfView);
}
// The move to the standard mode puts back the keys of the rows it hides: the row of the
// render scale has the frame buffer's two, and the percent it is worked out from is the starter's own.
[Theory]
[InlineData("width 1920\nheight 1080\nstarter.bufferscale 50\ngfx.framebuffer.width 960\ngfx.framebuffer.height 540\n")]
[InlineData("width 1920\nheight 1080\ngfx.framebuffer.width 960\ngfx.framebuffer.height 540\n")]
public void The_frame_buffer_put_back_takes_the_render_scale_with_it(string ini)
{
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, ini));
var store = installation.SettingsStore;
store.Load();
Assert.Equal(50, store.Settings.BufferScalePercent);
var reset = store.WithDefaults(store.Settings, new[] { "gfx.framebuffer.width", "gfx.framebuffer.height" });
Assert.Equal(100, reset.BufferScalePercent);
Assert.Equal(1920, reset.Width);
var written = store.Render(reset);
Assert.Equal("100", written["starter.bufferscale"]);
Assert.Equal("1920", written["gfx.framebuffer.width"]);
Assert.Equal("1080", written["gfx.framebuffer.height"]);
}
// ── What the screen shows otherwise ──────────────────────────────────────
[Fact]

View File

@@ -529,6 +529,7 @@ public sealed class SettingsStore
/// <summary>A copy of <paramref name="settings"/> with <paramref name="keys"/> as <paramref name="source"/> has them.</summary>
public SimulatorSettings WithKeysOf(SimulatorSettings settings, SimulatorSettings source, IReadOnlyCollection<string> keys)
{
keys = SettingsSerializer.WithCompanions(keys);
var taken = Render(source);
var config = new ConfigFile();

View File

@@ -379,6 +379,23 @@ public sealed class SettingsSerializer
c.Set(key.Key, value.Trim());
}
/// <summary>The keys of the frame buffer's size.</summary>
public static readonly string[] FramebufferKeys = { "gfx.framebuffer.width", "gfx.framebuffer.height" };
/// <summary>
/// <paramref name="keys"/> with the keys that say the same setting along with them: the
/// starter's own percent goes wherever the frame buffer's size does, or it would stand
/// when the size is put back.
/// </summary>
public static IReadOnlyCollection<string> WithCompanions(IReadOnlyCollection<string> keys)
{
if (!keys.Intersect(FramebufferKeys, StringComparer.OrdinalIgnoreCase).Any())
return keys;
var all = new HashSet<string>(keys, StringComparer.OrdinalIgnoreCase) { "starter.bufferscale" };
all.UnionWith(FramebufferKeys);
return all;
}
private static int ReadBufferScale(ConfigFile c) =>
Clamp(BufferScaleIn(c), 25, GraphicsRules.MaxBufferScale);