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