44 lines
1.1 KiB
Rust
44 lines
1.1 KiB
Rust
use crate::{client::audio::SoundSettings, utils::Debounce};
|
|
use bevy::prelude::*;
|
|
use bevy_persistent::{Persistent, StorageFormat};
|
|
|
|
pub fn plugin(app: &mut App) {
|
|
app.insert_resource(
|
|
Persistent::<SoundSettings>::builder()
|
|
.name("audio")
|
|
.format(StorageFormat::Ron)
|
|
.path(
|
|
dirs::config_dir()
|
|
.unwrap()
|
|
.join("com.rustunit.hedzreloaded")
|
|
.join("audio.ron"),
|
|
)
|
|
.default(SoundSettings::default())
|
|
.build()
|
|
.unwrap(),
|
|
);
|
|
|
|
app.add_systems(Update, persist_settings);
|
|
app.add_systems(Startup, load_settings);
|
|
}
|
|
|
|
fn persist_settings(
|
|
settings: Res<SoundSettings>,
|
|
mut persistent: ResMut<Persistent<SoundSettings>>,
|
|
mut debounce: Debounce<1000>,
|
|
) -> Result {
|
|
if settings.is_changed() {
|
|
debounce.reset();
|
|
}
|
|
|
|
if debounce.finished() {
|
|
persistent.set(*settings)?;
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
fn load_settings(persistent: Res<Persistent<SoundSettings>>, mut settings: ResMut<SoundSettings>) {
|
|
*settings = *persistent.get();
|
|
}
|