diff --git a/src/demo/level.rs b/src/demo/level.rs index c420ba9..6bf1b88 100644 --- a/src/demo/level.rs +++ b/src/demo/level.rs @@ -10,17 +10,11 @@ pub(super) fn plugin(_app: &mut App) { // later if needed. } -#[derive(Debug)] -pub struct SpawnLevel; - -impl Command for SpawnLevel { - fn apply(self, world: &mut World) { - // The only thing we have in our level is a player, - // but add things like walls etc. here. - world.commands().add(SpawnPlayer { max_speed: 400.0 }); - - // Flush the commands we just added so that they are - // all executed now, as part of this command. - world.flush_commands(); - } +/// A [`Command`] to spawn the level. +/// Functions that accept only `&mut World` as their parameter implement [`Command`]. +/// We use this style when a command requires no configuration. +pub fn spawn_level(world: &mut World) { + // The only thing we have in our level is a player, + // but add things like walls etc. here. + SpawnPlayer { max_speed: 400.0 }.apply(world); } diff --git a/src/screens/playing.rs b/src/screens/playing.rs index 2cef332..c6d322b 100644 --- a/src/screens/playing.rs +++ b/src/screens/playing.rs @@ -3,7 +3,9 @@ use bevy::{input::common_conditions::input_just_pressed, prelude::*}; use super::Screen; -use crate::{asset_tracking::LoadResource, audio::Music, demo::level::SpawnLevel}; +use crate::{ + asset_tracking::LoadResource, audio::Music, demo::level::spawn_level as spawn_level_command, +}; pub(super) fn plugin(app: &mut App) { app.load_resource::(); @@ -35,7 +37,7 @@ impl FromWorld for GameplayMusic { } fn spawn_level(mut commands: Commands, mut music: ResMut) { - commands.add(SpawnLevel); + commands.add(spawn_level_command); music.entity = Some( commands .spawn((