From 6296005c515c963c0c5acb783099054e71ad6f02 Mon Sep 17 00:00:00 2001 From: vE5li Date: Fri, 1 Mar 2024 09:54:34 +0100 Subject: [PATCH] Show default theme when trying to load an invalid theme --- src/interface/mod.rs | 12 +++++------- src/interface/theme.rs | 27 +++++++-------------------- 2 files changed, 12 insertions(+), 27 deletions(-) diff --git a/src/interface/mod.rs b/src/interface/mod.rs index 318a2576..00a4a476 100644 --- a/src/interface/mod.rs +++ b/src/interface/mod.rs @@ -203,15 +203,13 @@ impl Interface { #[profile] pub fn reload_theme(&mut self, kind: ThemeKind) { - let success = match kind { - ThemeKind::Menu => self.themes.menu.reload(self.interface_settings.menu_theme.get_file()), - ThemeKind::Main => self.themes.main.reload(self.interface_settings.main_theme.get_file()), + match kind { + ThemeKind::Menu => self.themes.menu.reload::(self.interface_settings.menu_theme.get_file()), + ThemeKind::Main => self.themes.main.reload::
(self.interface_settings.main_theme.get_file()), ThemeKind::Game => self.themes.game.reload(self.interface_settings.game_theme.get_file()), - }; - - if success { - self.post_update.resolve(); } + + self.post_update.resolve(); } pub fn schedule_render(&mut self) { diff --git a/src/interface/theme.rs b/src/interface/theme.rs index 0b4e3017..29ec4fbd 100644 --- a/src/interface/theme.rs +++ b/src/interface/theme.rs @@ -840,16 +840,11 @@ impl InterfaceTheme { std::fs::read_to_string(theme_file).ok().and_then(|data| ron::from_str(&data).ok()) } - pub fn reload(&mut self, theme_file: &str) -> bool { - let Some(theme) = Self::load(theme_file) else { - #[cfg(feature = "debug")] - print_debug!("failed to load theme from file {}{}{}", MAGENTA, theme_file, NONE); - - return false; - }; - - *self = theme; - true + pub fn reload(&mut self, theme_file: &str) + where + Self: ThemeDefault, + { + *self = Self::new::(theme_file); } pub fn save(&self, theme_file: &str) { @@ -878,16 +873,8 @@ impl GameTheme { std::fs::read_to_string(theme_file).ok().and_then(|data| ron::from_str(&data).ok()) } - pub fn reload(&mut self, theme_file: &str) -> bool { - let Some(theme) = Self::load(theme_file) else { - #[cfg(feature = "debug")] - print_debug!("failed to load theme from file {}{}{}", MAGENTA, theme_file, NONE); - - return false; - }; - - *self = theme; - true + pub fn reload(&mut self, theme_file: &str) { + *self = Self::new(theme_file); } pub fn save(&self, theme_file: &str) {