Struct PreferenceOverrides

Source
pub struct PreferenceOverrides {
    pub master: Option<f32>,
    pub buses: [Option<f32>; 4],
    pub muted: Option<bool>,
    pub quality: Option<Option<u8>>,
    pub look: Option<u8>,
    pub resolution: Option<u8>,
    pub shadows: Option<u8>,
    pub lights: Option<u8>,
    pub adaptive: Option<bool>,
}
Expand description

Sparse, device-local overrides of Preferences, with one slot per field.

None inherits; Some(value) overrides even when the value is false, zero, or equal to the defaults. Default creates an empty layer. Bus slots are effects, ambience, music and UI, in that order. The quality field has three states: None inherits, Some(None) clears a quality preference, and Some(Some(0..=2)) selects low/medium/high.

Public fields allow editing a draft; Self::valid, Self::then and Preferences::compose check the same ranges as Preferences::valid. This fixed-size type has no save codec; persist resolved Preferences to preserve the existing schema. An equal-to-default explicit choice cannot be recovered by diffing a saved snapshot.

use ferravex_play::persistence::Preferences;

let defaults = Preferences::default();
let mut user = defaults.diff(&defaults).unwrap();
user.master = Some(defaults.master); // Explicitly pin this gain.
user.quality = Some(None); // Explicitly use the game's quality default.
let new_defaults = Preferences { master: 0.5, quality: Some(2), ..defaults };
let effective = new_defaults.compose(&[user]).unwrap();
assert_eq!(effective.master, defaults.master);
assert_eq!(effective.quality, None);

Fields§

§master: Option<f32>

Finite gain in 0..=1, or inherit.

§buses: [Option<f32>; 4]

Independent finite gains in 0..=1: effects, ambience, music, UI.

§muted: Option<bool>§quality: Option<Option<u8>>

Inherit, clear, or choose a quality index in 0..=2.

§look: Option<u8>

Visual style index in 0..=3, or inherit.

§resolution: Option<u8>

Framebuffer density index in 0..=5, or inherit.

§shadows: Option<u8>

Shadow setting index in 0..=3, or inherit.

§lights: Option<u8>

Local-light setting index in 0..=4, or inherit.

§adaptive: Option<bool>

Implementations§

Source§

impl PreferenceOverrides

Source

pub fn valid(self) -> bool

Whether every supplied value is valid; an empty layer is valid.

use ferravex_play::persistence::Preferences;
let defaults = Preferences::default();
let mut layer = defaults.diff(&defaults).unwrap();
assert!(layer.valid());
layer.buses[2] = Some(f32::NAN);
assert!(!layer.valid());
Source

pub fn is_empty(self) -> bool

Whether all fields inherit. Explicit false/zero/quality-clear values count as overrides, even if applying them would leave a base unchanged.

use ferravex_play::persistence::Preferences;
let defaults = Preferences::default();
let mut layer = defaults.diff(&defaults).unwrap();
assert!(layer.is_empty());
layer.muted = Some(false);
assert!(!layer.is_empty());
Source

pub fn then( self, higher: PreferenceOverrides, ) -> Result<PreferenceOverrides, SaveError>

Combine two sparse layers, giving supplied values in higher priority.

Inherited fields remain unset until applied to a base. Returns SaveError::InvalidData if either layer is invalid, even for values shadowed by higher. Neither input is mutated and no storage is allocated.

use ferravex_play::persistence::Preferences;
let defaults = Preferences::default();
let user = defaults.diff(&Preferences { master: 0.2, muted: true, ..defaults }).unwrap();
let mut temporary = defaults.diff(&defaults).unwrap();
temporary.muted = Some(false); // Override an explicit mute.
let merged = user.then(temporary).unwrap();
assert_eq!(merged.master, Some(0.2));
assert_eq!(merged.muted, Some(false));
assert_eq!(merged.look, None);
assert_eq!(defaults.compose(&[merged]), defaults.compose(&[user, temporary]));

Trait Implementations§

Source§

impl Clone for PreferenceOverrides

Source§

fn clone(&self) -> PreferenceOverrides

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 PreferenceOverrides

Source§

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

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

impl Default for PreferenceOverrides

Source§

fn default() -> PreferenceOverrides

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

impl PartialEq for PreferenceOverrides

Source§

fn eq(&self, other: &PreferenceOverrides) -> 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 Copy for PreferenceOverrides

Source§

impl StructuralPartialEq for PreferenceOverrides

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.