use crate::z_ignore_test_common::*;
use flecs_ecs::prelude::*;
#[derive(Debug, Component)]
pub struct Position {
pub x: f32,
pub y: f32,
}
#[derive(Debug, Component)]
pub struct Velocity {
pub x: f32,
pub y: f32,
}
fn main() {
let world = World::new();
world
.observer::<flecs::Monitor, (&Position, &Velocity)>()
.each_iter(|it, index, (_pos, _vel)| {
if it.event() == flecs::OnAdd::ID {
println!(
" - Enter: {}: {}",
it.event_id().to_str(),
it.entity(index).name()
);
} else if it.event() == flecs::OnRemove::ID {
println!(
" - Leave: {}: {}",
it.event_id().to_str(),
it.entity(index).name()
);
}
});
let entity = world.entity_named("e");
entity.set(Position { x: 10.0, y: 20.0 });
entity.set(Velocity { x: 1.0, y: 2.0 });
entity.remove(Position::id());
}
#[cfg(feature = "flecs_nightly_tests")]
#[test]
fn test() {
let output_capture = OutputCapture::capture().unwrap();
main();
output_capture.test("observer_monitor".to_string());
}