// 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 keeps in triforce_options.ini, 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.
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, the Output resolution and the Handheld profile; 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);
}
/// A row of the game's Options menu that has a value in triforce_options.ini.
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 section rows), null where the tab has none (Audio).
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).
public required string Key { get; init; }
public required int Lo { get; init; }
public required int Hi { get; init; }
public required int Step { get; init; }
/// The game's default (vk_menu.h Options): the value when the file has no line for it.
public required int Default { get; init; }
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; }
/// A change here leaves the Quality preset alone; any other row changed by hand turns it back to Custom.
public required bool PresetExempt { get; init; }
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 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;
}
}