#![allow(clippy::too_many_arguments)] mod game_over; mod level0; mod level1; use crate::game::*; use bevy::prelude::*; use bevy_hanabi::*; use std::collections::BTreeSet; 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) .insert(SelectedCharacterId(None)) .insert(CharacterIdList(BTreeSet::new())) .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 effects: ResMut>, mut materials: ResMut>, current_level: Res, mut level_query: Query<(&mut SelectedCharacterId, &mut CharacterIdList)>, mut level_startup_event: EventReader, asset_server: Res, audio: Res>, ) { for LevelStartupEvent(level_entity) in level_startup_event.iter() { if let Ok((mut selected_character_id, mut character_id_list)) = level_query.get_mut(*level_entity) { if let Some(level_id) = current_level.0 { match level_id.0 { 0 => level0::setup( &mut commands, &character_meshes, &mut effects, &mut materials, &mut selected_character_id, &mut character_id_list, &audio, ), 1 => level1::setup( &mut commands, &character_meshes, &mut effects, &mut materials, &mut selected_character_id, &mut character_id_list, &audio, ), _ => game_over::setup(&mut commands, &asset_server), } } } } }