-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloading.rs
More file actions
44 lines (38 loc) · 1.25 KB
/
loading.rs
File metadata and controls
44 lines (38 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//! A loading screen during which game assets are loaded.
//! This reduces stuttering, especially for audio on WASM.
use bevy::prelude::*;
use super::Screen;
use crate::{
game::assets::{FontKey, HandleMap, ImageKey, SfxKey, SoundtrackKey},
ui::prelude::*,
};
pub(super) fn plugin(app: &mut App) {
app.add_systems(OnEnter(Screen::Loading), enter_loading);
app.add_systems(
Update,
continue_to_title.run_if(in_state(Screen::Loading).and_then(all_assets_loaded)),
);
}
fn enter_loading(mut commands: Commands) {
commands
.ui_root()
.insert(StateScoped(Screen::Loading))
.with_children(|children| {
children.label("Loading...");
});
}
fn all_assets_loaded(
asset_server: Res<AssetServer>,
image_handles: Res<HandleMap<ImageKey>>,
sfx_handles: Res<HandleMap<SfxKey>>,
soundtrack_handles: Res<HandleMap<SoundtrackKey>>,
font_handles: Res<HandleMap<FontKey>>,
) -> bool {
image_handles.all_loaded(&asset_server)
&& sfx_handles.all_loaded(&asset_server)
&& soundtrack_handles.all_loaded(&asset_server)
&& font_handles.all_loaded(&asset_server)
}
fn continue_to_title(mut next_screen: ResMut<NextState<Screen>>) {
next_screen.set(Screen::Title);
}