From aada43e8dc557aa8e35d5b4b2db37569f38b5d26 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Fri, 10 Feb 2023 03:03:00 +0100 Subject: [PATCH] is_changing_state --- kubi/src/loading_screen.rs | 16 +++++++--------- kubi/src/state.rs | 6 ++++++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/kubi/src/loading_screen.rs b/kubi/src/loading_screen.rs index eb323a1..585a009 100644 --- a/kubi/src/loading_screen.rs +++ b/kubi/src/loading_screen.rs @@ -2,7 +2,7 @@ use shipyard::{UniqueView, UniqueViewMut, Workload, IntoWorkload, WorkloadModifi use glam::{Mat3, vec2}; use crate::{ world::ChunkStorage, - state::{GameState, NextState}, + state::{GameState, NextState, is_changing_state}, transform::Transform2d, gui::{ GuiComponent, @@ -72,13 +72,11 @@ fn switch_to_ingame_if_loaded( fn despawn_loading_screen_if_switching_state( mut storages: AllStoragesViewMut, ) { - let next = *storages.borrow::>().unwrap(); - if let Some(state) = next.0 { - if state != GameState::LoadingWorld { - let progress_bar = storages.borrow::>().unwrap().0; - storages.delete_entity(progress_bar); - storages.remove_unique::().unwrap(); - } + let state = storages.borrow::>().unwrap().0.unwrap(); + if state != GameState::LoadingWorld { + let progress_bar = storages.borrow::>().unwrap().0; + storages.delete_entity(progress_bar); + storages.remove_unique::().unwrap(); } } @@ -88,6 +86,6 @@ pub fn update_loading_screen() -> Workload { resize_progress_bar.into_workload().run_if(if_resized), update_progress_bar_progress, switch_to_ingame_if_loaded, - despawn_loading_screen_if_switching_state, + despawn_loading_screen_if_switching_state.into_workload().run_if(is_changing_state), ).into_workload() } diff --git a/kubi/src/state.rs b/kubi/src/state.rs index 305f7c4..3301964 100644 --- a/kubi/src/state.rs +++ b/kubi/src/state.rs @@ -29,6 +29,12 @@ pub fn update_state( *state = take(&mut next.0).unwrap_or(*state); } +pub fn is_changing_state( + state: UniqueView +) -> bool { + state.0.is_some() +} + pub fn is_ingame( state: UniqueView ) -> bool {