mirror of
https://github.com/an-anime-team/an-anime-game-launcher.git
synced 2024-11-24 05:46:17 +03:00
Added HUD support in game launching
This commit is contained in:
parent
6cd2c326d8
commit
eb2620f9cc
5 changed files with 60 additions and 41 deletions
54
src/lib/config/hud.rs
Normal file
54
src/lib/config/hud.rs
Normal file
|
@ -0,0 +1,54 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
||||
pub enum HUD {
|
||||
None,
|
||||
DXVK,
|
||||
MangoHUD
|
||||
}
|
||||
|
||||
impl Default for HUD {
|
||||
fn default() -> Self {
|
||||
Self::None
|
||||
}
|
||||
}
|
||||
|
||||
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"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<u32> for HUD {
|
||||
fn into(self) -> u32 {
|
||||
match self {
|
||||
Self::None => 0,
|
||||
Self::DXVK => 1,
|
||||
Self::MangoHUD => 2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HUD {
|
||||
/// Get environment variables corresponding to used wine hud
|
||||
pub fn get_env_vars(&self) -> HashMap<&str, &str> {
|
||||
match self {
|
||||
Self::None => HashMap::new(),
|
||||
Self::DXVK => HashMap::from([
|
||||
("DXVK_HUD", "1")
|
||||
]),
|
||||
Self::MangoHUD => HashMap::from([
|
||||
("MANGOHUD", "1")
|
||||
])
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,10 +7,10 @@ use serde::{Serialize, Deserialize};
|
|||
|
||||
use super::consts::*;
|
||||
|
||||
mod wine_hud;
|
||||
mod hud;
|
||||
mod wine_sync;
|
||||
|
||||
pub use wine_hud::WineHUD;
|
||||
pub use hud::HUD;
|
||||
pub use wine_sync::WineSync;
|
||||
|
||||
pub fn get() -> Result<Config, Error> {
|
||||
|
@ -178,7 +178,7 @@ impl Default for Wine {
|
|||
pub struct Enhancements {
|
||||
pub fsr: Fsr,
|
||||
pub gamemode: bool,
|
||||
pub hud: WineHUD
|
||||
pub hud: HUD
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
||||
pub enum WineHUD {
|
||||
None,
|
||||
DXVK,
|
||||
MangoHUD
|
||||
}
|
||||
|
||||
impl Default for WineHUD {
|
||||
fn default() -> Self {
|
||||
Self::None
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<u32> for WineHUD {
|
||||
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 WineHUD enum"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<u32> for WineHUD {
|
||||
fn into(self) -> u32 {
|
||||
match self {
|
||||
Self::None => 0,
|
||||
Self::DXVK => 1,
|
||||
Self::MangoHUD => 2
|
||||
}
|
||||
}
|
||||
}
|
|
@ -96,7 +96,9 @@ pub fn run(debug: bool) -> Result<(), Error> {
|
|||
}
|
||||
|
||||
command.env("WINEPREFIX", &config.game.wine.prefix);
|
||||
|
||||
command.envs(config.game.wine.sync.get_env_vars());
|
||||
command.envs(config.game.enhancements.hud.get_env_vars());
|
||||
|
||||
command.envs(config.game.environment)
|
||||
.current_dir(config.game.path)
|
||||
|
|
|
@ -33,7 +33,7 @@ impl Page {
|
|||
result.hud_combo.connect_selected_notify(|hud| {
|
||||
if let Ok(mut config) = config::get() {
|
||||
// TODO: show toast
|
||||
config.game.enhancements.hud = config::WineHUD::try_from(hud.selected()).unwrap();
|
||||
config.game.enhancements.hud = config::HUD::try_from(hud.selected()).unwrap();
|
||||
|
||||
config::update(config).unwrap();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue