Updated window_mode
property
This commit is contained in:
parent
e0ca079052
commit
14263492c6
3 changed files with 56 additions and 4 deletions
|
@ -2,17 +2,21 @@ use serde::{Serialize, Deserialize};
|
|||
use serde_json::Value as JsonValue;
|
||||
|
||||
pub mod fps;
|
||||
pub mod window_mode;
|
||||
|
||||
pub mod prelude {
|
||||
pub use super::fps::Fps;
|
||||
pub use super::window_mode::WindowMode;
|
||||
}
|
||||
|
||||
use prelude::*;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Config {
|
||||
pub fps: u64,
|
||||
pub power_saving: bool,
|
||||
pub monitor: u64,
|
||||
pub window_mode: u64,
|
||||
pub window_mode: WindowMode,
|
||||
pub priority: u64
|
||||
}
|
||||
|
||||
|
@ -22,7 +26,7 @@ impl Default for Config {
|
|||
fps: 120,
|
||||
power_saving: false,
|
||||
monitor: 1,
|
||||
window_mode: 0,
|
||||
window_mode: WindowMode::default(),
|
||||
priority: 3
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +53,7 @@ impl From<&JsonValue> for Config {
|
|||
},
|
||||
|
||||
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
|
||||
},
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
|
@ -53,7 +53,9 @@ impl ConfigSchema {
|
|||
Self {
|
||||
FPSTarget: config.fps,
|
||||
UsePowerSave: config.power_saving,
|
||||
Fullscreen: config.fullscreen,
|
||||
PopupWindow: config.window_mode == 1,
|
||||
Fullscreen: config.window_mode == 2,
|
||||
MonitorNum: config.monitor,
|
||||
Priority: config.priority,
|
||||
|
||||
..Self::default()
|
||||
|
|
Loading…
Reference in a new issue