add example
This commit is contained in:
parent
2a2b2343d7
commit
2deec07a33
3 changed files with 38 additions and 0 deletions
|
|
@ -170,6 +170,10 @@ name = "custom_type_ruby"
|
||||||
path = "examples/ruby/custom_type.rs"
|
path = "examples/ruby/custom_type.rs"
|
||||||
required-features = ["ruby"]
|
required-features = ["ruby"]
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "ecs_ruby"
|
||||||
|
path = "examples/ruby/ecs.rs"
|
||||||
|
required-features = ["ruby"]
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tracing-subscriber = "0.3.18"
|
tracing-subscriber = "0.3.18"
|
||||||
|
|
|
||||||
1
assets/examples/ruby/ecs.rb
Normal file
1
assets/examples/ruby/ecs.rb
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
print_player_names
|
||||||
33
examples/ruby/ecs.rs
Normal file
33
examples/ruby/ecs.rs
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
use bevy::prelude::*;
|
||||||
|
use bevy_scriptum::prelude::*;
|
||||||
|
use bevy_scriptum::runtimes::ruby::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
struct Player;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
App::new()
|
||||||
|
.add_plugins(DefaultPlugins)
|
||||||
|
.add_scripting::<RubyRuntime>(|runtime| {
|
||||||
|
runtime.add_function(
|
||||||
|
String::from("print_player_names"),
|
||||||
|
|players: Query<&Name, With<Player>>| {
|
||||||
|
for player in &players {
|
||||||
|
println!("player name: {}", player);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.add_systems(Startup, startup)
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn startup(mut commands: Commands, assets_server: Res<AssetServer>) {
|
||||||
|
commands.spawn((Player, Name::new("John")));
|
||||||
|
commands.spawn((Player, Name::new("Mary")));
|
||||||
|
commands.spawn((Player, Name::new("Alice")));
|
||||||
|
|
||||||
|
commands.spawn(Script::<RubyScript>::new(
|
||||||
|
assets_server.load("examples/ruby/ecs.rb"),
|
||||||
|
));
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue