From 2405835e9353409332088abbcf929f27f79cd2b8 Mon Sep 17 00:00:00 2001 From: Zicklag Date: Mon, 16 Oct 2023 16:08:40 +0000 Subject: [PATCH] fix: fix crash in web build due to trying to set fullscreen mode. (#860) --- assets/locales/en-US/settings.ftl | 1 + src/fullscreen.rs | 32 ++++++++++++++++----------- src/ui/main_menu/settings/graphics.rs | 4 ++++ 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/assets/locales/en-US/settings.ftl b/assets/locales/en-US/settings.ftl index 51b25d4e7e..2363951568 100644 --- a/assets/locales/en-US/settings.ftl +++ b/assets/locales/en-US/settings.ftl @@ -22,3 +22,4 @@ matchmaking-server = Matchmaking Server # Graphics settings graphics = Graphics fullscreen = Fullscreen +no-graphics-settings-on-web = There are no graphics settings on web. diff --git a/src/fullscreen.rs b/src/fullscreen.rs index ba1f6e0182..2f4d6e911f 100644 --- a/src/fullscreen.rs +++ b/src/fullscreen.rs @@ -5,20 +5,26 @@ pub fn game_plugin(game: &mut Game) { } fn update_fullscreen(game: &mut Game) { - let storage = game.shared_resource_cell::().unwrap(); - let mut storage = storage.borrow_mut(); - let window = game.shared_resource_cell::().unwrap(); - let mut window = window.borrow_mut(); - let keyboard = game.shared_resource::().unwrap(); + #[cfg(target_arch = "wasm32")] + let _ = game; - let f11_pressed = keyboard - .key_events - .iter() - .any(|x| x.key_code == Set(KeyCode::F11) && x.button_state.pressed()); + #[cfg(not(target_arch = "wasm32"))] + { + let storage = game.shared_resource_cell::().unwrap(); + let mut storage = storage.borrow_mut(); + let window = game.shared_resource_cell::().unwrap(); + let mut window = window.borrow_mut(); + let keyboard = game.shared_resource::().unwrap(); - let settings = storage.get_mut::().unwrap(); - if f11_pressed { - settings.fullscreen = !settings.fullscreen; + let f11_pressed = keyboard + .key_events + .iter() + .any(|x| x.key_code == Set(KeyCode::F11) && x.button_state.pressed()); + + let settings = storage.get_mut::().unwrap(); + if f11_pressed { + settings.fullscreen = !settings.fullscreen; + } + window.fullscreen = settings.fullscreen; } - window.fullscreen = settings.fullscreen; } diff --git a/src/ui/main_menu/settings/graphics.rs b/src/ui/main_menu/settings/graphics.rs index ee4797d885..7d5fa0496d 100644 --- a/src/ui/main_menu/settings/graphics.rs +++ b/src/ui/main_menu/settings/graphics.rs @@ -19,6 +19,7 @@ pub(super) fn widget( ui.add_space(normal_font.size / 2.0); + #[cfg(not(target_arch = "wasm32"))] ui.horizontal(|ui| { ui.add_space(normal_font.size * 3.0); ui.checkbox( @@ -26,4 +27,7 @@ pub(super) fn widget( normal_font.rich(localization.get("fullscreen")), ); }); + + #[cfg(target_arch = "wasm32")] + ui.label(normal_font.rich(localization.get("no-graphics-settings-on-web"))); }