1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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);
        });
    }
}