From 50ff8881413f3ed8c8e775892bf7dec51c0c3c7b Mon Sep 17 00:00:00 2001 From: biroder <107300789+biroder@users.noreply.github.com> Date: Mon, 29 May 2023 10:42:34 +0300 Subject: [PATCH] Fix #208 and add a different log level for file logging --- src/engine_constants/mod.rs | 4 ++++ src/game/mod.rs | 14 +++++++++++--- src/game/shared_game_state.rs | 16 ++++++++-------- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/engine_constants/mod.rs b/src/engine_constants/mod.rs index 585b468..0e16c8c 100644 --- a/src/engine_constants/mod.rs +++ b/src/engine_constants/mod.rs @@ -1759,6 +1759,10 @@ impl EngineConstants { let _ = sound_manager.set_sample_params(2, typewriter_sample); } + pub fn is_base(&self) -> bool { + !self.is_switch && !self.is_cs_plus && !self.is_demo + } + pub fn apply_csplus_nx_patches(&mut self) { log::info!("Applying Switch-specific Cave Story+ constants patches..."); diff --git a/src/game/mod.rs b/src/game/mod.rs index 1ce43a0..c7dbab5 100644 --- a/src/game/mod.rs +++ b/src/game/mod.rs @@ -267,8 +267,12 @@ fn init_logger() -> GameResult { message )) }) - .level(log::LevelFilter::Info) - .chain(std::io::stderr()); + .level(log::LevelFilter::Debug) + .chain( + fern::Dispatch::new() + .level(log::LevelFilter::Info) + .chain(std::io::stderr()) + ); let date = chrono::Utc::now(); @@ -276,7 +280,11 @@ fn init_logger() -> GameResult { file.push(format!("log_{}", date.format("%Y-%m-%d"))); file.set_extension("txt"); - dispatcher = dispatcher.chain(fern::log_file(file).unwrap()); + dispatcher = dispatcher.chain( + fern::Dispatch::new() + .level(log::LevelFilter::Debug) + .chain(fern::log_file(file).unwrap()) + ); dispatcher.apply()?; //log::info!("===GAME LAUNCH==="); diff --git a/src/game/shared_game_state.rs b/src/game/shared_game_state.rs index d26f2fc..afad837 100644 --- a/src/game/shared_game_state.rs +++ b/src/game/shared_game_state.rs @@ -409,11 +409,11 @@ impl SharedGameState { constants.load_locales(ctx)?; let locale = SharedGameState::get_locale(&constants, &settings.locale).unwrap_or_default(); - constants.textscript.encoding = if locale.code == "jp" && !constants.is_switch { - TextScriptEncoding::ShiftJIS + if (locale.code == "jp" || locale.code == "en") && constants.is_base() { + constants.textscript.encoding = TextScriptEncoding::ShiftJIS } else { - TextScriptEncoding::UTF8 - }; + constants.textscript.encoding = TextScriptEncoding::UTF8 + } let font = BMFont::load(&constants.base_paths, &locale.font.path, ctx, locale.font.scale).or_else(|e| { log::warn!("Failed to load font, using built-in: {}", e); @@ -561,11 +561,11 @@ impl SharedGameState { pub fn update_locale(&mut self, ctx: &mut Context) { if let Some(locale) = SharedGameState::get_locale(&self.constants, &self.settings.locale) { self.loc = locale; - self.constants.textscript.encoding = if self.loc.code == "jp" && !self.constants.is_switch { - TextScriptEncoding::ShiftJIS + if (self.loc.code == "jp" || self.loc.code == "en") && self.constants.is_base() { + self.constants.textscript.encoding = TextScriptEncoding::ShiftJIS } else { - TextScriptEncoding::UTF8 - }; + self.constants.textscript.encoding = TextScriptEncoding::UTF8 + } } let font = BMFont::load(&self.constants.base_paths, &self.loc.font.path, ctx, self.loc.font.scale)