Migrate to bevy 0.11
This commit is contained in:
parent
b4859e817e
commit
ab6cfe825e
13 changed files with 57 additions and 50 deletions
|
|
@ -13,7 +13,7 @@ keywords = ["bevy", "rhai", "scripting", "game", "gamedev"]
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy = { default-features = false, version = "0.10.1", features = [
|
bevy = { default-features = false, version = "0.11.0", features = [
|
||||||
"bevy_asset",
|
"bevy_asset",
|
||||||
] }
|
] }
|
||||||
serde = "1.0.162"
|
serde = "1.0.162"
|
||||||
|
|
|
||||||
12
README.md
12
README.md
|
|
@ -21,7 +21,7 @@ use bevy_scriptum::prelude::*;
|
||||||
|
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_plugin(ScriptingPlugin::default())
|
.add_plugins(ScriptingPlugin::default())
|
||||||
.add_script_function(String::from("hello_bevy"), || {
|
.add_script_function(String::from("hello_bevy"), || {
|
||||||
println!("hello bevy, called from script");
|
println!("hello bevy, called from script");
|
||||||
});
|
});
|
||||||
|
|
@ -42,7 +42,7 @@ struct Player;
|
||||||
|
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_plugin(ScriptingPlugin::default())
|
.add_plugins(ScriptingPlugin::default())
|
||||||
.add_script_function(
|
.add_script_function(
|
||||||
String::from("print_player_names"),
|
String::from("print_player_names"),
|
||||||
|players: Query<&Name, With<Player>>| {
|
|players: Query<&Name, With<Player>>| {
|
||||||
|
|
@ -61,7 +61,7 @@ use rhai::ImmutableString;
|
||||||
|
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_plugin(ScriptingPlugin::default())
|
.add_plugins(ScriptingPlugin::default())
|
||||||
.add_script_function(
|
.add_script_function(
|
||||||
String::from("fun_with_string_param"),
|
String::from("fun_with_string_param"),
|
||||||
|In((x,)): In<(ImmutableString,)>| {
|
|In((x,)): In<(ImmutableString,)>| {
|
||||||
|
|
@ -93,7 +93,7 @@ use bevy_scriptum::prelude::*;
|
||||||
|
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_plugin(ScriptingPlugin::default())
|
.add_plugins(ScriptingPlugin::default())
|
||||||
.run();
|
.run();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -106,7 +106,7 @@ use bevy_scriptum::prelude::*;
|
||||||
|
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_plugin(ScriptingPlugin::default())
|
.add_plugins(ScriptingPlugin::default())
|
||||||
.add_script_function(
|
.add_script_function(
|
||||||
String::from("my_print"),
|
String::from("my_print"),
|
||||||
|In((x,)): In<(ImmutableString,)>| {
|
|In((x,)): In<(ImmutableString,)>| {
|
||||||
|
|
@ -128,7 +128,7 @@ use bevy::prelude::*;
|
||||||
use bevy_scriptum::Script;
|
use bevy_scriptum::Script;
|
||||||
|
|
||||||
App::new()
|
App::new()
|
||||||
.add_startup_system(|mut commands: Commands, asset_server: Res<AssetServer>| {
|
.add_systems(Startup,|mut commands: Commands, asset_server: Res<AssetServer>| {
|
||||||
commands.spawn(Script::new(asset_server.load("script.rhai")));
|
commands.spawn(Script::new(asset_server.load("script.rhai")));
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,11 @@ fn main() {
|
||||||
let mut app_exit_event_reader = ManualEventReader::<AppExit>::default();
|
let mut app_exit_event_reader = ManualEventReader::<AppExit>::default();
|
||||||
loop {
|
loop {
|
||||||
if let Some(app_exit_events) = app.world.get_resource_mut::<Events<AppExit>>() {
|
if let Some(app_exit_events) = app.world.get_resource_mut::<Events<AppExit>>() {
|
||||||
if let Some(_) = app_exit_event_reader.iter(&app_exit_events).last() {
|
if app_exit_event_reader
|
||||||
|
.iter(&app_exit_events)
|
||||||
|
.last()
|
||||||
|
.is_some()
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -17,9 +21,9 @@ fn main() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_plugin(ScriptingPlugin::default())
|
.add_plugins(ScriptingPlugin::default())
|
||||||
.add_startup_system(startup)
|
.add_systems(Startup, startup)
|
||||||
.add_system(call_rhai_on_update_from_rust)
|
.add_systems(Update, call_rhai_on_update_from_rust)
|
||||||
.add_script_function(String::from("quit"), |mut exit: EventWriter<AppExit>| {
|
.add_script_function(String::from("quit"), |mut exit: EventWriter<AppExit>| {
|
||||||
exit.send(AppExit);
|
exit.send(AppExit);
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,17 @@
|
||||||
use bevy::{prelude::*};
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::{prelude::*, Script};
|
use bevy_scriptum::{prelude::*, Script};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_plugin(ScriptingPlugin::default())
|
.add_plugins(ScriptingPlugin::default())
|
||||||
.add_script_function(
|
.add_script_function(
|
||||||
String::from("get_name"),
|
String::from("get_name"),
|
||||||
|In((entity,)): In<(Entity,)>, names: Query<&Name>| {
|
|In((entity,)): In<(Entity,)>, names: Query<&Name>| {
|
||||||
names.get(entity).unwrap().to_string()
|
names.get(entity).unwrap().to_string()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.add_startup_system(startup)
|
.add_systems(Startup, startup)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
use bevy::{prelude::*};
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::{prelude::*, Script, ScriptingRuntime};
|
use bevy_scriptum::{prelude::*, Script, ScriptingRuntime};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_plugin(ScriptingPlugin::default())
|
.add_plugins(ScriptingPlugin::default())
|
||||||
.add_script_function(String::from("hello_bevy"), || {
|
.add_script_function(String::from("hello_bevy"), || {
|
||||||
println!("hello bevy, called from script");
|
println!("hello bevy, called from script");
|
||||||
})
|
})
|
||||||
.add_startup_system(startup)
|
.add_systems(Startup, startup)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use bevy::{prelude::*};
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::{prelude::*, Script};
|
use bevy_scriptum::{prelude::*, Script};
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
|
|
@ -7,7 +7,7 @@ struct Player;
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_plugin(ScriptingPlugin::default())
|
.add_plugins(ScriptingPlugin::default())
|
||||||
.add_script_function(
|
.add_script_function(
|
||||||
String::from("print_player_names"),
|
String::from("print_player_names"),
|
||||||
|players: Query<&Name, With<Player>>| {
|
|players: Query<&Name, With<Player>>| {
|
||||||
|
|
@ -16,7 +16,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.add_startup_system(startup)
|
.add_systems(Startup, startup)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
use bevy::{prelude::*};
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::{prelude::*, Script};
|
use bevy_scriptum::{prelude::*, Script};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_plugin(ScriptingPlugin::default())
|
.add_plugins(ScriptingPlugin::default())
|
||||||
.add_startup_system(startup)
|
.add_systems(Startup, startup)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
use bevy::{prelude::*};
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::{prelude::*, Script};
|
use bevy_scriptum::{prelude::*, Script};
|
||||||
use rhai::ImmutableString;
|
use rhai::ImmutableString;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_plugin(ScriptingPlugin::default())
|
.add_plugins(ScriptingPlugin::default())
|
||||||
.add_script_function(String::from("fun_without_params"), || {
|
.add_script_function(String::from("fun_without_params"), || {
|
||||||
println!("called without params");
|
println!("called without params");
|
||||||
})
|
})
|
||||||
|
|
@ -36,7 +36,7 @@ fn main() {
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.add_startup_system(startup)
|
.add_systems(Startup, startup)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
use bevy::{prelude::*};
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::{prelude::*, Script};
|
use bevy_scriptum::{prelude::*, Script};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_plugin(ScriptingPlugin::default())
|
.add_plugins(ScriptingPlugin::default())
|
||||||
.add_script_function(String::from("hello_bevy"), || {
|
.add_script_function(String::from("hello_bevy"), || {
|
||||||
println!("hello bevy, called from script");
|
println!("hello bevy, called from script");
|
||||||
})
|
})
|
||||||
.add_startup_system(startup)
|
.add_systems(Startup, startup)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
use bevy::{prelude::*};
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::{prelude::*, Script};
|
use bevy_scriptum::{prelude::*, Script};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_plugin(ScriptingPlugin::default())
|
.add_plugins(ScriptingPlugin::default())
|
||||||
.add_script_function(String::from("hello_bevy"), hello_bevy_callback_system)
|
.add_script_function(String::from("hello_bevy"), hello_bevy_callback_system)
|
||||||
.add_startup_system(startup)
|
.add_systems(Startup, startup)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use bevy::{prelude::*};
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::{prelude::*, Script};
|
use bevy_scriptum::{prelude::*, Script};
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
|
|
@ -7,12 +7,12 @@ struct Player;
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_plugin(ScriptingPlugin::default())
|
.add_plugins(ScriptingPlugin::default())
|
||||||
.add_script_function(
|
.add_script_function(
|
||||||
String::from("get_player_name"),
|
String::from("get_player_name"),
|
||||||
|player_names: Query<&Name, With<Player>>| player_names.single().to_string(),
|
|player_names: Query<&Name, With<Player>>| player_names.single().to_string(),
|
||||||
)
|
)
|
||||||
.add_startup_system(startup)
|
.add_systems(Startup, startup)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
use bevy::{
|
use bevy::{
|
||||||
asset::{AssetLoader, LoadContext, LoadedAsset},
|
asset::{AssetLoader, LoadContext, LoadedAsset},
|
||||||
reflect::TypeUuid,
|
reflect::{TypePath, TypeUuid},
|
||||||
utils::BoxedFuture,
|
utils::BoxedFuture,
|
||||||
};
|
};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
/// A script that can be loaded by the [crate::ScriptingPlugin].
|
/// A script that can be loaded by the [crate::ScriptingPlugin].
|
||||||
#[derive(Debug, Deserialize, TypeUuid)]
|
#[derive(Debug, Deserialize, TypeUuid, TypePath)]
|
||||||
#[uuid = "3ed4b68b-4f5d-4d82-96f6-5194e358921a"]
|
#[uuid = "3ed4b68b-4f5d-4d82-96f6-5194e358921a"]
|
||||||
pub struct RhaiScript(pub String);
|
pub struct RhaiScript(pub String);
|
||||||
|
|
||||||
|
|
|
||||||
29
src/lib.rs
29
src/lib.rs
|
|
@ -19,7 +19,7 @@
|
||||||
//!
|
//!
|
||||||
//! App::new()
|
//! App::new()
|
||||||
//! .add_plugins(DefaultPlugins)
|
//! .add_plugins(DefaultPlugins)
|
||||||
//! .add_plugin(ScriptingPlugin::default())
|
//! .add_plugins(ScriptingPlugin::default())
|
||||||
//! .add_script_function(String::from("hello_bevy"), || {
|
//! .add_script_function(String::from("hello_bevy"), || {
|
||||||
//! println!("hello bevy, called from script");
|
//! println!("hello bevy, called from script");
|
||||||
//! });
|
//! });
|
||||||
|
|
@ -40,7 +40,7 @@
|
||||||
//!
|
//!
|
||||||
//! App::new()
|
//! App::new()
|
||||||
//! .add_plugins(DefaultPlugins)
|
//! .add_plugins(DefaultPlugins)
|
||||||
//! .add_plugin(ScriptingPlugin::default())
|
//! .add_plugins(ScriptingPlugin::default())
|
||||||
//! .add_script_function(
|
//! .add_script_function(
|
||||||
//! String::from("print_player_names"),
|
//! String::from("print_player_names"),
|
||||||
//! |players: Query<&Name, With<Player>>| {
|
//! |players: Query<&Name, With<Player>>| {
|
||||||
|
|
@ -59,7 +59,7 @@
|
||||||
//!
|
//!
|
||||||
//! App::new()
|
//! App::new()
|
||||||
//! .add_plugins(DefaultPlugins)
|
//! .add_plugins(DefaultPlugins)
|
||||||
//! .add_plugin(ScriptingPlugin::default())
|
//! .add_plugins(ScriptingPlugin::default())
|
||||||
//! .add_script_function(
|
//! .add_script_function(
|
||||||
//! String::from("fun_with_string_param"),
|
//! String::from("fun_with_string_param"),
|
||||||
//! |In((x,)): In<(ImmutableString,)>| {
|
//! |In((x,)): In<(ImmutableString,)>| {
|
||||||
|
|
@ -91,7 +91,7 @@
|
||||||
//!
|
//!
|
||||||
//! App::new()
|
//! App::new()
|
||||||
//! .add_plugins(DefaultPlugins)
|
//! .add_plugins(DefaultPlugins)
|
||||||
//! .add_plugin(ScriptingPlugin::default())
|
//! .add_plugins(ScriptingPlugin::default())
|
||||||
//! .run();
|
//! .run();
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
|
|
@ -104,7 +104,7 @@
|
||||||
//!
|
//!
|
||||||
//! App::new()
|
//! App::new()
|
||||||
//! .add_plugins(DefaultPlugins)
|
//! .add_plugins(DefaultPlugins)
|
||||||
//! .add_plugin(ScriptingPlugin::default())
|
//! .add_plugins(ScriptingPlugin::default())
|
||||||
//! .add_script_function(
|
//! .add_script_function(
|
||||||
//! String::from("my_print"),
|
//! String::from("my_print"),
|
||||||
//! |In((x,)): In<(ImmutableString,)>| {
|
//! |In((x,)): In<(ImmutableString,)>| {
|
||||||
|
|
@ -126,7 +126,7 @@
|
||||||
//! use bevy_scriptum::Script;
|
//! use bevy_scriptum::Script;
|
||||||
//!
|
//!
|
||||||
//! App::new()
|
//! App::new()
|
||||||
//! .add_startup_system(|mut commands: Commands, asset_server: Res<AssetServer>| {
|
//! .add_systems(Startup,|mut commands: Commands, asset_server: Res<AssetServer>| {
|
||||||
//! commands.spawn(Script::new(asset_server.load("script.rhai")));
|
//! commands.spawn(Script::new(asset_server.load("script.rhai")));
|
||||||
//! });
|
//! });
|
||||||
//! ```
|
//! ```
|
||||||
|
|
@ -221,13 +221,16 @@ impl Plugin for ScriptingPlugin {
|
||||||
.init_asset_loader::<RhaiScriptLoader>()
|
.init_asset_loader::<RhaiScriptLoader>()
|
||||||
.init_resource::<Callbacks>()
|
.init_resource::<Callbacks>()
|
||||||
.insert_resource(ScriptingRuntime::default())
|
.insert_resource(ScriptingRuntime::default())
|
||||||
.add_startup_system(init_engine.pipe(log_errors))
|
.add_systems(Startup, init_engine.pipe(log_errors))
|
||||||
.add_systems((
|
.add_systems(
|
||||||
reload_scripts,
|
Update,
|
||||||
process_calls.pipe(log_errors).after(process_new_scripts),
|
(
|
||||||
init_callbacks.pipe(log_errors),
|
reload_scripts,
|
||||||
process_new_scripts.pipe(log_errors).after(init_callbacks),
|
process_calls.pipe(log_errors).after(process_new_scripts),
|
||||||
));
|
init_callbacks.pipe(log_errors),
|
||||||
|
process_new_scripts.pipe(log_errors).after(init_callbacks),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue