1#![cfg_attr(docsrs, feature(doc_cfg))]
7#![allow(clippy::type_complexity)]
8#![cfg_attr(not(feature = "std"), no_std)]
9
10extern crate alloc;
11
12use crate::reactor::ReactorPlugin;
13use crate::runner::RunnerPlugin;
14use bevy::app::{App, Plugin};
15
16pub mod action;
17pub mod runner;
18pub mod task;
19
20#[allow(missing_docs)]
21pub mod prelude {
22 #[cfg(feature = "record")]
23 pub use crate::action::record::{
24 extension::{RecordExtension, RequestRedo, RequestUndo},
25 EditRecordResult, Record, Redo, RedoAction, Rollback, Track, Undo, UndoRedoInProgress,
26 };
27 #[cfg(feature = "side-effect")]
28 pub use crate::action::side_effect::AsyncFunctor;
29 pub use crate::{
30 action::inspect::{inspect, Inspect},
31 action::omit::*,
32 action::pipe::Pipe,
33 action::seed::ActionSeed,
34 action::sequence::Then,
35 action::switch::*,
36 action::through::{through, Through},
37 action::wait::Either,
38 action::Map,
39 action::Remake,
40 action::*,
41 reactor::*,
42 runner::*,
43 task::ReactorTask,
44 FlurxPlugin,
45 };
46}
47
48mod reactor;
49mod selector;
50mod world_ptr;
51
52mod core;
53#[cfg(test)]
55mod test_util;
56
57pub struct FlurxPlugin;
59
60impl Plugin for FlurxPlugin {
61 #[inline]
62 fn build(&self, app: &mut App) {
63 app.add_plugins((ReactorPlugin, RunnerPlugin));
64 }
65}
66
67#[cfg(test)]
68mod tests {
69 use crate::action::once;
70 use crate::prelude::ActionSeed;
71 use crate::FlurxPlugin;
72 use bevy::app::{App, AppExit};
73 use bevy::ecs::message::MessageCursor;
74 use bevy::ecs::system::RunSystemOnce;
75 use bevy::input::InputPlugin;
76 use bevy::prelude::{Message, MessageReader, ResMut, Resource};
77 use bevy::state::app::StatesPlugin;
78 use bevy::MinimalPlugins;
79 use bevy_test_helper::resource::count::Count;
80 use bevy_test_helper::BevyTestHelperPlugin;
81
82 pub fn exit_reader() -> MessageCursor<AppExit> {
83 MessageCursor::<AppExit>::default()
84 }
85
86 pub fn increment_count() -> ActionSeed {
87 once::run(|mut count: ResMut<Count>| {
88 count.increment();
89 })
90 }
91
92 #[allow(unused)]
93 pub fn decrement_count() -> ActionSeed {
94 once::run(|mut count: ResMut<Count>| {
95 count.decrement();
96 })
97 }
98
99 #[derive(Default, Eq, PartialEq, Copy, Clone)]
100 pub struct TestAct;
101
102 #[derive(Debug, Copy, Clone, Eq, PartialEq)]
103 pub struct NumAct(pub usize);
104
105 pub fn test_app() -> App {
106 let mut app = App::new();
107 app.add_plugins((
108 MinimalPlugins,
109 InputPlugin,
110 StatesPlugin,
111 BevyTestHelperPlugin,
112 FlurxPlugin,
113 ));
114 #[cfg(feature = "record")]
115 {
116 use crate::prelude::{Record, RecordExtension};
117 app.add_record::<NumAct>();
118 app.add_record::<TestAct>();
119 app.init_resource::<Record<TestAct>>();
120 }
121
122 app
123 }
124
125 #[derive(Eq, PartialEq, Debug, Resource, Copy, Clone, Default)]
126 pub struct TestResource;
127
128 #[allow(unused)]
129 pub fn came_event<E: Message>(app: &mut App) -> bool {
130 app.world_mut()
131 .run_system_once(|mut e: MessageReader<E>| {
132 let came = !e.is_empty();
133 e.clear();
134 came
135 })
136 .expect("Failed to run system `came_event`")
137 }
138}