bevy-compose

Crates.iobevy-compose
lib.rsbevy-compose
version0.2.0-alpha.4
sourcesrc
created_at2024-04-10 02:24:10.071859
updated_at2024-10-09 01:07:59.458076
descriptionReactive UI framework for Bevy
homepage
repository
max_upload_size
id1203077
size126,380
Matt Hunzinger (matthunz)

documentation

README

bevy-compose

Crates.io version docs.rs docs CI status

Reactive ECS plugin for Bevy.

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

use bevy::prelude::*;
use bevy_compose::TemplatePlugin;

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

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

#[derive(Component)]
struct Zombie;

fn main() {
    App::new()
        .add_plugins(TemplatePlugin::default().with_template(
            // 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 after the `Health` component is updated.
                |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);
    }
}

Inspiration

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

Commit count: 0

cargo fmt