use flax::{component, components::name, World};
use itertools::Itertools;
pub fn main() -> anyhow::Result<()> {
let mut world = World::new();
let id = world.spawn();
if world.is_alive(id) {
println!("It is alive!");
}
world.despawn(id)?;
if world.is_alive(id) {
println!("We've got a zombie on our hands");
}
let ids = world.spawn_many().take(10).collect_vec();
println!("ids: {ids:?}");
component! {
position: (f32, f32),
}
let id = world.spawn();
world.set(id, position(), (1.0, 4.0))?;
{
let val = world.get(id, position())?;
println!("The entity is at: {val:?}");
}
world.set(id, position(), (1.0, 4.5))?;
{
let mut pos = world.get_mut(id, position())?;
pos.1 += 1.0;
}
println!("The entity is now at: {:?}", world.get(id, position())?);
component! {
health: f32 => [ flax::Debuggable ],
}
world.set(id, health(), 100.0)?;
let component_name = world.get(health().id(), name())?;
println!("The name of the component is {component_name:?}");
println!("World: {world:#?}");
Ok(())
}