delete the map
Some checks failed
Rust Checks / checks (push) Has been cancelled
Rust Checks / checks (pull_request) Failing after 1m33s

This commit is contained in:
CoCo_Sol 2024-02-17 21:42:38 +01:00
parent e3c2bc1ac9
commit 1350b04e29

View file

@ -11,10 +11,13 @@ pub struct MapGenerationPlugin;
impl Plugin for MapGenerationPlugin {
fn build(&self, app: &mut App) {
app.add_event::<MapGenerationEvent>().add_systems(
Update,
generate_map.run_if(in_state(crate::CurrentScene::Game)),
);
app.add_event::<MapGenerationEvent>()
.add_event::<EndMapGenerationEvent>()
.add_systems(
Update,
(generate_map.after(delete_map), delete_map)
.run_if(in_state(crate::CurrentScene::Game)),
);
}
}
@ -68,3 +71,15 @@ fn get_type_tile(position: (f32, f32), noise: &Perlin) -> Tile {
_ => Tile::Grass,
}
}
fn delete_map(
mut commands: Commands,
query: Query<Entity, With<Tile>>,
mut event: EventReader<EndMapGenerationEvent>,
) {
for _ in event.read() {
for entity in query.iter() {
commands.entity(entity).despawn_recursive();
}
}
}