Skip to content

Commit

Permalink
Show default theme when trying to load an invalid theme
Browse files Browse the repository at this point in the history
  • Loading branch information
vE5li committed Mar 1, 2024
1 parent ce21d3e commit 6296005
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 27 deletions.
12 changes: 5 additions & 7 deletions src/interface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Menu>(self.interface_settings.menu_theme.get_file()),
ThemeKind::Main => self.themes.main.reload::<Main>(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) {
Expand Down
27 changes: 7 additions & 20 deletions src/interface/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: ThemeType>(&mut self, theme_file: &str)
where
Self: ThemeDefault<T>,
{
*self = Self::new::<T>(theme_file);
}

pub fn save(&self, theme_file: &str) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 6296005

Please sign in to comment.