An open API service indexing awesome lists of open source software.

https://github.com/iiyese/moshimoshi

A small crate to sugar working with command callbacks in bevy.
https://github.com/iiyese/moshimoshi

Last synced: 26 days ago
JSON representation

A small crate to sugar working with command callbacks in bevy.

Awesome Lists containing this project

README

          

# Status
Unmaintained. Use oneshot systems as of bevy 0.13

# moshimoshi
A small crate to sugar working with command callbacks in bevy.

[![Crates.io](https://img.shields.io/crates/v/moshimoshi)](https://crates.io/crates/moshimoshi)
[![Docs.rs](https://img.shields.io/docsrs/moshimoshi)](https://docs.rs/aery/latest/moshimoshi)

```rust
use bevy::prelude::*;
use moshimoshi::*;

#[derive(Component)]
struct Button;

#[derive(Component, Deref, DerefMut)]
struct OnClick(EntityCallback);

#[derive(Component, Deref, DerefMut)]
struct Counter(u32);

#[derive(Component)]
struct Text(String);

fn setup(mut commands: Commands) {
commands.spawn((
Button,
Counter(0),
Text("Click Me".to_string()),
OnClick(moshi!([e: Entity], counter: Query<&mut Counter> => {
**counter.get_mut(e).unwrap() += 1;
}))
));
}

impl Button {
fn update(mut commands: Commands, buttons: Query<(Entity, &OnClick), Changed>) {
for (entity, callback) in buttons.iter() {
commands.add(RunEntityCallback { entity, func: **callback });
}
}
}

fn main() {
App::new()
.add_systems(Update, (Button::update, apply_deferred).chain())
.run()
}
```

### Version table
| Bevy version | moshimoshi verison |
|--------------|--------------------|
| 0.11 | 0.1 - 0.2 |