Updated window_mode property

This commit is contained in:
Observer KRypt0n_ 2022-12-30 11:49:49 +02:00
parent e0ca079052
commit 14263492c6
No known key found for this signature in database
GPG key ID: 844DA47BA25FE1E2
3 changed files with 56 additions and 4 deletions

View file

@ -2,17 +2,21 @@ use serde::{Serialize, Deserialize};
use serde_json::Value as JsonValue; use serde_json::Value as JsonValue;
pub mod fps; pub mod fps;
pub mod window_mode;
pub mod prelude { pub mod prelude {
pub use super::fps::Fps; pub use super::fps::Fps;
pub use super::window_mode::WindowMode;
} }
use prelude::*;
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Config { pub struct Config {
pub fps: u64, pub fps: u64,
pub power_saving: bool, pub power_saving: bool,
pub monitor: u64, pub monitor: u64,
pub window_mode: u64, pub window_mode: WindowMode,
pub priority: u64 pub priority: u64
} }
@ -22,7 +26,7 @@ impl Default for Config {
fps: 120, fps: 120,
power_saving: false, power_saving: false,
monitor: 1, monitor: 1,
window_mode: 0, window_mode: WindowMode::default(),
priority: 3 priority: 3
} }
} }
@ -49,7 +53,7 @@ impl From<&JsonValue> for Config {
}, },
window_mode: match value.get("window_mode") { window_mode: match value.get("window_mode") {
Some(value) => value.as_u64().unwrap_or(default.window_mode), Some(value) => WindowMode::from(value),
None => default.window_mode None => default.window_mode
}, },

View file

@ -0,0 +1,46 @@
use serde::{Serialize, Deserialize};
use serde_json::Value as JsonValue;
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum WindowMode {
None,
Popup,
Fullscreen
}
impl Default for WindowMode {
fn default() -> Self {
Self::None
}
}
impl From<&JsonValue> for WindowMode {
fn from(value: &JsonValue) -> Self {
serde_json::from_value(value.clone()).unwrap_or_default()
}
}
impl TryFrom<u32> for WindowMode {
type Error = String;
fn try_from(value: u32) -> Result<Self, Self::Error> {
match value {
0 => Ok(Self::None),
1 => Ok(Self::Popup),
2 => Ok(Self::Fullscreen),
_ => Err(String::from("Failed to convert number to WindowMode enum"))
}
}
}
#[allow(clippy::from_over_into)]
impl Into<u32> for WindowMode {
fn into(self) -> u32 {
match self {
Self::None => 0,
Self::Popup => 1,
Self::Fullscreen => 2
}
}
}

View file

@ -53,7 +53,9 @@ impl ConfigSchema {
Self { Self {
FPSTarget: config.fps, FPSTarget: config.fps,
UsePowerSave: config.power_saving, UsePowerSave: config.power_saving,
Fullscreen: config.fullscreen, PopupWindow: config.window_mode == 1,
Fullscreen: config.window_mode == 2,
MonitorNum: config.monitor,
Priority: config.priority, Priority: config.priority,
..Self::default() ..Self::default()