pub struct PersistedSettings {
pub fov_degrees: f32,
pub sfx_volume: f32,
pub render_distance_chunks: u32,
pub sensitivity_pct: u32,
}Expand description
User-adjustable settings persisted to worlds/{world_name}/settings.json.
All four fields map directly to the in-game sliders exposed by
crate::ui::PauseMenuPlugin:
| Field | Slider | Range |
|---|---|---|
fov_degrees | Field of View | 50–120 |
sfx_volume | SFX Volume | 0.0–1.0 |
render_distance_chunks | Render Distance | 4–32 (even) |
sensitivity_pct | Mouse Sensitivity | 10–100 |
Fields§
§fov_degrees: f32Vertical field-of-view in degrees. Valid range: 50.0–120.0.
sfx_volume: f32SFX volume in the range [0.0, 1.0].
render_distance_chunks: u32Render distance in chunks (even values only). Valid range: 4–32.
sensitivity_pct: u32Mouse sensitivity as a percentage of the default.
100 = default (“Minecraft-like” feel), 10 = slowest.
The underlying crate::player::Player::sensitivity multiplier is
sensitivity_pct / 100, combined internally with the hidden
MOUSE_SCALE constant (rad/px) to produce camera rotation per mouse
pixel.
Implementations§
Source§impl PersistedSettings
impl PersistedSettings
Sourcepub fn save(&self, world_name: &str)
pub fn save(&self, world_name: &str)
Saves these settings to worlds/{world_name}/settings.json.
Creates the directory if it does not exist. Silently ignores I/O errors so that a read-only filesystem does not crash the game.
Sourcepub fn load(world_name: &str) -> Option<Self>
pub fn load(world_name: &str) -> Option<Self>
Loads settings from worlds/{world_name}/settings.json.
Returns None if the file does not exist or cannot be parsed (e.g. on
the first run before any settings have been saved).
Sourcepub fn save_to(&self, path: &Path)
pub fn save_to(&self, path: &Path)
Saves these settings to the file at path.
Creates the parent directory if it does not exist. Silently ignores
I/O errors, like save.
Sourcepub fn load_from(path: &Path) -> Option<Self>
pub fn load_from(path: &Path) -> Option<Self>
Loads settings from the file at path.
Returns None if the file does not exist or cannot be parsed.
Sourcepub fn load_distance(&self) -> f32
pub fn load_distance(&self) -> f32
Load distance in world units for the saved render distance, with the
chunk count limited to the menu range 4–32.
Sourcepub fn capture(
player: Option<&PlayerConfig>,
world: Option<&WorldConfig>,
sfx: Option<&SfxConfig>,
) -> Self
pub fn capture( player: Option<&PlayerConfig>, world: Option<&WorldConfig>, sfx: Option<&SfxConfig>, ) -> Self
Reads the four settings from the resources the settings menu edits.
A missing resource contributes the default of its type. The render
distance is the load distance in whole chunks, limited to 4–32.
Sourcepub fn apply(
&self,
player: Option<&mut PlayerConfig>,
world: Option<&mut WorldConfig>,
manager: Option<&mut ChunkManager>,
sfx: Option<&mut SfxConfig>,
)
pub fn apply( &self, player: Option<&mut PlayerConfig>, world: Option<&mut WorldConfig>, manager: Option<&mut ChunkManager>, sfx: Option<&mut SfxConfig>, )
Writes these settings to the resources the settings menu edits.
Every value is limited to the range documented on its field first; a field of view or volume that is not a finite number is skipped.
The render distance is written to WorldConfig and ChunkManager
only when it differs from the load distance already configured. The
unload distance then becomes the load distance plus
RENDER_DISTANCE_UNLOAD_MARGIN. A saved value equal to the
configured one leaves a custom unload distance as it is.
Trait Implementations§
Source§impl Clone for PersistedSettings
impl Clone for PersistedSettings
Source§impl Debug for PersistedSettings
impl Debug for PersistedSettings
Source§impl<'de> Deserialize<'de> for PersistedSettings
impl<'de> Deserialize<'de> for PersistedSettings
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Forget for PersistedSettings
impl Freeze for PersistedSettings
impl Move for PersistedSettings
impl RefUnwindSafe for PersistedSettings
impl Send for PersistedSettings
impl Sync for PersistedSettings
impl Unpin for PersistedSettings
impl UnsafeUnpin for PersistedSettings
impl UnwindSafe for PersistedSettings
Blanket Implementations§
Source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
Source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
T ShaderType for self. When used in AsBindGroup
derives, it is safe to assume that all images in self exist.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ConditionalSend for Twhere
T: Send,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more