Struct Preferences

Source
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: u8

Browser framebuffer density: device, 0.75x, 1x, 1.5x, 2x, 3x.

§shadows: u8

Preset, off, 512 hard, 1024 soft.

§lights: u8

Preset, off, 2, 4, 8 local lights.

§adaptive: bool

Implementations§

Source§

impl Preferences

Source

pub fn valid(self) -> bool

Source

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);
Source

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

Source§

fn clone(&self) -> Preferences

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Preferences

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for Preferences

Source§

fn default() -> Preferences

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Preferences

Source§

fn eq(&self, other: &Preferences) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl SaveData for Preferences

Source§

const SCHEMA: u64 = 5_068_889_694_885_270_321u64

Source§

const VERSION: u32 = 5u32

Source§

const MAX_BYTES: usize = 1_024usize

Source§

fn write(&self, d: &mut Document) -> Result<(), SaveError>

Source§

fn read(d: &Document) -> Result<Preferences, SaveError>

Source§

fn encode(&self, generation: u64) -> Result<Vec<u8>, SaveError>

Source§

fn decode(data: &[u8]) -> Result<(Self, u64), SaveError>

Source§

impl Copy for Preferences

Source§

impl StructuralPartialEq for Preferences

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.