Skip to content
This repository was archived by the owner on Nov 25, 2024. It is now read-only.

actuate-rs/bevy_mod_actuate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

87 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bevy_mod_actuate

Crates.io version docs.rs docs CI status

Depreciated:

Actuate now supports Bevy by default!

Declarative scenes and reactivity for Bevy powered by Actuate.

use actuate::prelude::{Mut, *};
use bevy::prelude::*;
use bevy_mod_actuate::prelude::*;

// Counter composable.
#[derive(Data)]
struct Counter {
    start: i32,
}

impl Compose for Counter {
    fn compose(cx: Scope<Self>) -> impl Compose {
        let count = use_mut(&cx, || cx.me().start);

        spawn_with(
            Node {
                flex_direction: FlexDirection::Column,
                ..default()
            },
            (
                spawn(Text::new(format!("High five count: {}", count))),
                spawn(Text::new("Up high")).observe(
                    move |_trigger: In<Trigger<Pointer<Click>>>| Mut::update(count, |x| *x += 1),
                ),
                spawn(Text::new("Down low")).observe(
                    move |_trigger: In<Trigger<Pointer<Click>>>| Mut::update(count, |x| *x -= 1),
                ),
                if *count == 0 {
                    Some(spawn(Text::new("Gimme five!")))
                } else {
                    None
                },
            ),
        )
    }
}

fn main() {
    App::new()
        .add_plugins((DefaultPlugins, ActuatePlugin))
        .add_systems(Startup, setup)
        .run();
}

fn setup(mut commands: Commands) {
    commands.spawn(Camera2d::default());

    // Spawn a composition with a `Counter`, adding it to the Actuate runtime.
    commands.spawn((Node::default(), Composition::new(Counter { start: 0 })));
}

About

No description, website, or topics provided.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages