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, healths: ComponentVec, visibles: ComponentVec, } fn main() { let mut world = world::World::::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 query = ( &world.storage.positions, &mut world.storage.healths, &world.storage.visibles, ) .into_query(); query.for_each(|(_, (_, h, _))| { h.0 += 10; }); } println!(); { let query = ( &world.storage.positions, &world.storage.healths, &world.storage.visibles, ) .into_query(); query.for_each(|(e, (p, h, v))| { println!("{e:?} is {v:?} at ({}, {}) with {} HP", p.x, p.y, h.0); }); } }