kudo/lib.rs
1//! A simple and predictable Entity Component System.
2//!
3//! An entity-component-system (ECS) is a data structure and organizational pattern often
4//! used by game-like code.
5//!
6//! An ECS is made up of three parts:
7//!
8//! * **Entities**: IDs associated with various components
9//! * **Components**: Individual units of data associated with an entity.
10//! * **Systems**: Code that iterates over components
11//!
12//! ```
13//! # use kudo::*;
14//! // First we create the world.
15//! let mut world = World::new();
16//!
17//! // Let's create a new entity with a name and a health component.
18//! // Components are just plain structs.
19//!
20//! // This will be our health component
21//! struct Health(i32);
22//!
23//! // Spawn the entity with a String component we'll use for the name and a Health component.
24//! // Within the call to spawn we pass in a tuple that can have multiple components.
25//! world.spawn(("Medusa".to_string(), Health(-2)));
26//!
27//! // Query the world for entities that have a String component and a Health component.
28//! // The '&' before each component requests read-only access to the component.
29//! // Using '&mut' would request write/read access for that component.
30//! let mut query = world.query::<(&String, &Health)>().unwrap();
31//!
32//! // Iterate over all the components we found and check if their health is less than 0.
33//! for (name, health) in query.iter() {
34//! if health.0 < 0 {
35//! println!("{} has perished!", name);
36//! }
37//! }
38//! ```
39
40mod iterators;
41mod query;
42mod system;
43mod world;
44
45pub use iterators::*;
46pub use query::*;
47pub use system::*;
48pub use world::*;