game states cleanup

This commit is contained in:
2026-09-19 10:53:36 +02:00
parent 9df830bf18
commit d42f5af75f
7 changed files with 74 additions and 20 deletions
+9 -1
View File
@@ -57,11 +57,19 @@ fn spawn_chunk(commands: &mut Commands, id: i64, run_seed: u64) {
crate::background::spawn_background_chunk(commands, id);
// crate::obstacle::spawn_obstacle_chunk(commands, id, run_seed);
}
fn cleanup_chunk(mut commands: Commands, entities: Query<Entity, With<Chunk>>) {
for entity in entities {
commands.entity(entity).despawn();
}
}
pub struct WorldPlugin;
impl Plugin for WorldPlugin {
fn build(&self, app: &mut App) {
app.insert_resource(RunSeed(rand::random::<u64>()))
.add_systems(Update, stream_world.run_if(in_state(GameState::InGame)));
.add_systems(Update, stream_world.run_if(in_state(GameState::InGame)))
.add_systems(OnExit(GameState::InGame), cleanup_chunk);
}
}