save/load avatar setting from config file

This commit is contained in:
yuni 2024-06-17 01:43:23 +02:00
parent 548386ef54
commit 377c2a4f0b
3 changed files with 6 additions and 0 deletions

View file

@ -147,6 +147,7 @@ pub fn setup(mut settings: ResMut<Settings>, prefs: Res<var::Preferences>) {
settings.set_noise_cancellation_mode(prefs.noise_cancellation_mode); settings.set_noise_cancellation_mode(prefs.noise_cancellation_mode);
settings.third_person = prefs.third_person; settings.third_person = prefs.third_person;
settings.shadows_sun = prefs.shadows_sun; settings.shadows_sun = prefs.shadows_sun;
settings.ar_avatar = prefs.avatar;
} }
pub fn handle_game_event( pub fn handle_game_event(

View file

@ -1281,6 +1281,7 @@ fn update_overlay_visibility(
fn update_avatar( fn update_avatar(
mut commands: Commands, mut commands: Commands,
mut settings: ResMut<Settings>, mut settings: ResMut<Settings>,
mut prefs: ResMut<var::Preferences>,
asset_server: Res<AssetServer>, asset_server: Res<AssetServer>,
q_avatar: Query<(Entity, &SceneInstance), With<PlayerAvatar>>, q_avatar: Query<(Entity, &SceneInstance), With<PlayerAvatar>>,
q_player: Query<Entity, With<actor::Player>>, q_player: Query<Entity, With<actor::Player>>,
@ -1289,6 +1290,9 @@ fn update_avatar(
if settings.ar_avatar >= PLAYER_AR_AVATARS.len() { if settings.ar_avatar >= PLAYER_AR_AVATARS.len() {
settings.ar_avatar = settings.ar_avatar % PLAYER_AR_AVATARS.len(); settings.ar_avatar = settings.ar_avatar % PLAYER_AR_AVATARS.len();
} }
prefs.avatar = settings.ar_avatar;
prefs.save();
let ava = if let Some(ava) = PLAYER_AR_AVATARS.get(settings.ar_avatar) { let ava = if let Some(ava) = PLAYER_AR_AVATARS.get(settings.ar_avatar) {
ava ava
} else { } else {

View file

@ -456,6 +456,7 @@ pub struct Preferences {
pub noise_cancellation_mode: usize, pub noise_cancellation_mode: usize,
pub third_person: bool, pub third_person: bool,
pub shadows_sun: bool, pub shadows_sun: bool,
pub avatar: usize,
#[serde(skip)] #[serde(skip)]
pub source_file: Option<String>, pub source_file: Option<String>,