diff --git a/hello-world/src/main.rs b/hello-world/src/main.rs index af93c3f..8879c12 100644 --- a/hello-world/src/main.rs +++ b/hello-world/src/main.rs @@ -1,36 +1,14 @@ use bevy::prelude::*; +mod people; + fn main() { App::new() - .add_systems(Startup, add_people) - .add_systems(Update, (hello_world, greet_people)) + .add_plugins((DefaultPlugins, people::Plugin)) + .add_systems(Startup, hello_world) .run(); } -#[derive(Component)] -struct Person; - -#[derive(Component)] -struct Name(String); - -impl Name { - fn new>(name: S) -> Self { - Self(name.into()) - } -} - -fn add_people(mut cmds: Commands) { - cmds.spawn((Person, Name::new("Elaina Proctor"))); - cmds.spawn((Person, Name::new("Renzo Hume"))); - cmds.spawn((Person, Name::new("Zayna Nieves"))); -} - fn hello_world() { println!("Hello, world!"); } - -fn greet_people(q: Query<&Name, With>) { - for name in &q { - println!("Hello, {}!", name.0); - } -} diff --git a/hello-world/src/people.rs b/hello-world/src/people.rs new file mode 100644 index 0000000..dd54fd9 --- /dev/null +++ b/hello-world/src/people.rs @@ -0,0 +1,38 @@ +use bevy::{ + app::{Startup, Update}, + prelude::{App, Commands, Component, Query, With}, +}; + +pub struct Plugin; + +impl bevy::app::Plugin for Plugin { + fn build(&self, app: &mut App) { + #[rustfmt::skip] + app.add_systems(Startup, startup) + .add_systems(Update, greet); + } +} + +#[derive(Component)] +struct Person; + +#[derive(Component)] +struct Name(String); + +impl Name { + fn new>(name: S) -> Self { + Self(name.into()) + } +} + +fn startup(mut cmds: Commands) { + cmds.spawn((Person, Name::new("Elaina Proctor"))); + cmds.spawn((Person, Name::new("Renzo Hume"))); + cmds.spawn((Person, Name::new("Zayna Nieves"))); +} + +fn greet(q: Query<&Name, With>) { + for name in &q { + println!("Hello, {}!", name.0); + } +}