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.
- Host: GitHub
- URL: https://github.com/iiyese/moshimoshi
- Owner: iiYese
- License: apache-2.0
- Archived: true
- Created: 2023-09-09T15:28:00.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-26T03:44:25.000Z (over 1 year ago)
- Last Synced: 2024-04-26T16:22:12.463Z (over 1 year ago)
- Language: Rust
- Homepage:
- Size: 9.77 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
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.
[](https://crates.io/crates/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 |