// The game's in-game Options (gpu/vk/vk_menu.cpp, the Row table) as plain data for the launcher: one GameOptionRow per row the // game shows with a value, with its tab, section, name, key, range, default, help and the labels its value shows. // GameOptionsSchema.All lists them; GameOptionsFile reads and writes the file the way the game does. ((Triforce, options_version // 8) A merged row (HDR, Frame generation, Frame pacing, Low latency: gpu/vk/merged_rows.h) has no line of its own: it is a view // of two saved values, its Parts, each kept under its own key as before.) namespace Triforce.Logic; /// The Options screen's tabs, as the game's header shows them. (The game's Debug tab is not ported: its rows' /// keys are kept in the file as they are, GameOptionsSchema.KeptKeys.) public enum GameOptionTab { Display, Graphics, Audio, Controls, System } /// Choice: a few values, each with a label (toggles and lists). Slider: a numeric range on steps (volume, nits, /// percent, sensitivity), each value labelled by its unit (Label). public enum GameOptionKind { Choice, Slider } /// One value of a row and the text the game's menu shows for it. public sealed record GameOptionChoice(int Value, string Label); /// The values of the other rows, for the labels that depend on them (the Render resolution's sizes follow the /// Upscaler and the Output resolution; the Anti-aliasing row shows the upscaler's own while one draws; the Microphone shows /// the saved device's name). GameOptionsFile is one. public interface IGameOptionValues { /// A row's value as the game reads it (its default when the file has no line). int Get(string key); /// A line's value as the file has it, null when it has no such line. string? Raw(string key); } /// ((Triforce, options_version 8) A saved value that a merged row stands for (vk_menu.cpp's TAB_HIDDEN rows): its key /// in triforce_options.ini, its range and default (vk_menu.h Options), and its own value's label (the hidden row's tx_*). public sealed record GameOptionPart(string Key, int Lo, int Hi, int Default, Func Label) { /// A value as the game reads it from the file: inside Lo..Hi. public int AsRead(int value) => Math.Clamp(value, Lo, Hi); } /// A merged row's rules (merged_rows.h): its value from its parts' (Of), and its parts' from a new value of it and /// their values now (Split). public sealed record GameOptionMerge(Func Of, Func Split); /// A row of the game's Options menu that has a value in triforce_options.ini (its own line, or its Parts' lines). public sealed record GameOptionRow { /// The tab it is on. The Motion page's rows and the Controls page's Button prompts are on Controls, in /// the sections "Motion" and "Controls" (the rows that open those pages). public required GameOptionTab Tab { get; init; } /// The heading above it on its tab (the menu's MENU_HEADING rows), null where the tab has none. public required string? Section { get; init; } /// The row's name, exactly as the menu shows it. public required string Name { get; init; } /// Its key in triforce_options.ini (vk_menu.cpp ini_key). A merged row has no line: its key here starts with '@' /// and is the launcher's alone (its values are its Parts' keys). public required string Key { get; init; } public required int Lo { get; init; } public required int Hi { get; init; } public required int Step { get; init; } readonly int dflt; /// The game's default (vk_menu.h Options): the value when the file has no line for it. A merged row's: the view /// of its parts' defaults (Low latency's follows the card's maker). public int Default { get => Merge != null ? Merge.Of(Parts!.Select(p => p.Default).ToArray()) : dflt; init => dflt = value; } public required GameOptionKind Kind { get; init; } /// The help under the list while the row is selected, exactly the menu's. public required string Help { get; init; } /// Read once at the game's start: a change applies after a restart (the menu tags it "After restart"). public required bool Restart { get; init; } /// The table's preset_exempt flag. (Triforce, options_version 8) The Quality preset is gone and nothing reads it; /// the rows keep their shape, so the flag is kept as the table has it. public required bool PresetExempt { get; init; } /// A merged row's saved values, in merged_rows.h's order (null for a row with a line of its own). public IReadOnlyList? Parts { get; init; } /// A merged row's rules (null for a row with a line of its own). public GameOptionMerge? Merge { get; init; } /// A merged row: a view of its Parts, no line of its own. public bool IsMerged => Merge != null; internal Func Format { get; init; } = (v, _) => v.ToString(System.Globalization.CultureInfo.InvariantCulture); internal Func>? ChoiceList { get; init; } /// The values a Choice row offers, in the menu's order, with their labels as the menu shows them where nothing /// is known of this PC (fps cap 6 "Monitor's rate", GPU device from GameOptionsSchema.GpuNames). Empty for a Slider. /// GameOptionsFile.ChoicesOf has the ones that follow the file's other rows (the Upscaler, the Render resolution). public IReadOnlyList Choices => ChoiceList?.Invoke() ?? Array.Empty(); /// The label of a value, as the menu shows it with the other rows at their defaults. public string Label(int value) => Format(value, null); /// The label of a value with the other rows as values has them. public string Label(int value, IGameOptionValues? values) => Format(value, values); /// A value as the launcher may set it: inside Lo..Hi, on the row's steps from Lo (the nearest, the larger on a /// tie). The Output resolution's values past its list are its first, as the game reads them. public int Clamp(int value) { if (Key == GameOptionsSchema.OutputResKey) return value >= Lo && value <= Hi ? value : 0; var v = Math.Clamp(value, Lo, Hi); if (Step > 1) { var k = (v - Lo + Step / 2) / Step; v = Math.Min(Lo + k * Step, Hi); } return v; } /// A value as the game reads it from the file (menu_init): inside Lo..Hi, not moved onto the steps (a hand-edited /// 125 stays 125), except the Rumble strength (the nearest 25) and the Output resolution (past its list: its first). public int AsRead(int value) { if (Key == GameOptionsSchema.OutputResKey) return value >= Lo && value <= Hi ? value : 0; var v = Math.Clamp(value, Lo, Hi); if (Key == GameOptionsSchema.RumbleKey) v = (Math.Clamp(v, 0, 300) + 12) / 25 * 25; return v; } }