From 6ed2169efe03e50947769f90324ddb131a923efd Mon Sep 17 00:00:00 2001 From: hut Date: Sat, 16 Mar 2024 15:13:00 +0100 Subject: [PATCH] tutorial: plugins --- src/main.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2850615..0a3e78f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,8 +2,7 @@ use bevy::prelude::*; fn main() { App::new() - .add_systems(Startup, add_people) - .add_systems(Update, (hello_world, greet_people)) + .add_plugins((DefaultPlugins, HelloPlugin)) .run(); } @@ -19,6 +18,15 @@ fn add_people(mut commands: Commands) { commands.spawn((Person, Name("Zayna Nieves".to_string()))); } +fn update_people(mut query: Query<&mut Name, With>) { + for mut name in &mut query { + if name.0 == "Elaina Proctor" { + name.0 = "Elaina Hume".to_string(); + break; + } + } +} + fn greet_people(query: Query<&Name, With>) { for name in &query { println!("hello {}!", name.0); @@ -28,3 +36,11 @@ fn greet_people(query: Query<&Name, With>) { fn hello_world() { println!("hello world!"); } + +pub struct HelloPlugin; +impl Plugin for HelloPlugin { + fn build(&self, app: &mut App) { + app.add_systems(Startup, add_people) + .add_systems(Update, (hello_world, (update_people, greet_people).chain())); + } +}