use crate::prelude::*; pub(crate) struct LoadingPlugin; impl Plugin for LoadingPlugin { fn build(&self, app: &mut App) { app.add_systems(Startup, initialize) .add_systems(Update, loading.run_if(in_state(GameState::Loading))) .add_systems(OnEnter(GameState::Loading), enter_loading) .add_systems(OnExit(GameState::Loading), exit_loading); } } #[derive(Debug, Component, PartialEq)] struct Loading; // TODO: Why is this image not showing?? fn initialize(mut commands: Commands, server: Res) { commands.spawn((Loading, GameState::Loading, Camera2dBundle { ..default() })); commands.spawn(( Loading, GameState::Loading, ImageBundle { image: UiImage { texture: server.load("images/Liquid Mirror.jpg"), ..default() }, style: Style { width: Val::Percent(100.0), height: Val::Percent(100.0), ..default() }, visibility: Visibility::Hidden, ..default() }, )); } /// On enter loading, activate camera fn enter_loading(mut cameras: Query<&mut Camera, With>) { cameras .iter_mut() .for_each(|mut camera| camera.is_active = true); } /// On exit loading, deactivate camera /// This used to be general purpose, but we got rid of the 2d display mode, so it is hard coded for loading -> main game fn exit_loading(mut cameras: Query<&mut Camera, With>) { cameras .iter_mut() .for_each(|mut camera| camera.is_active = false); } fn loading( server: Res, images: Res>, gltfs: Res>, tweaks: Res>, fonts: Res>, mut next_state: ResMut>, time: Res