-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
dynamic_queries.rs
64 lines (53 loc) · 1.89 KB
/
dynamic_queries.rs
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use bevy::prelude::*;
use bevy_mod_scripting::prelude::*;
#[derive(Component, Reflect)]
#[reflect(Component)]
pub struct ComponentA;
#[derive(Component, Reflect)]
#[reflect(Component)]
pub struct ComponentB;
#[derive(Component, Reflect)]
#[reflect(Component)]
pub struct ComponentC;
fn main() {
let mut app = App::new();
app.add_plugins((DefaultPlugins, ScriptingPlugin))
.register_type::<ComponentA>()
.register_type::<ComponentB>()
.register_type::<ComponentC>()
.add_script_host::<LuaScriptHost<()>>(PostUpdate)
.add_script_handler::<LuaScriptHost<()>, 0, 0>(PostUpdate)
.add_api_provider::<LuaScriptHost<()>>(Box::new(LuaBevyAPIProvider))
.add_api_provider::<LuaScriptHost<()>>(Box::new(LuaCoreBevyAPIProvider))
.add_systems(Startup, (setup, apply_deferred, run).chain())
.run();
}
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn((ComponentA,));
commands.spawn((ComponentA, ComponentB));
commands.spawn((ComponentA, ComponentC));
commands.spawn((ComponentA, ComponentB, ComponentC));
commands.spawn((ComponentB,));
commands.spawn((ComponentB, ComponentC));
commands.spawn((ComponentB, ComponentA));
commands.spawn((ComponentB, ComponentA, ComponentC));
commands.spawn((ComponentC,));
commands.spawn((ComponentC, ComponentA));
commands.spawn((ComponentC, ComponentB));
commands.spawn((ComponentC, ComponentA, ComponentB));
let path = "scripts/dynamic_queries.lua";
let handle = asset_server.load(path);
commands.spawn(ScriptCollection::<LuaFile> {
scripts: vec![Script::new(path.into(), handle)],
});
}
fn run(mut events: PriorityEventWriter<LuaEvent<()>>) {
events.send(
LuaEvent {
hook_name: "on_event".into(),
args: (),
recipients: Recipients::All,
},
0,
);
}