#![allow(clippy::too_many_arguments)] mod game_over; mod level0; mod level1; use crate::game::*; use bevy::prelude::*; pub fn setup_level( commands: &mut Commands, current_level: &mut ResMut, level_startup_event: &mut EventWriter, camera_query: &mut Query<&mut Transform, With>, level_id: LevelId, ) { let level_entity = commands.spawn().insert(Level).id(); current_level.0 = Some(level_id); camera_query.single_mut().translation = Default::default(); level_startup_event.send(LevelStartupEvent(level_entity)); } pub fn despawn_level(mut commands: Commands, level_query: Query>) { for entity in level_query.iter() { commands.entity(entity).despawn_recursive(); } } // This is a bad design, to be refactored some days pub fn post_setup_level( mut commands: Commands, character_meshes: Res, mut meshes: ResMut>, mut materials: ResMut>, current_level: Res, mut level_startup_event: EventReader, asset_server: Res, audio: Res>, ) { for LevelStartupEvent(_level_entity) in level_startup_event.iter() { if let Some(level_id) = current_level.0 { match level_id.0 { 0 => level0::setup( &mut commands, &mut meshes, &character_meshes, &mut materials, &audio, ), 1 => level1::setup( &mut commands, &mut meshes, &character_meshes, &mut materials, &audio, ), _ => game_over::setup(&mut commands, &asset_server), } } } }