use flecs::*;
#[derive(Copy, Clone, Default, Debug, PartialEq)]
struct Position {
x: f32,
y: f32,
}
#[derive(Copy, Clone, Default, Debug, PartialEq)]
struct Velocity {
x: f32,
y: f32,
}
struct Human {}
struct Eats {}
struct Apples {}
fn iterate_components(e: Entity) {
println!("{}", e.type_info().to_str());
let mut i = 0;
e.each(|id| {
println!("{}: [{}] {}", i, id.raw(), id.to_str());
i += 1;
});
println!("");
i = 0;
e.each(|id| {
if id.is_pair() {
let rel = id.relation();
let obj = id.object();
println!("rel: {}, obj: {}", rel.name(), obj.name());
} else {
let e = id.entity();
println!("{}: entity: {} [{}]", i, e.name(), e.symbol());
}
i += 1;
});
println!("");
}
fn main() {
println!("Entity Iterate Components starting...");
let mut world = World::new();
world.component::<Position>();
world.component::<Velocity>();
world.component::<Human>();
world.component::<Eats>();
world.component::<Apples>();
let bob = world
.entity()
.set::<Position>(Position { x: 10.0, y: 20.0 })
.set::<Velocity>(Velocity { x: 1.0, y: 1.0 })
.add::<Human>()
.add_relation::<Eats, Apples>();
println!("\nBob's components");
iterate_components(bob);
println!("Position's components");
iterate_components(world.component::<Position>());
}
#[cfg(test)]
mod tests {
#[test]
fn flecs_entity_iterate_components() {
super::main();
}
}