Skip to content

Commit

Permalink
fix: fix crash in web build due to trying to set fullscreen mode. (#860)
Browse files Browse the repository at this point in the history
  • Loading branch information
zicklag authored Oct 16, 2023
1 parent f81431d commit 2405835
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
1 change: 1 addition & 0 deletions assets/locales/en-US/settings.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
32 changes: 19 additions & 13 deletions src/fullscreen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,26 @@ pub fn game_plugin(game: &mut Game) {
}

fn update_fullscreen(game: &mut Game) {
let storage = game.shared_resource_cell::<Storage>().unwrap();
let mut storage = storage.borrow_mut();
let window = game.shared_resource_cell::<Window>().unwrap();
let mut window = window.borrow_mut();
let keyboard = game.shared_resource::<KeyboardInputs>().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::<Storage>().unwrap();
let mut storage = storage.borrow_mut();
let window = game.shared_resource_cell::<Window>().unwrap();
let mut window = window.borrow_mut();
let keyboard = game.shared_resource::<KeyboardInputs>().unwrap();

let settings = storage.get_mut::<Settings>().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::<Settings>().unwrap();
if f11_pressed {
settings.fullscreen = !settings.fullscreen;
}
window.fullscreen = settings.fullscreen;
}
window.fullscreen = settings.fullscreen;
}
4 changes: 4 additions & 0 deletions src/ui/main_menu/settings/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ 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(
&mut state.modified_settings.fullscreen,
normal_font.rich(localization.get("fullscreen")),
);
});

#[cfg(target_arch = "wasm32")]
ui.label(normal_font.rich(localization.get("no-graphics-settings-on-web")));
}

0 comments on commit 2405835

Please sign in to comment.