feat(wuwa): return back editions support
This commit is contained in:
parent
1e94edd76e
commit
8a00674501
7 changed files with 73 additions and 61 deletions
|
@ -42,7 +42,7 @@ impl ConfigExt for Config {
|
|||
#[inline]
|
||||
fn get() -> anyhow::Result<Self::Schema> {
|
||||
unsafe {
|
||||
match &CONFIG {
|
||||
match CONFIG.as_ref() {
|
||||
Some(config) => Ok(config.clone()),
|
||||
None => Self::get_raw()
|
||||
}
|
||||
|
|
|
@ -11,18 +11,20 @@ crate::config_impl_wine_schema!(launcher_dir);
|
|||
crate::config_impl_dxvk_schema!(launcher_dir);
|
||||
|
||||
pub mod enhancements;
|
||||
pub mod paths;
|
||||
|
||||
pub mod prelude {
|
||||
pub use super::Wine;
|
||||
pub use super::Dxvk;
|
||||
pub use super::enhancements::Enhancements;
|
||||
pub use super::paths::Paths;
|
||||
}
|
||||
|
||||
use prelude::*;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Game {
|
||||
pub path: PathBuf,
|
||||
pub path: Paths,
|
||||
pub wine: Wine,
|
||||
pub dxvk: Dxvk,
|
||||
pub enhancements: Enhancements,
|
||||
|
@ -33,10 +35,8 @@ pub struct Game {
|
|||
impl Default for Game {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
let launcher_dir = launcher_dir().expect("Failed to get launcher dir");
|
||||
|
||||
Self {
|
||||
path: launcher_dir.join("Wuthering Waves"),
|
||||
path: Paths::default(),
|
||||
wine: Wine::default(),
|
||||
dxvk: Dxvk::default(),
|
||||
enhancements: Enhancements::default(),
|
||||
|
@ -51,13 +51,9 @@ impl From<&JsonValue> for Game {
|
|||
let default = Self::default();
|
||||
|
||||
Self {
|
||||
path: match value.get("path") {
|
||||
Some(value) => match value.as_str() {
|
||||
Some(value) => PathBuf::from(value),
|
||||
None => default.path
|
||||
},
|
||||
None => default.path
|
||||
},
|
||||
path: value.get("path")
|
||||
.map(Paths::from)
|
||||
.unwrap_or(default.path),
|
||||
|
||||
wine: value.get("wine")
|
||||
.map(Wine::from)
|
||||
|
|
60
src/games/wuwa/config/schema/game/paths.rs
Normal file
60
src/games/wuwa/config/schema/game/paths.rs
Normal file
|
@ -0,0 +1,60 @@
|
|||
use std::path::{Path, PathBuf};
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde_json::Value as JsonValue;
|
||||
|
||||
use anime_game_core::wuwa::consts::GameEdition;
|
||||
|
||||
use crate::wuwa::consts::launcher_dir;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Paths {
|
||||
pub global: PathBuf,
|
||||
pub china: PathBuf
|
||||
}
|
||||
|
||||
impl Paths {
|
||||
#[inline]
|
||||
/// Get game path for given edition
|
||||
pub fn for_edition(&self, edition: impl Into<GameEdition>) -> &Path {
|
||||
match edition.into() {
|
||||
GameEdition::Global => self.global.as_path(),
|
||||
GameEdition::China => self.china.as_path()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Paths {
|
||||
fn default() -> Self {
|
||||
let launcher_dir = launcher_dir().expect("Failed to get launcher dir");
|
||||
|
||||
Self {
|
||||
global: launcher_dir.join("Wuthering Waves"),
|
||||
china: launcher_dir.join("Wuthering Waves China")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&JsonValue> for Paths {
|
||||
fn from(value: &JsonValue) -> Self {
|
||||
let default = Self::default();
|
||||
|
||||
Self {
|
||||
global: match value.get("global") {
|
||||
Some(value) => match value.as_str() {
|
||||
Some(value) => PathBuf::from(value),
|
||||
None => default.global
|
||||
},
|
||||
None => default.global
|
||||
},
|
||||
|
||||
china: match value.get("china") {
|
||||
Some(value) => match value.as_str() {
|
||||
Some(value) => PathBuf::from(value),
|
||||
None => default.china
|
||||
},
|
||||
None => default.china
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,7 +19,6 @@ use crate::components::{
|
|||
|
||||
pub mod launcher;
|
||||
pub mod game;
|
||||
pub mod patch;
|
||||
|
||||
#[cfg(feature = "components")]
|
||||
pub mod components;
|
||||
|
@ -28,7 +27,6 @@ pub mod prelude {
|
|||
pub use super::launcher::prelude::*;
|
||||
pub use super::game::prelude::*;
|
||||
pub use super::game::*;
|
||||
pub use super::patch::*;
|
||||
|
||||
#[cfg(feature = "components")]
|
||||
pub use super::components::*;
|
||||
|
@ -45,9 +43,7 @@ pub struct Schema {
|
|||
pub sandbox: Sandbox,
|
||||
|
||||
#[cfg(feature = "components")]
|
||||
pub components: Components,
|
||||
|
||||
pub patch: Patch
|
||||
pub components: Components
|
||||
}
|
||||
|
||||
impl From<&JsonValue> for Schema {
|
||||
|
@ -75,11 +71,6 @@ impl From<&JsonValue> for Schema {
|
|||
components: match value.get("components") {
|
||||
Some(value) => Components::from(value),
|
||||
None => default.components
|
||||
},
|
||||
|
||||
patch: match value.get("patch") {
|
||||
Some(value) => Patch::from(value),
|
||||
None => default.patch
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde_json::Value as JsonValue;
|
||||
|
||||
use crate::wuwa::consts::launcher_dir;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Patch {
|
||||
pub path: PathBuf
|
||||
}
|
||||
|
||||
impl Default for Patch {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
let launcher_dir = launcher_dir().expect("Failed to get launcher dir");
|
||||
|
||||
Self {
|
||||
path: launcher_dir.join("patch")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&JsonValue> for Patch {
|
||||
fn from(value: &JsonValue) -> Self {
|
||||
let default = Self::default();
|
||||
|
||||
Self {
|
||||
path: match value.get("path").and_then(|path| path.as_str()).map(PathBuf::from) {
|
||||
Some(path) => path,
|
||||
None => default.path
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -50,7 +50,7 @@ pub fn run() -> anyhow::Result<()> {
|
|||
|
||||
let config = Config::get()?;
|
||||
|
||||
if !config.game.path.exists() {
|
||||
if !config.game.path.for_edition(config.launcher.edition).exists() {
|
||||
return Err(anyhow::anyhow!("Game is not installed"));
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ pub fn run() -> anyhow::Result<()> {
|
|||
let mut folders = Folders {
|
||||
wine: config.game.wine.builds.join(&wine.name),
|
||||
prefix: config.game.wine.prefix.clone(),
|
||||
game: config.game.path.clone(),
|
||||
game: config.game.path.for_edition(config.launcher.edition).to_path_buf(),
|
||||
temp: config.launcher.temp.clone().unwrap_or(std::env::temp_dir())
|
||||
};
|
||||
|
||||
|
@ -232,7 +232,7 @@ pub fn run() -> anyhow::Result<()> {
|
|||
|
||||
// We use real current dir here because sandboxed one
|
||||
// obviously doesn't exist
|
||||
command.current_dir(&config.game.path)
|
||||
command.current_dir(&config.game.path.for_edition(config.launcher.edition))
|
||||
.spawn()?.wait_with_output()?;
|
||||
|
||||
#[cfg(feature = "discord-rpc")]
|
||||
|
|
|
@ -134,7 +134,7 @@ impl LauncherState {
|
|||
}
|
||||
|
||||
Self::get(LauncherStateParams {
|
||||
game_path: config.game.path.clone(),
|
||||
game_path: config.game.path.for_edition(config.launcher.edition).to_path_buf(),
|
||||
game_edition: config.launcher.edition,
|
||||
|
||||
wine_prefix: config.get_wine_prefix_path(),
|
||||
|
|
Loading…
Reference in a new issue