pub struct Preferences {
pub master: f32,
pub buses: [f32; 4],
pub muted: bool,
pub quality: Option<u8>,
pub look: u8,
pub resolution: u8,
pub shadows: u8,
pub lights: u8,
pub adaptive: bool,
}Expand description
Device-local presentation preferences, separate from gameplay control bindings.
Use Self::diff to extract choices relative to defaults and
Self::compose to resolve defaults, user choices and temporary overrides.
Only the resulting complete preferences use the existing version-5 save
format. Unknown document fields are still ignored on read and omitted when
encoding a new save; composition does not retain them.
Fields§
§master: f32§buses: [f32; 4]§muted: bool§quality: Option<u8>§look: u8§resolution: u8Browser framebuffer density: device, 0.75x, 1x, 1.5x, 2x, 3x.
shadows: u8Preset, off, 512 hard, 1024 soft.
lights: u8Preset, off, 2, 4, 8 local lights.
adaptive: boolImplementations§
Source§impl Preferences
impl Preferences
pub fn valid(self) -> bool
Sourcepub fn compose(
self,
layers: &[PreferenceOverrides],
) -> Result<Preferences, SaveError>
pub fn compose( self, layers: &[PreferenceOverrides], ) -> Result<Preferences, SaveError>
Resolve layers in order; the last supplied value for each field wins.
Validates the base and each layer, including values hidden by later
layers. Returns SaveError::InvalidData for any invalid input. Nothing
is mutated on success or failure. Uses constant storage, with no heap
allocation, and work proportional to the supplied slice length.
Keep user choices separate from temporary layers when saving: the returned value contains all effective overrides, without provenance.
use ferravex_play::persistence::{Preferences, SaveData};
let defaults = Preferences::default();
let user = defaults.diff(&Preferences { master: 0.4, ..defaults }).unwrap();
let temporary = defaults.diff(&Preferences { muted: true, ..defaults }).unwrap();
let effective = defaults.compose(&[user, temporary]).unwrap();
assert_eq!(effective.master, 0.4);
assert!(effective.muted);
// Save only the user layer; the temporary mute is session-local.
let saved = defaults.compose(&[user]).unwrap().encode(1).unwrap();
assert!(!Preferences::decode(&saved).unwrap().0.muted);
assert_eq!(defaults.compose(&[]).unwrap(), defaults);Sourcepub fn diff(
&self,
choices: &Preferences,
) -> Result<PreferenceOverrides, SaveError>
pub fn diff( &self, choices: &Preferences, ) -> Result<PreferenceOverrides, SaveError>
Extract the minimal overrides that transform this base into choices.
Validates both values and returns SaveError::InvalidData if either is
invalid. Each differing field (including each individual bus) contains
the chosen value; equal fields inherit. Gain comparison is exact numeric
equality, so positive and negative zero compare equal. No allocation.
A snapshot cannot reveal whether a value equal to the base was explicitly
chosen. To pin such a value across future default changes, set its override
to Some(value) explicitly. In particular, Some(None) resets quality to
the game’s default; an outer None inherits the lower layer’s quality.
use ferravex_play::persistence::Preferences;
let defaults = Preferences { quality: Some(2), ..Preferences::default() };
let choices = Preferences { quality: None, buses: [1., 1., 0.25, 1.], ..defaults };
let diff = defaults.diff(&choices).unwrap();
assert_eq!(diff.quality, Some(None));
assert_eq!(diff.buses, [None, None, Some(0.25), None]);
assert_eq!(diff.master, None);
assert_eq!(defaults.compose(&[diff]).unwrap(), choices);Trait Implementations§
Source§impl Clone for Preferences
impl Clone for Preferences
Source§fn clone(&self) -> Preferences
fn clone(&self) -> Preferences
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more