bevy/examples/ecs/query_bundle.rs
bjorn3 6d6bc2a8b4 Merge AppBuilder into App (#2531)
This is extracted out of eb8f973646476b4a4926ba644a77e2b3a5772159 and includes some additional changes to remove all references to AppBuilder and fix examples that still used App::build() instead of App::new(). In addition I didn't extract the sub app feature as it isn't ready yet.

You can use `git diff --diff-filter=M eb8f973646476b4a4926ba644a77e2b3a5772159` to find all differences in this PR. The `--diff-filtered=M` filters all files added in the original commit but not in this commit away.

Co-Authored-By: Carter Anderson <mcanders1@gmail.com>
2021-07-27 20:21:06 +00:00

51 lines
1.3 KiB
Rust

use bevy::{log::LogPlugin, prelude::*};
fn main() {
App::new()
.add_plugin(LogPlugin)
.add_startup_system(setup.system())
.add_system(log_names.system().label(LogNamesSystem))
.add_system(log_person_bundles.system().after(LogNamesSystem))
.run();
}
#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemLabel)]
struct LogNamesSystem;
#[derive(Debug)]
struct Name(String);
#[derive(Debug)]
struct Age(usize);
#[derive(Debug, Bundle)]
struct PersonBundle {
name: Name,
age: Age,
}
/// Sets up two entities, one with a [Name] component as part of a bundle,
/// and one entity with [Name] only.
fn setup(mut commands: Commands) {
commands.spawn().insert(Name("Steve".to_string()));
commands.spawn().insert_bundle(PersonBundle {
name: Name("Bob".to_string()),
age: Age(40),
});
}
fn log_names(query: Query<&Name>) {
info!("Log all entities with `Name` component");
// this will necessarily have to print both components.
for name in query.iter() {
info!("{:?}", name);
}
}
fn log_person_bundles(query: Query<&Name, WithBundle<PersonBundle>>) {
info!("Log `Name` components from entities that have all components in `PersonBundle`.");
// this should only print `Name("Bob")`.
for name in query.iter() {
info!("{:?}", name);
}
}