2022-08-23 10:02:58 +00:00
|
|
|
#![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<CurrentLevel>,
|
|
|
|
level_startup_event: &mut EventWriter<LevelStartupEvent>,
|
|
|
|
level_id: LevelId,
|
|
|
|
) {
|
|
|
|
let level_entity = commands
|
|
|
|
.spawn()
|
|
|
|
.insert(Level)
|
|
|
|
.insert(SelectedCharacterId(None))
|
|
|
|
.insert(CharacterIdList(BTreeSet::new()))
|
|
|
|
.id();
|
|
|
|
current_level.0 = Some(level_id);
|
|
|
|
|
|
|
|
level_startup_event.send(LevelStartupEvent(level_entity));
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn despawn_level(mut commands: Commands, level_query: Query<Entity, With<Level>>) {
|
|
|
|
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<CharacterMeshes>,
|
|
|
|
mut effects: ResMut<Assets<EffectAsset>>,
|
|
|
|
mut materials: ResMut<Assets<ColorMaterial>>,
|
|
|
|
current_level: Res<CurrentLevel>,
|
|
|
|
mut level_query: Query<(&mut SelectedCharacterId, &mut CharacterIdList)>,
|
|
|
|
mut level_startup_event: EventReader<LevelStartupEvent>,
|
|
|
|
asset_server: Res<AssetServer>,
|
2022-08-23 15:02:13 +00:00
|
|
|
audio: Res<crossbeam_channel::Sender<AudioMsg>>,
|
2022-08-23 10:02:58 +00:00
|
|
|
) {
|
|
|
|
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,
|
2022-08-23 15:02:13 +00:00
|
|
|
&audio,
|
2022-08-23 10:02:58 +00:00
|
|
|
),
|
|
|
|
1 => level1::setup(
|
|
|
|
&mut commands,
|
|
|
|
&character_meshes,
|
|
|
|
&mut effects,
|
|
|
|
&mut materials,
|
|
|
|
&mut selected_character_id,
|
|
|
|
&mut character_id_list,
|
2022-08-23 15:02:13 +00:00
|
|
|
&audio,
|
2022-08-23 10:02:58 +00:00
|
|
|
),
|
|
|
|
_ => game_over::setup(&mut commands, &asset_server),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|