add example
This commit is contained in:
parent
9bec12deec
commit
ca82a8f3a3
4 changed files with 73 additions and 0 deletions
|
|
@ -195,6 +195,10 @@ name = "hello_world_ruby"
|
|||
path = "examples/ruby/hello_world.rs"
|
||||
required-features = ["ruby"]
|
||||
|
||||
[[example]]
|
||||
name = "multiple_plugins_ruby"
|
||||
path = "examples/ruby/multiple_plugins.rs"
|
||||
required-features = ["ruby"]
|
||||
|
||||
[dev-dependencies]
|
||||
tracing-subscriber = "0.3.18"
|
||||
|
|
|
|||
1
assets/examples/ruby/multiple_plugins_plugin_a.rb
Normal file
1
assets/examples/ruby/multiple_plugins_plugin_a.rb
Normal file
|
|
@ -0,0 +1 @@
|
|||
hello_from_plugin_a
|
||||
1
assets/examples/ruby/multiple_plugins_plugin_b.rb
Normal file
1
assets/examples/ruby/multiple_plugins_plugin_b.rb
Normal file
|
|
@ -0,0 +1 @@
|
|||
hello_from_plugin_b_with_parameters("hello", 42)
|
||||
67
examples/ruby/multiple_plugins.rs
Normal file
67
examples/ruby/multiple_plugins.rs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
use bevy::prelude::*;
|
||||
use bevy_scriptum::prelude::*;
|
||||
use bevy_scriptum::runtimes::ruby::prelude::*;
|
||||
|
||||
// Plugin A
|
||||
struct PluginA;
|
||||
impl Plugin for PluginA {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_scripting_api::<RubyRuntime>(|runtime| {
|
||||
runtime.add_function(String::from("hello_from_plugin_a"), || {
|
||||
info!("Hello from Plugin A");
|
||||
});
|
||||
})
|
||||
.add_systems(Startup, plugin_a_startup);
|
||||
}
|
||||
}
|
||||
|
||||
fn plugin_a_startup(mut commands: Commands, assets_server: Res<AssetServer>) {
|
||||
commands.spawn(Script::<RubyScript>::new(
|
||||
assets_server.load("examples/lua/multiple_plugins_plugin_a.lua"),
|
||||
));
|
||||
}
|
||||
|
||||
// Plugin B
|
||||
struct PluginB;
|
||||
impl Plugin for PluginB {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_scripting_api::<RubyRuntime>(|runtime| {
|
||||
runtime.add_function(
|
||||
String::from("hello_from_plugin_b_with_parameters"),
|
||||
hello_from_b,
|
||||
);
|
||||
})
|
||||
.add_systems(Startup, plugin_b_startup);
|
||||
}
|
||||
}
|
||||
|
||||
fn plugin_b_startup(mut commands: Commands, assets_server: Res<AssetServer>) {
|
||||
commands.spawn(Script::<RubyScript>::new(
|
||||
assets_server.load("examples/lua/multiple_plugins_plugin_b.lua"),
|
||||
));
|
||||
}
|
||||
|
||||
fn hello_from_b(In((text, x)): In<(String, i32)>) {
|
||||
info!("{} from Plugin B: {}", text, x);
|
||||
}
|
||||
|
||||
// Main
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_scripting::<RubyRuntime>(|runtime| {
|
||||
runtime.add_function(String::from("hello_bevy"), || {
|
||||
info!("hello bevy, called from script");
|
||||
});
|
||||
})
|
||||
.add_systems(Startup, main_startup)
|
||||
.add_plugins(PluginA)
|
||||
.add_plugins(PluginB)
|
||||
.run();
|
||||
}
|
||||
|
||||
fn main_startup(mut commands: Commands, assets_server: Res<AssetServer>) {
|
||||
commands.spawn(Script::<RubyScript>::new(
|
||||
assets_server.load("examples/ruby/hello_world.rb"),
|
||||
));
|
||||
}
|
||||
Loading…
Reference in a new issue