config: changed some enums to use enum_ordinalize crate
This commit is contained in:
parent
646e351305
commit
3a7486e6b7
9 changed files with 44 additions and 163 deletions
|
@ -14,13 +14,15 @@ dirs = "4.0.0"
|
||||||
|
|
||||||
serde = { version = "1.0", features = ["derive"], optional = true }
|
serde = { version = "1.0", features = ["derive"], optional = true }
|
||||||
serde_json = { version = "1.0", optional = true }
|
serde_json = { version = "1.0", optional = true }
|
||||||
|
enum-ordinalize = { version = "3.1.12", optional = true }
|
||||||
|
|
||||||
wincompatlib = { version = "0.2.0", optional = true }
|
wincompatlib = { version = "0.2.0", optional = true }
|
||||||
lazy_static = { version = "1.4.0", optional = true }
|
lazy_static = { version = "1.4.0", optional = true }
|
||||||
md5 = { version = "0.7.0", optional = true }
|
md5 = { version = "0.7.0", optional = true }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
states = []
|
states = []
|
||||||
config = ["dep:serde", "dep:serde_json"]
|
config = ["dep:serde", "dep:serde_json", "dep:enum-ordinalize"]
|
||||||
components = ["dep:wincompatlib", "dep:lazy_static"]
|
components = ["dep:wincompatlib", "dep:lazy_static"]
|
||||||
game = ["components", "config"]
|
game = ["components", "config"]
|
||||||
fps-unlocker = ["dep:md5"]
|
fps-unlocker = ["dep:md5"]
|
||||||
|
|
|
@ -46,6 +46,7 @@ impl Fps {
|
||||||
180 => Self::HundredEighty,
|
180 => Self::HundredEighty,
|
||||||
200 => Self::TwoHundred,
|
200 => Self::TwoHundred,
|
||||||
240 => Self::TwoHundredFourty,
|
240 => Self::TwoHundredFourty,
|
||||||
|
|
||||||
num => Self::Custom(num)
|
num => Self::Custom(num)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,6 +60,7 @@ impl Fps {
|
||||||
Self::HundredEighty => 180,
|
Self::HundredEighty => 180,
|
||||||
Self::TwoHundred => 200,
|
Self::TwoHundred => 200,
|
||||||
Self::TwoHundredFourty => 240,
|
Self::TwoHundredFourty => 240,
|
||||||
|
|
||||||
Self::Custom(num) => *num
|
Self::Custom(num) => *num
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
use serde_json::Value as JsonValue;
|
use serde_json::Value as JsonValue;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
use enum_ordinalize::Ordinalize;
|
||||||
|
|
||||||
|
#[derive(Ordinalize, Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub enum WindowMode {
|
pub enum WindowMode {
|
||||||
None,
|
None,
|
||||||
Popup,
|
Popup,
|
||||||
|
@ -19,28 +21,3 @@ impl From<&JsonValue> for WindowMode {
|
||||||
serde_json::from_value(value.clone()).unwrap_or_default()
|
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -8,9 +8,9 @@ use crate::consts::launcher_dir;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
|
|
||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
pub use super::config::Config;
|
|
||||||
|
|
||||||
pub use super::config::prelude::*;
|
pub use super::config::prelude::*;
|
||||||
|
|
||||||
|
pub use super::config::Config;
|
||||||
}
|
}
|
||||||
|
|
||||||
use prelude::*;
|
use prelude::*;
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
use serde_json::Value as JsonValue;
|
use serde_json::Value as JsonValue;
|
||||||
|
|
||||||
|
use enum_ordinalize::Ordinalize;
|
||||||
|
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
#[derive(Ordinalize, Debug, Clone, Copy, Serialize, Deserialize)]
|
||||||
pub enum HUD {
|
pub enum HUD {
|
||||||
None,
|
None,
|
||||||
DXVK,
|
DXVK,
|
||||||
|
@ -24,30 +26,6 @@ impl From<&JsonValue> for HUD {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<u32> for HUD {
|
|
||||||
type Error = String;
|
|
||||||
|
|
||||||
fn try_from(value: u32) -> Result<Self, Self::Error> {
|
|
||||||
match value {
|
|
||||||
0 => Ok(Self::None),
|
|
||||||
1 => Ok(Self::DXVK),
|
|
||||||
2 => Ok(Self::MangoHUD),
|
|
||||||
_ => Err(String::from("Failed to convert number to HUD enum"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::from_over_into)]
|
|
||||||
impl Into<u32> for HUD {
|
|
||||||
fn into(self) -> u32 {
|
|
||||||
match self {
|
|
||||||
Self::None => 0,
|
|
||||||
Self::DXVK => 1,
|
|
||||||
Self::MangoHUD => 2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl HUD {
|
impl HUD {
|
||||||
/// Get environment variables corresponding to used wine hud
|
/// Get environment variables corresponding to used wine hud
|
||||||
pub fn get_env_vars(&self, config: &Config) -> HashMap<&str, &str> {
|
pub fn get_env_vars(&self, config: &Config) -> HashMap<&str, &str> {
|
||||||
|
|
|
@ -3,7 +3,9 @@ use std::collections::HashMap;
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
use serde_json::Value as JsonValue;
|
use serde_json::Value as JsonValue;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
use enum_ordinalize::Ordinalize;
|
||||||
|
|
||||||
|
#[derive(Ordinalize, Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub enum WineLang {
|
pub enum WineLang {
|
||||||
System,
|
System,
|
||||||
English,
|
English,
|
||||||
|
@ -30,58 +32,7 @@ impl From<&JsonValue> for WineLang {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<u32> for WineLang {
|
|
||||||
type Error = String;
|
|
||||||
|
|
||||||
fn try_from(value: u32) -> Result<Self, Self::Error> {
|
|
||||||
match value {
|
|
||||||
0 => Ok(Self::System),
|
|
||||||
1 => Ok(Self::English),
|
|
||||||
2 => Ok(Self::Russian),
|
|
||||||
3 => Ok(Self::German),
|
|
||||||
4 => Ok(Self::Portuguese),
|
|
||||||
5 => Ok(Self::Polish),
|
|
||||||
6 => Ok(Self::French),
|
|
||||||
7 => Ok(Self::Spanish),
|
|
||||||
8 => Ok(Self::Chinese),
|
|
||||||
9 => Ok(Self::Japanese),
|
|
||||||
10 => Ok(Self::Korean),
|
|
||||||
|
|
||||||
_ => Err(String::from("Failed to convert number to WineLang enum"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::from_over_into)]
|
|
||||||
impl Into<u32> for WineLang {
|
|
||||||
fn into(self) -> u32 {
|
|
||||||
for (i, lang) in Self::list().into_iter().enumerate() {
|
|
||||||
if lang == self {
|
|
||||||
return i as u32;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unreachable!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WineLang {
|
impl WineLang {
|
||||||
pub fn list() -> Vec<Self> {
|
|
||||||
vec![
|
|
||||||
Self::System,
|
|
||||||
Self::English,
|
|
||||||
Self::Russian,
|
|
||||||
Self::German,
|
|
||||||
Self::Portuguese,
|
|
||||||
Self::Polish,
|
|
||||||
Self::French,
|
|
||||||
Self::Spanish,
|
|
||||||
Self::Chinese,
|
|
||||||
Self::Japanese,
|
|
||||||
Self::Korean
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get environment variables corresponding to used wine language
|
/// Get environment variables corresponding to used wine language
|
||||||
pub fn get_env_vars(&self) -> HashMap<&str, &str> {
|
pub fn get_env_vars(&self) -> HashMap<&str, &str> {
|
||||||
HashMap::from([("LANG", match self {
|
HashMap::from([("LANG", match self {
|
||||||
|
|
|
@ -3,7 +3,9 @@ use std::collections::HashMap;
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
use serde_json::Value as JsonValue;
|
use serde_json::Value as JsonValue;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
use enum_ordinalize::Ordinalize;
|
||||||
|
|
||||||
|
#[derive(Ordinalize, Debug, Clone, Copy, Serialize, Deserialize)]
|
||||||
pub enum WineSync {
|
pub enum WineSync {
|
||||||
None,
|
None,
|
||||||
ESync,
|
ESync,
|
||||||
|
@ -23,33 +25,6 @@ impl From<&JsonValue> for WineSync {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<u32> for WineSync {
|
|
||||||
type Error = String;
|
|
||||||
|
|
||||||
fn try_from(value: u32) -> Result<Self, Self::Error> {
|
|
||||||
match value {
|
|
||||||
0 => Ok(Self::None),
|
|
||||||
1 => Ok(Self::ESync),
|
|
||||||
2 => Ok(Self::FSync),
|
|
||||||
3 => Ok(Self::Futex2),
|
|
||||||
|
|
||||||
_ => Err(String::from("Failed to convert number to WineSync enum"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::from_over_into)]
|
|
||||||
impl Into<u32> for WineSync {
|
|
||||||
fn into(self) -> u32 {
|
|
||||||
match self {
|
|
||||||
Self::None => 0,
|
|
||||||
Self::ESync => 1,
|
|
||||||
Self::FSync => 2,
|
|
||||||
Self::Futex2 => 3
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WineSync {
|
impl WineSync {
|
||||||
/// Get environment variables corresponding to used wine sync
|
/// Get environment variables corresponding to used wine sync
|
||||||
pub fn get_env_vars(&self) -> HashMap<&str, &str> {
|
pub fn get_env_vars(&self) -> HashMap<&str, &str> {
|
||||||
|
|
|
@ -24,16 +24,12 @@ pub enum GameEdition {
|
||||||
|
|
||||||
impl Default for GameEdition {
|
impl Default for GameEdition {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let locale = match std::env::var("LC_ALL") {
|
#[allow(clippy::or_fun_call)]
|
||||||
Ok(locale) => locale,
|
let locale = std::env::var("LC_ALL").unwrap_or_else(|_| {
|
||||||
Err(_) => match std::env::var("LC_MESSAGES") {
|
std::env::var("LC_MESSAGES").unwrap_or_else(|_| {
|
||||||
Ok(locale) => locale,
|
std::env::var("LANG").unwrap_or(String::from("en_us"))
|
||||||
Err(_) => match std::env::var("LANG") {
|
})
|
||||||
Ok(locale) => locale,
|
});
|
||||||
Err(_) => return Self::Global
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if locale.len() > 4 && &locale[..5].to_lowercase() == "zh_cn" {
|
if locale.len() > 4 && &locale[..5].to_lowercase() == "zh_cn" {
|
||||||
Self::China
|
Self::China
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub enum Resolution {
|
pub enum Resolution {
|
||||||
Custom(u64, u64),
|
|
||||||
|
|
||||||
// qHD; 960x540
|
// qHD; 960x540
|
||||||
MiniHD,
|
MiniHD,
|
||||||
|
|
||||||
|
@ -15,13 +13,14 @@ pub enum Resolution {
|
||||||
QuadHD,
|
QuadHD,
|
||||||
|
|
||||||
// 3840x2160
|
// 3840x2160
|
||||||
UltraHD
|
UltraHD,
|
||||||
|
|
||||||
|
Custom(u64, u64)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Resolution {
|
impl Resolution {
|
||||||
pub fn list() -> Vec<Self> {
|
pub fn list() -> Vec<Self> {
|
||||||
vec![
|
vec![
|
||||||
Self::Custom(0, 0),
|
|
||||||
Self::MiniHD,
|
Self::MiniHD,
|
||||||
Self::HD,
|
Self::HD,
|
||||||
Self::FullHD,
|
Self::FullHD,
|
||||||
|
@ -60,12 +59,13 @@ impl TryFrom<u32> for Resolution {
|
||||||
|
|
||||||
fn try_from(value: u32) -> Result<Self, Self::Error> {
|
fn try_from(value: u32) -> Result<Self, Self::Error> {
|
||||||
match value {
|
match value {
|
||||||
0 => Ok(Self::Custom(0, 0)),
|
0 => Ok(Self::MiniHD),
|
||||||
1 => Ok(Self::MiniHD),
|
1 => Ok(Self::HD),
|
||||||
2 => Ok(Self::HD),
|
2 => Ok(Self::FullHD),
|
||||||
3 => Ok(Self::FullHD),
|
3 => Ok(Self::QuadHD),
|
||||||
4 => Ok(Self::QuadHD),
|
4 => Ok(Self::UltraHD),
|
||||||
5 => Ok(Self::UltraHD),
|
|
||||||
|
5 => Ok(Self::Custom(0, 0)),
|
||||||
|
|
||||||
_ => Err(String::from("Failed to convert number to Resolution enum"))
|
_ => Err(String::from("Failed to convert number to Resolution enum"))
|
||||||
}
|
}
|
||||||
|
@ -76,13 +76,13 @@ impl TryFrom<u32> for Resolution {
|
||||||
impl Into<u32> for Resolution {
|
impl Into<u32> for Resolution {
|
||||||
fn into(self) -> u32 {
|
fn into(self) -> u32 {
|
||||||
match self {
|
match self {
|
||||||
Self::MiniHD => 1,
|
Self::MiniHD => 0,
|
||||||
Self::HD => 2,
|
Self::HD => 1,
|
||||||
Self::FullHD => 3,
|
Self::FullHD => 2,
|
||||||
Self::QuadHD => 4,
|
Self::QuadHD => 3,
|
||||||
Self::UltraHD => 5,
|
Self::UltraHD => 4,
|
||||||
|
|
||||||
_ => 0 // Custom resolution
|
_ => 5 // Custom resolution
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue