No description
Find a file
Matt Hunzinger 4a77094c2b Pass clippy
2024-10-27 21:45:03 -04:00
.github/workflows Change actions to bevy CI template 2024-04-10 11:32:56 -04:00
examples Pass clippy 2024-10-27 21:45:03 -04:00
src Pass clippy 2024-10-27 21:45:03 -04:00
.gitignore Initial Commit 2024-04-09 16:45:16 -04:00
Cargo.lock Publish v0.2.0-alpha.4 2024-10-08 21:04:25 -04:00
Cargo.toml Publish v0.2.0-alpha.4 2024-10-08 21:04:25 -04:00
LICENSE-APACHE Create LICENSE-APACHE 2024-04-09 20:51:34 -04:00
LICENSE-MIT Create LICENSE-MIT 2024-04-09 20:51:48 -04:00
README.md Create Template struct 2024-10-08 22:02:54 -04:00

bevy-compose

Crates.io version docs.rs docs CI status

Reactive bundle template plugin for Bevy.

This crate provides a framework for parallel reactive systems using the ECS.

use bevy::prelude::*;
use bevy_compose::{Template, TemplatePlugin};

#[derive(Clone, Copy, PartialEq, Component, Deref)]
struct Health(i32);

#[derive(Component, Deref)]
struct Damage(i32);

#[derive(Component)]
struct Zombie;

fn main() {
    App::new()
        .add_plugins(TemplatePlugin::default().add(Template::new(
            // Spawning a Zombie will spawn the following components:
            Zombie,
            (
                // This only runs once.
                || Health(100),
                // This runs every time a `Health` component is updated,
                // and it's guraranteed to run before other systems using the `Damage` component.
                |entity: In<Entity>, health_query: Query<&Health>| {
                    let health = health_query.get(*entity).unwrap();
                    Damage(**health * 2)
                },
            ),
        )))
        .add_systems(Startup, setup)
        .add_systems(PostUpdate, debug)
        .run();
}

fn setup(mut commands: Commands) {
    commands.spawn(Zombie);
}

fn debug(query: Query<&Damage>) {
    for dmg in &query {
        dbg!(**dmg);
        // 200.
    }
}

Inspiration

This crate is inspired by Xilem, Concoct and SwiftUI with its typed approach to reactivity.