feat(honkai): added multi-regional support

This commit is contained in:
Observer KRypt0n_ 2023-08-03 16:49:21 +02:00
parent 1669dceafc
commit d72eb796cf
No known key found for this signature in database
GPG key ID: 844DA47BA25FE1E2
4 changed files with 19 additions and 7 deletions

View file

@ -9,7 +9,7 @@ edition = "2021"
[dependencies.anime-game-core] [dependencies.anime-game-core]
git = "https://github.com/an-anime-team/anime-game-core" git = "https://github.com/an-anime-team/anime-game-core"
tag = "1.13.5" tag = "1.14.0"
features = ["all"] features = ["all"]
# path = "../anime-game-core" # ! for dev purposes only # path = "../anime-game-core" # ! for dev purposes only

View file

@ -5,12 +5,14 @@ use serde_json::Value as JsonValue;
use enum_ordinalize::Ordinalize; use enum_ordinalize::Ordinalize;
#[cfg(feature = "discord-rpc")] use anime_game_core::honkai::consts::GameEdition;
pub mod discord_rpc;
use crate::config::schema_blanks::prelude::*; use crate::config::schema_blanks::prelude::*;
use crate::honkai::consts::launcher_dir; use crate::honkai::consts::launcher_dir;
#[cfg(feature = "discord-rpc")]
pub mod discord_rpc;
pub mod prelude { pub mod prelude {
pub use super::{ pub use super::{
Launcher, Launcher,
@ -54,6 +56,7 @@ impl Default for LauncherBehavior {
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Launcher { pub struct Launcher {
pub language: String, pub language: String,
pub edition: GameEdition,
pub style: LauncherStyle, pub style: LauncherStyle,
pub temp: Option<PathBuf>, pub temp: Option<PathBuf>,
pub repairer: Repairer, pub repairer: Repairer,
@ -69,6 +72,7 @@ impl Default for Launcher {
fn default() -> Self { fn default() -> Self {
Self { Self {
language: String::from("en-us"), language: String::from("en-us"),
edition: GameEdition::from_system_lang(),
style: LauncherStyle::default(), style: LauncherStyle::default(),
temp: launcher_dir().ok(), temp: launcher_dir().ok(),
repairer: Repairer::default(), repairer: Repairer::default(),
@ -91,6 +95,11 @@ impl From<&JsonValue> for Launcher {
None => default.language None => default.language
}, },
edition: match value.get("edition") {
Some(value) => serde_json::from_value(value.clone()).unwrap_or(default.edition),
None => default.edition
},
style: match value.get("style") { style: match value.get("style") {
Some(value) => serde_json::from_value(value.to_owned()).unwrap_or_default(), Some(value) => serde_json::from_value(value.to_owned()).unwrap_or_default(),
None => default.style None => default.style

View file

@ -69,7 +69,7 @@ pub fn run() -> anyhow::Result<()> {
tracing::info!("Checking telemetry"); tracing::info!("Checking telemetry");
if let Ok(Some(server)) = telemetry::is_disabled() { if let Ok(Some(server)) = telemetry::is_disabled(config.launcher.edition) {
return Err(anyhow::anyhow!("Telemetry server is not disabled: {server}")); return Err(anyhow::anyhow!("Telemetry server is not disabled: {server}"));
} }

View file

@ -4,6 +4,7 @@ use anime_game_core::prelude::*;
use anime_game_core::honkai::prelude::*; use anime_game_core::honkai::prelude::*;
use crate::config::ConfigExt; use crate::config::ConfigExt;
use crate::honkai::config::Config;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum LauncherState { pub enum LauncherState {
@ -42,6 +43,7 @@ pub enum StateUpdating {
pub struct LauncherStateParams<F: Fn(StateUpdating)> { pub struct LauncherStateParams<F: Fn(StateUpdating)> {
pub wine_prefix: PathBuf, pub wine_prefix: PathBuf,
pub game_path: PathBuf, pub game_path: PathBuf,
pub game_edition: GameEdition,
pub patch_folder: PathBuf, pub patch_folder: PathBuf,
pub apply_mfplat: bool, pub apply_mfplat: bool,
@ -61,7 +63,7 @@ impl LauncherState {
// Check game installation status // Check game installation status
(params.status_updater)(StateUpdating::Game); (params.status_updater)(StateUpdating::Game);
let game = Game::new(&params.game_path, ()); let game = Game::new(&params.game_path, params.game_edition);
let diff = game.try_get_diff()?; let diff = game.try_get_diff()?;
@ -88,7 +90,7 @@ impl LauncherState {
} }
// Check telemetry servers // Check telemetry servers
let disabled = telemetry::is_disabled() let disabled = telemetry::is_disabled(params.game_edition)
// Return true if there's no domain name resolved, or false otherwise // Return true if there's no domain name resolved, or false otherwise
.map(|result| result.is_none()) .map(|result| result.is_none())
@ -123,7 +125,7 @@ impl LauncherState {
pub fn get_from_config<T: Fn(StateUpdating)>(status_updater: T) -> anyhow::Result<Self> { pub fn get_from_config<T: Fn(StateUpdating)>(status_updater: T) -> anyhow::Result<Self> {
tracing::debug!("Trying to get launcher state"); tracing::debug!("Trying to get launcher state");
let config = crate::honkai::config::Config::get()?; let config = Config::get()?;
match &config.game.wine.selected { match &config.game.wine.selected {
#[cfg(feature = "components")] #[cfg(feature = "components")]
@ -137,6 +139,7 @@ impl LauncherState {
Self::get(LauncherStateParams { Self::get(LauncherStateParams {
wine_prefix: config.get_wine_prefix_path(), wine_prefix: config.get_wine_prefix_path(),
game_path: config.game.path, game_path: config.game.path,
game_edition: config.launcher.edition,
patch_folder: config.patch.path, patch_folder: config.patch.path,
apply_mfplat: config.patch.apply_mfplat, apply_mfplat: config.patch.apply_mfplat,