is_changing_state

This commit is contained in:
griffi-gh 2023-02-10 03:03:00 +01:00
parent 8e9eeb1f30
commit aada43e8dc
2 changed files with 13 additions and 9 deletions

View file

@ -2,7 +2,7 @@ use shipyard::{UniqueView, UniqueViewMut, Workload, IntoWorkload, WorkloadModifi
use glam::{Mat3, vec2}; use glam::{Mat3, vec2};
use crate::{ use crate::{
world::ChunkStorage, world::ChunkStorage,
state::{GameState, NextState}, state::{GameState, NextState, is_changing_state},
transform::Transform2d, transform::Transform2d,
gui::{ gui::{
GuiComponent, GuiComponent,
@ -72,15 +72,13 @@ fn switch_to_ingame_if_loaded(
fn despawn_loading_screen_if_switching_state( fn despawn_loading_screen_if_switching_state(
mut storages: AllStoragesViewMut, mut storages: AllStoragesViewMut,
) { ) {
let next = *storages.borrow::<UniqueView<NextState>>().unwrap(); let state = storages.borrow::<UniqueView<NextState>>().unwrap().0.unwrap();
if let Some(state) = next.0 {
if state != GameState::LoadingWorld { if state != GameState::LoadingWorld {
let progress_bar = storages.borrow::<UniqueView<ProgressbarId>>().unwrap().0; let progress_bar = storages.borrow::<UniqueView<ProgressbarId>>().unwrap().0;
storages.delete_entity(progress_bar); storages.delete_entity(progress_bar);
storages.remove_unique::<ProgressbarId>().unwrap(); storages.remove_unique::<ProgressbarId>().unwrap();
} }
} }
}
pub fn update_loading_screen() -> Workload { pub fn update_loading_screen() -> Workload {
( (
@ -88,6 +86,6 @@ pub fn update_loading_screen() -> Workload {
resize_progress_bar.into_workload().run_if(if_resized), resize_progress_bar.into_workload().run_if(if_resized),
update_progress_bar_progress, update_progress_bar_progress,
switch_to_ingame_if_loaded, 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() ).into_workload()
} }

View file

@ -29,6 +29,12 @@ pub fn update_state(
*state = take(&mut next.0).unwrap_or(*state); *state = take(&mut next.0).unwrap_or(*state);
} }
pub fn is_changing_state(
state: UniqueView<NextState>
) -> bool {
state.0.is_some()
}
pub fn is_ingame( pub fn is_ingame(
state: UniqueView<GameState> state: UniqueView<GameState>
) -> bool { ) -> bool {