use checs::iter::LendingIterator;
use checs::query::IntoQuery;
use checs::world;
struct Position {
x: u32,
y: u32,
}
struct Health(i32);
#[derive(Debug)]
struct Visible;
checs::impl_storage!(
struct Storage {
positions: Position,
healths: Health,
visibles: Visible,
}
);
fn main() {
let mut world = world::World::<Storage>::new();
checs::spawn!(world, Health(80), Position { x: 0, y: 0 }, Visible);
checs::spawn!(world, Position { x: 1, y: 1 }, Visible);
checs::spawn!(world, Position { x: 2, y: 1 });
checs::spawn!(world, Health(100), Position { x: 1, y: 4 }, Visible);
{
let ps = &world.storage.positions;
let hs = &mut world.storage.healths;
let vs = &world.storage.visibles;
let query = (ps, hs, vs).into_query();
query.for_each(|(_, (_, h, _))| {
h.0 += 10;
});
}
println!();
{
let ps = &world.storage.positions;
let hs = &world.storage.healths;
let vs = &world.storage.visibles;
let query = (ps, hs, vs).into_query();
query.for_each(|(e, (p, h, v))| {
println!("{e:?} is {v:?} at ({}, {}) with {} HP", p.x, p.y, h.0);
});
}
}