Skip to content

Commit

Permalink
wip: prepare for rewrite, all tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
mrchantey committed Jul 8, 2024
1 parent b02adca commit a7b0239
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 40 deletions.
57 changes: 29 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,36 @@
</div>

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

fn main(){

let mut app = App::new();

app.add_plugins((
DefaultPlugins,
DefaultBeetPlugins
));

app.world_mut().spawn((
Running,
SequenceSelector::default(),
))
.with_children(|parent| {
parent.spawn((
LogOnRun("Hello".into()),
InsertOnRun(RunResult::Success),
));
parent.spawn((
LogOnRun("World".into()),
InsertOnRun(RunResult::Success),
));
});

app.run();
// A demonstration of Sequence control flow
fn main() {
App::new()
.add_plugins((
LogPlugin::default(),
BeetObserverPlugin
))
.world_mut()
.spawn((
Name::new("root"),
LogNameOnRun,
SequenceFlow
))
.with_children(|parent| {
parent.spawn((
Name::new("child1"),
LogNameOnRun,
EndOnRun::success(),
));
parent.spawn((
Name::new("child2"),
LogNameOnRun,
EndOnRun::success(),
));
})
.flush_trigger(OnRun);

// Running: root
// Running: child1
// Running: child2
}
```
## Examples
Expand Down
7 changes: 7 additions & 0 deletions crates/beet_ecs/src/extensions/world_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ pub impl World {
self.spawn(Observer::new(system));
self
}
fn observing<E: Event, B: Bundle, M>(
&mut self,
system: impl IntoObserverSystem<E, B, M>,
) -> &mut Self {
self.spawn(Observer::new(system));
self
}
}

#[extend::ext]
Expand Down
35 changes: 23 additions & 12 deletions examples/hello_world.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
use beet::prelude::*;
use bevy::log::LogPlugin;
use bevy::prelude::*;

#[rustfmt::skip]
fn main() {
std::env::set_var("RUST_LOG", "info");
pretty_env_logger::init();

World::new()
// ensures RunResult from children bubble up to the parent
.with_observer(bubble_run_result)
// logs the name of each entity as it runs
.with_observer(log_name_on_run)
// create the root entity
.spawn((Name::new("root"), SequenceFlow))
App::new()
.add_plugins((
LogPlugin::default(),
BeetObserverPlugin
))
.world_mut()
.spawn((
Name::new("root"),
LogNameOnRun,
SequenceFlow
))
.with_children(|parent| {
parent.spawn((Name::new("child1"), EndOnRun::success()));
parent.spawn((Name::new("child2"), EndOnRun::success()));
parent.spawn((
Name::new("child1"),
LogNameOnRun,
EndOnRun::success(),
));
parent.spawn((
Name::new("child2"),
LogNameOnRun,
EndOnRun::success(),
));
})
// trigger OnRun for the root
.flush_trigger(OnRun);
Expand Down

0 comments on commit a7b0239

Please sign in to comment.