pub(crate) const VSYNC_OPTIONS: [&str; 2] = ["Off", "On"];
pub const OFF_ON_OPTIONS: [&str; 2] = ["Off", "On"];
pub const QUALITY_TOGGLE_KEYS: [&str; 5] = [
"ssao",
"ssr",
"ray_traced_reflections",
"ssgi",
"auto_exposure",
];
pub fn is_quality_toggle(key: &str) -> bool {
QUALITY_TOGGLE_KEYS.contains(&key)
}
pub const WINDOW_MODE_OPTIONS: [&str; 3] = ["Windowed", "Borderless", "Fullscreen"];
pub(crate) const RENDER_SCALE_OPTIONS: [&str; 4] = ["Quality", "Balanced", "Performance", "Ultra"];
pub const UPSCALE_BACKEND_OPTIONS: [&str; 4] = ["Auto", "FSR 3", "DLSS", "XeSS"];
pub(crate) const FPS_CAP_OPTIONS: [&str; 6] = ["Unlimited", "30", "60", "120", "144", "240"];
pub const SSGI_RESOLUTION_OPTIONS: [&str; 3] = ["Full", "Half", "Quarter"];
pub(crate) const SSGI_RAYS_OPTIONS: [&str; 4] = ["4", "8", "16", "32"];
pub(crate) const SSGI_STEPS_OPTIONS: [&str; 4] = ["8", "12", "24", "48"];
pub const REFLECTION_BLUR_OPTIONS: [&str; 3] = ["Full", "Half", "Quarter"];
pub const AA_MODE_OPTIONS: [&str; 3] = ["Off", "FXAA", "TAA"];
pub(crate) const SHADOW_RESOLUTION_OPTIONS: [&str; 4] = ["Off", "1024", "2048", "4096"];
pub const SHADOW_UPDATE_OPTIONS: [&str; 2] = ["Every Frame", "Hybrid"];
pub(crate) const SHADOW_DISTANCE_OPTIONS: [&str; 4] = ["40 m", "80 m", "160 m", "320 m"];
pub(crate) const SHADOW_CASCADES_OPTIONS: [&str; 3] = ["2", "3", "4"];
pub(crate) const ANISOTROPY_OPTIONS: [&str; 5] = ["Off", "2x", "4x", "8x", "16x"];
pub const FRAME_BUFFERING_OPTIONS: [&str; 3] = ["1", "2", "3"];
pub(crate) const TEXTURE_QUALITY_OPTIONS: [&str; 4] = ["Low", "Medium", "High", "Ultra"];
pub const GRAPHICS_QUALITY_OPTIONS: [&str; 6] =
["Auto", "Low", "Medium", "High", "Ultra", "Custom"];
pub(crate) const VOLUME_OPTIONS: [&str; 5] = ["Off", "25%", "50%", "75%", "100%"];
pub(crate) const DYNAMIC_DROPDOWN_KEYS: [&str; 1] = ["resolution"];
pub fn is_dynamic_dropdown(key: &str) -> bool {
DYNAMIC_DROPDOWN_KEYS.contains(&key)
}
pub fn options(key: &str) -> Option<&'static [&'static str]> {
match key {
"graphics_quality" => Some(&GRAPHICS_QUALITY_OPTIONS),
"vsync" => Some(&VSYNC_OPTIONS),
"window_mode" => Some(&WINDOW_MODE_OPTIONS),
"render_scale" => Some(&RENDER_SCALE_OPTIONS),
"upscale_backend" => Some(&UPSCALE_BACKEND_OPTIONS),
"fps_cap" => Some(&FPS_CAP_OPTIONS),
"master_volume" | "music_volume" | "sfx_volume" | "voice_volume" => Some(&VOLUME_OPTIONS),
"aa_mode" => Some(&AA_MODE_OPTIONS),
"ssgi_resolution" => Some(&SSGI_RESOLUTION_OPTIONS),
"ssgi_rays" => Some(&SSGI_RAYS_OPTIONS),
"ssgi_steps" => Some(&SSGI_STEPS_OPTIONS),
"reflection_blur_resolution" => Some(&REFLECTION_BLUR_OPTIONS),
"shadow_map_size" => Some(&SHADOW_RESOLUTION_OPTIONS),
"shadow_update" => Some(&SHADOW_UPDATE_OPTIONS),
"shadow_distance" => Some(&SHADOW_DISTANCE_OPTIONS),
"shadow_cascades" => Some(&SHADOW_CASCADES_OPTIONS),
"anisotropy" => Some(&ANISOTROPY_OPTIONS),
"frames_in_flight" => Some(&FRAME_BUFFERING_OPTIONS),
"texture_quality" => Some(&TEXTURE_QUALITY_OPTIONS),
"temporal_upscaling" | "hdr_display" | "hdr_pq" | "occlusion_two_pass" => {
Some(&OFF_ON_OPTIONS)
}
"perf_stats" | "show_fps" | "show_vram" => Some(&OFF_ON_OPTIONS),
key if is_quality_toggle(key) => Some(&OFF_ON_OPTIONS),
_ => None,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn resolution_is_a_dynamic_dropdown_with_no_static_options() {
assert!(is_dynamic_dropdown("resolution"));
assert!(options("resolution").is_none());
assert!(!is_dynamic_dropdown("window_mode"));
assert!(!is_dynamic_dropdown("nope"));
}
#[test]
fn quality_toggles_are_off_then_on() {
for key in QUALITY_TOGGLE_KEYS {
assert!(is_quality_toggle(key), "{key} should classify as a toggle");
assert_eq!(options(key), Some(&["Off", "On"][..]), "{key} options");
}
assert!(!is_quality_toggle("vsync"));
assert!(!is_quality_toggle("nope"));
}
#[test]
fn unknown_key_has_no_options() {
assert!(options("does_not_exist").is_none());
}
#[test]
fn multi_option_settings_are_dropdowns_and_toggles_are_steppers() {
for key in [
"graphics_quality",
"window_mode",
"render_scale",
"fps_cap",
"master_volume",
"aa_mode",
"shadow_map_size",
"anisotropy",
] {
assert!(
options(key).unwrap().len() > 2,
"{key} should be a dropdown"
);
}
for key in ["vsync", "shadow_update", "temporal_upscaling", "ssao"] {
assert_eq!(options(key).unwrap().len(), 2, "{key} should be a stepper");
}
}
}