generated from tipragot/rust
delete the map
This commit is contained in:
parent
e3c2bc1ac9
commit
1350b04e29
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue