checs 0.5.1

An Entity-Component-System library.
Documentation
# checs

[![Crates.io](https://img.shields.io/crates/v/checs.svg)](https://crates.io/crates/checs)
[![Documentation](https://docs.rs/checs/badge.svg)](https://docs.rs/checs)
[![License](https://img.shields.io/crates/l/checs.svg)](https://codeberg.org/tinturing/checs/src/branch/main/LICENSE)

An Entity-Component-System library.

## Disclaimer

This is a work in progress.

## Example

This is a very basic example of how to use `checs`.

> Note: You can find this example at `examples/basic.rs`. Run it with:
>
> ```sh
> cargo run --example basic
> ```

---

Define some components and a `World` to store them in.

> Note: Components are just plain old Rust types.

```rust
struct Position { x: u32, y: u32, }
struct Health(i32);
struct Visible;

use checs::component::ComponentVec;
use checs::Storage;

#[derive(Default, Storage)]
struct Storage {
    positions: ComponentVec<Position>,
    healths: ComponentVec<Health>,
    visibles: ComponentVec<Visible>,
}

let mut world = checs::world::World::<Storage>::new();
```

Create entities with initial components.

```rust
// Either manually...
let player = world.spawn();
world.insert(player, Position { x: 0, y: 0 });
world.insert(player, Visible);
world.insert(player, Health(80));

// ...or by using the `spawn` macro...
let obstacle = checs::spawn!(world, Position { x: 1, y: 1 }, Visible);
let trap = checs::spawn!(world, Position { x: 2, y: 1 });

// ...or by using `spawn_with`.
let enemy = world.spawn_with((Position { x: 1, y: 4 }, Visible, Health(100)));
```

Create a query to find the entities that share some components.

```rust
use checs::iter::LendingIterator;
use checs::query::IntoQuery;

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(|(e, (p, h, _v))| {
    h.0 = h.0 - 17;
    println!("{e:?} at ({}, {}) has {} HP.", p.x, p.y, h.0);
});

// Entity(0) at (0, 0) has 63 HP.
// Entity(3) at (1, 4) has 83 HP.
```