mirror of
https://github.com/an-anime-team/an-anime-game-launcher.git
synced 2024-11-21 20:36:01 +03:00
Added wine sync and fsr options syncronization
- moved `WineSync` and `WineHUD` to separate files
This commit is contained in:
parent
919d7eaaa9
commit
6cd2c326d8
6 changed files with 154 additions and 62 deletions
|
@ -46,7 +46,7 @@ Adw.PreferencesPage enhanced_page {
|
|||
]
|
||||
};
|
||||
|
||||
Gtk.Switch {
|
||||
Gtk.Switch fsr_switcher {
|
||||
valign: center;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,12 @@ use serde::{Serialize, Deserialize};
|
|||
|
||||
use super::consts::*;
|
||||
|
||||
mod wine_hud;
|
||||
mod wine_sync;
|
||||
|
||||
pub use wine_hud::WineHUD;
|
||||
pub use wine_sync::WineSync;
|
||||
|
||||
pub fn get() -> Result<Config, Error> {
|
||||
match config_file() {
|
||||
Some(path) => {
|
||||
|
@ -52,42 +58,6 @@ pub fn update(config: Config) -> Result<(), Error> {
|
|||
}
|
||||
}
|
||||
|
||||
#[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 HUD enum"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<u32> for WineHUD {
|
||||
fn into(self) -> u32 {
|
||||
match self {
|
||||
WineHUD::None => 0,
|
||||
WineHUD::DXVK => 1,
|
||||
WineHUD::MangoHUD => 2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct Config {
|
||||
pub launcher: Launcher,
|
||||
|
@ -120,25 +90,6 @@ impl Config {
|
|||
None => None
|
||||
}
|
||||
}
|
||||
|
||||
/// Get environment variables corresponding to used wine sync
|
||||
pub fn get_wine_sync_env_vars(&self) -> HashMap<&str, &str> {
|
||||
match self.game.wine.sync.as_str() {
|
||||
"esync" => HashMap::from([
|
||||
("WINEESYNC", "1")
|
||||
]),
|
||||
"fsync" => HashMap::from([
|
||||
("WINEESYNC", "1"),
|
||||
("WINEFSYNC", "1")
|
||||
]),
|
||||
"futex2" => HashMap::from([
|
||||
("WINEESYNC", "1"),
|
||||
("WINEFSYNC", "1"),
|
||||
("WINEFSYNC_FUTEX2", "1")
|
||||
]),
|
||||
_ => HashMap::new()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
|
@ -203,7 +154,7 @@ pub struct Wine {
|
|||
pub prefix: String,
|
||||
pub builds: String,
|
||||
pub selected: Option<String>,
|
||||
pub sync: String
|
||||
pub sync: WineSync
|
||||
}
|
||||
|
||||
impl Default for Wine {
|
||||
|
@ -218,7 +169,7 @@ impl Default for Wine {
|
|||
None => String::new()
|
||||
},
|
||||
selected: None,
|
||||
sync: String::from("esync")
|
||||
sync: WineSync::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -232,7 +183,7 @@ pub struct Enhancements {
|
|||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
||||
pub struct Fsr {
|
||||
pub strength: u8,
|
||||
pub strength: u32,
|
||||
pub enabled: bool
|
||||
}
|
||||
|
37
src/lib/config/wine_hud.rs
Normal file
37
src/lib/config/wine_hud.rs
Normal file
|
@ -0,0 +1,37 @@
|
|||
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
|
||||
}
|
||||
}
|
||||
}
|
63
src/lib/config/wine_sync.rs
Normal file
63
src/lib/config/wine_sync.rs
Normal file
|
@ -0,0 +1,63 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
||||
pub enum WineSync {
|
||||
None,
|
||||
ESync,
|
||||
FSync,
|
||||
Futex2
|
||||
}
|
||||
|
||||
impl Default for WineSync {
|
||||
fn default() -> Self {
|
||||
Self::ESync
|
||||
}
|
||||
}
|
||||
|
||||
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"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
/// Get environment variables corresponding to used wine sync
|
||||
pub fn get_env_vars(&self) -> HashMap<&str, &str> {
|
||||
match self {
|
||||
Self::None => HashMap::new(),
|
||||
Self::ESync => HashMap::from([
|
||||
("WINEESYNC", "1")
|
||||
]),
|
||||
Self::FSync => HashMap::from([
|
||||
("WINEESYNC", "1"),
|
||||
("WINEFSYNC", "1")
|
||||
]),
|
||||
Self::Futex2 => HashMap::from([
|
||||
("WINEESYNC", "1"),
|
||||
("WINEFSYNC", "1"),
|
||||
("WINEFSYNC_FUTEX2", "1")
|
||||
])
|
||||
}
|
||||
}
|
||||
}
|
|
@ -96,7 +96,7 @@ pub fn run(debug: bool) -> Result<(), Error> {
|
|||
}
|
||||
|
||||
command.env("WINEPREFIX", &config.game.wine.prefix);
|
||||
command.envs(config.get_wine_sync_env_vars());
|
||||
command.envs(config.game.wine.sync.get_env_vars());
|
||||
|
||||
command.envs(config.game.environment)
|
||||
.current_dir(config.game.path)
|
||||
|
|
|
@ -12,7 +12,8 @@ pub struct Page {
|
|||
|
||||
pub hud_combo: adw::ComboRow,
|
||||
pub sync_combo: adw::ComboRow,
|
||||
pub fsr_combo: adw::ComboRow
|
||||
pub fsr_combo: adw::ComboRow,
|
||||
pub fsr_switcher: gtk::Switch
|
||||
}
|
||||
|
||||
impl Page {
|
||||
|
@ -24,7 +25,8 @@ impl Page {
|
|||
|
||||
hud_combo: get_object(&builder, "hud_combo")?,
|
||||
sync_combo: get_object(&builder, "sync_combo")?,
|
||||
fsr_combo: get_object(&builder, "fsr_combo")?
|
||||
fsr_combo: get_object(&builder, "fsr_combo")?,
|
||||
fsr_switcher: get_object(&builder, "fsr_switcher")?
|
||||
};
|
||||
|
||||
// Wine HUD selection
|
||||
|
@ -37,6 +39,36 @@ impl Page {
|
|||
}
|
||||
});
|
||||
|
||||
// Wine sync selection
|
||||
result.sync_combo.connect_selected_notify(|hud| {
|
||||
if let Ok(mut config) = config::get() {
|
||||
// TODO: show toast
|
||||
config.game.wine.sync = config::WineSync::try_from(hud.selected()).unwrap();
|
||||
|
||||
config::update(config).unwrap();
|
||||
}
|
||||
});
|
||||
|
||||
// FSR strength selection
|
||||
result.fsr_combo.connect_selected_notify(|hud| {
|
||||
if let Ok(mut config) = config::get() {
|
||||
// TODO: show toast
|
||||
config.game.enhancements.fsr.strength = hud.selected();
|
||||
|
||||
config::update(config).unwrap();
|
||||
}
|
||||
});
|
||||
|
||||
// FSR switcher changing
|
||||
result.fsr_switcher.connect_state_notify(|switcher| {
|
||||
if let Ok(mut config) = config::get() {
|
||||
// TODO: show toast
|
||||
config.game.enhancements.fsr.enabled = switcher.state();
|
||||
|
||||
config::update(config).unwrap();
|
||||
}
|
||||
});
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
|
@ -51,6 +83,15 @@ impl Page {
|
|||
// Update Wine HUD
|
||||
self.hud_combo.set_selected(config.game.enhancements.hud.into());
|
||||
|
||||
// Update Wine sync
|
||||
self.sync_combo.set_selected(config.game.wine.sync.into());
|
||||
|
||||
// FSR strength selection
|
||||
self.fsr_combo.set_selected(config.game.enhancements.fsr.strength);
|
||||
|
||||
// FSR switcher changing
|
||||
self.fsr_switcher.set_state(config.game.enhancements.fsr.enabled);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue