-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function on_event() | ||
local component_a = world:get_type_by_name("ComponentA") | ||
local component_b = world:get_type_by_name("ComponentB") | ||
local component_c = world:get_type_by_name("ComponentC") | ||
|
||
for entity, _ in world:query(component_a):with(component_b):without(component_c):iter() do | ||
print(entity) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
fn on_event() { | ||
let component_a = world.get_type_by_name("ComponentA"); | ||
let component_b = world.get_type_by_name("ComponentB"); | ||
let component_c = world.get_type_by_name("ComponentC"); | ||
|
||
// Use with_components/without_components, as the word `with` is | ||
// reserved in rhai | ||
for results in world.query([component_a]).with_components([component_b]).without_components([component_c]) { | ||
print(results.Entity); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
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::<RhaiScriptHost<()>>(PostUpdate) | ||
.add_script_handler::<RhaiScriptHost<()>, 0, 0>(PostUpdate) | ||
.add_api_provider::<RhaiScriptHost<()>>(Box::new(RhaiBevyAPIProvider)) | ||
.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.rhai"; | ||
let handle = asset_server.load(path); | ||
|
||
commands.spawn(ScriptCollection::<RhaiFile> { | ||
scripts: vec![Script::new(path.into(), handle)], | ||
}); | ||
} | ||
|
||
fn run(mut events: PriorityEventWriter<RhaiEvent<()>>) { | ||
events.send( | ||
RhaiEvent { | ||
hook_name: "on_event".into(), | ||
args: (), | ||
recipients: Recipients::All, | ||
}, | ||
0, | ||
); | ||
} |