From 67cde95a35d9fbb3e1f0f64ce5a17936827b72f8 Mon Sep 17 00:00:00 2001 From: VirxEC Date: Wed, 30 Aug 2023 00:34:14 -0400 Subject: [PATCH] Save camera state to `settings.txt` --- src/camera.rs | 3 +- src/gui.rs | 104 ++++++++++++++++++++++++++------------------------ 2 files changed, 56 insertions(+), 51 deletions(-) diff --git a/src/camera.rs b/src/camera.rs index 3cec9f3..32a0eec 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -11,6 +11,7 @@ use bevy_atmosphere::prelude::*; use bevy_framepace::{FramepacePlugin, FramepaceSettings}; use bevy_mod_picking::prelude::*; use bevy_vector_shapes::prelude::*; +use serde::{Deserialize, Serialize}; use crate::spectator::*; @@ -29,7 +30,7 @@ pub struct BoostAmount; #[derive(Component)] pub struct TimeDisplay; -#[derive(Component, Clone, Copy, Default, PartialEq, Eq)] +#[derive(Component, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)] pub enum PrimaryCamera { #[default] Spectator, diff --git a/src/gui.rs b/src/gui.rs index 1b1f489..014521c 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -39,22 +39,21 @@ impl Plugin for DebugOverlayPlugin { Update, ( listen, - #[cfg(debug_assertions)] - debug_ui, ( + #[cfg(debug_assertions)] + debug_ui, ui_system, - ( - toggle_vsync, - toggle_ballcam, - update_daytime, - #[cfg(not(feature = "ssao"))] - update_msaa, - write_settings_to_file, - // update_draw_distance, - ), - ) - .chain(), - ), + toggle_vsync, + toggle_ballcam, + update_daytime, + #[cfg(not(feature = "ssao"))] + update_msaa, + write_settings_to_file, + update_camera_state, + // update_draw_distance, + ), + ) + .chain(), ); } } @@ -71,6 +70,7 @@ struct Options { daytime: f32, day_speed: f32, msaa: u8, + camera_state: PrimaryCamera, // draw_distance: u8, } @@ -88,6 +88,7 @@ impl Default for Options { daytime: 0., day_speed: 1., msaa: 2, + camera_state: PrimaryCamera::Spectator, // draw_distance: 3, } } @@ -126,6 +127,7 @@ impl Options { "daytime" => options.daytime = value.parse().unwrap(), "day_speed" => options.day_speed = value.parse().unwrap(), "msaa" => options.msaa = value.parse().unwrap(), + "camera_state" => options.camera_state = serde_json::from_str(value).unwrap(), _ => println!("Unknown key {key} with value {value}"), } } @@ -154,6 +156,7 @@ impl Options { file.write_fmt(format_args!("daytime={}\n", self.daytime))?; file.write_fmt(format_args!("day_speed={}\n", self.day_speed))?; file.write_fmt(format_args!("msaa={}\n", self.msaa))?; + file.write_fmt(format_args!("camera_state={}\n", serde_json::to_string(&self.camera_state)?))?; Ok(()) } @@ -168,6 +171,7 @@ impl Options { || self.daytime != other.daytime || self.day_speed != other.day_speed || self.msaa != other.msaa + || self.camera_state != other.camera_state } } @@ -195,31 +199,7 @@ fn debug_ui( }); } -fn ui_system( - mut windows: Query<&mut Window, With>, - mut picking_state: ResMut, - mut options: ResMut, - mut contexts: EguiContexts, - keys: Res>, - time: Res