1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use crate::prelude::*;
use beet_core::prelude::*;
/// Logs the [`Name`] of the entity when it runs.
/// ## Tags
/// - [InputOutput](ActionTag::InputOutput)
/// ## Example
/// ```
/// # use beet_core::prelude::*;
/// # use beet_flow::prelude::*;
/// # let mut world = ControlFlowPlugin::world();
/// world
/// .spawn((Name::new("root"), LogNameOnRun))
/// .trigger_target(GetOutcome);
/// ```
#[action(log_name_on_run)]
#[derive(Default, Component, Reflect)]
#[reflect(Default, Component)]
#[require(Name)]
pub struct LogNameOnRun;
/// Logs the [`Name`] of the entity when it runs.
fn log_name_on_run(ev: On<GetOutcome>, query: Query<&Name>) -> Result {
if let Ok(name) = query.get(ev.target()) {
info!("Running: {name}");
}
Ok(())
}
#[cfg(test)]
mod test {
use crate::prelude::*;
use beet_core::prelude::*;
/// run with `--nocapture` to check output
#[test]
fn action() {
let mut world = ControlFlowPlugin::world();
world
.spawn((Name::new("root"), LogNameOnRun))
.trigger_target(GetOutcome)
.flush();
}
}