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
|
||||
|
||||
[dependencies]
|
||||
bevy = { default-features = false, version = "0.10.1", features = [
|
||||
bevy = { default-features = false, version = "0.11.0", features = [
|
||||
"bevy_asset",
|
||||
] }
|
||||
serde = "1.0.162"
|
||||
|
|
|
|||
12
README.md
12
README.md
|
|
@ -21,7 +21,7 @@ use bevy_scriptum::prelude::*;
|
|||
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_plugin(ScriptingPlugin::default())
|
||||
.add_plugins(ScriptingPlugin::default())
|
||||
.add_script_function(String::from("hello_bevy"), || {
|
||||
println!("hello bevy, called from script");
|
||||
});
|
||||
|
|
@ -42,7 +42,7 @@ struct Player;
|
|||
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_plugin(ScriptingPlugin::default())
|
||||
.add_plugins(ScriptingPlugin::default())
|
||||
.add_script_function(
|
||||
String::from("print_player_names"),
|
||||
|players: Query<&Name, With<Player>>| {
|
||||
|
|
@ -61,7 +61,7 @@ use rhai::ImmutableString;
|
|||
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_plugin(ScriptingPlugin::default())
|
||||
.add_plugins(ScriptingPlugin::default())
|
||||
.add_script_function(
|
||||
String::from("fun_with_string_param"),
|
||||
|In((x,)): In<(ImmutableString,)>| {
|
||||
|
|
@ -93,7 +93,7 @@ use bevy_scriptum::prelude::*;
|
|||
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_plugin(ScriptingPlugin::default())
|
||||
.add_plugins(ScriptingPlugin::default())
|
||||
.run();
|
||||
```
|
||||
|
||||
|
|
@ -106,7 +106,7 @@ use bevy_scriptum::prelude::*;
|
|||
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_plugin(ScriptingPlugin::default())
|
||||
.add_plugins(ScriptingPlugin::default())
|
||||
.add_script_function(
|
||||
String::from("my_print"),
|
||||
|In((x,)): In<(ImmutableString,)>| {
|
||||
|
|
@ -128,7 +128,7 @@ use bevy::prelude::*;
|
|||
use bevy_scriptum::Script;
|
||||
|
||||
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")));
|
||||
});
|
||||
```
|
||||
|
|
|
|||
|
|
@ -9,7 +9,11 @@ fn main() {
|
|||
let mut app_exit_event_reader = ManualEventReader::<AppExit>::default();
|
||||
loop {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -17,9 +21,9 @@ fn main() {
|
|||
}
|
||||
})
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_plugin(ScriptingPlugin::default())
|
||||
.add_startup_system(startup)
|
||||
.add_system(call_rhai_on_update_from_rust)
|
||||
.add_plugins(ScriptingPlugin::default())
|
||||
.add_systems(Startup, startup)
|
||||
.add_systems(Update, call_rhai_on_update_from_rust)
|
||||
.add_script_function(String::from("quit"), |mut exit: EventWriter<AppExit>| {
|
||||
exit.send(AppExit);
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
use bevy::{prelude::*};
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::{prelude::*, Script};
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_plugin(ScriptingPlugin::default())
|
||||
.add_plugins(ScriptingPlugin::default())
|
||||
.add_script_function(
|
||||
String::from("get_name"),
|
||||
|In((entity,)): In<(Entity,)>, names: Query<&Name>| {
|
||||
names.get(entity).unwrap().to_string()
|
||||
},
|
||||
)
|
||||
.add_startup_system(startup)
|
||||
.add_systems(Startup, startup)
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
use bevy::{prelude::*};
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::{prelude::*, Script, ScriptingRuntime};
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_plugin(ScriptingPlugin::default())
|
||||
.add_plugins(ScriptingPlugin::default())
|
||||
.add_script_function(String::from("hello_bevy"), || {
|
||||
println!("hello bevy, called from script");
|
||||
})
|
||||
.add_startup_system(startup)
|
||||
.add_systems(Startup, startup)
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use bevy::{prelude::*};
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::{prelude::*, Script};
|
||||
|
||||
#[derive(Component)]
|
||||
|
|
@ -7,7 +7,7 @@ struct Player;
|
|||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_plugin(ScriptingPlugin::default())
|
||||
.add_plugins(ScriptingPlugin::default())
|
||||
.add_script_function(
|
||||
String::from("print_player_names"),
|
||||
|players: Query<&Name, With<Player>>| {
|
||||
|
|
@ -16,7 +16,7 @@ fn main() {
|
|||
}
|
||||
},
|
||||
)
|
||||
.add_startup_system(startup)
|
||||
.add_systems(Startup, startup)
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
use bevy::{prelude::*};
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::{prelude::*, Script};
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_plugin(ScriptingPlugin::default())
|
||||
.add_startup_system(startup)
|
||||
.add_plugins(ScriptingPlugin::default())
|
||||
.add_systems(Startup, startup)
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
use bevy::{prelude::*};
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::{prelude::*, Script};
|
||||
use rhai::ImmutableString;
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_plugin(ScriptingPlugin::default())
|
||||
.add_plugins(ScriptingPlugin::default())
|
||||
.add_script_function(String::from("fun_without_params"), || {
|
||||
println!("called without params");
|
||||
})
|
||||
|
|
@ -36,7 +36,7 @@ fn main() {
|
|||
);
|
||||
},
|
||||
)
|
||||
.add_startup_system(startup)
|
||||
.add_systems(Startup, startup)
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
use bevy::{prelude::*};
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::{prelude::*, Script};
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_plugin(ScriptingPlugin::default())
|
||||
.add_plugins(ScriptingPlugin::default())
|
||||
.add_script_function(String::from("hello_bevy"), || {
|
||||
println!("hello bevy, called from script");
|
||||
})
|
||||
.add_startup_system(startup)
|
||||
.add_systems(Startup, startup)
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
use bevy::{prelude::*};
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::{prelude::*, Script};
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_plugin(ScriptingPlugin::default())
|
||||
.add_plugins(ScriptingPlugin::default())
|
||||
.add_script_function(String::from("hello_bevy"), hello_bevy_callback_system)
|
||||
.add_startup_system(startup)
|
||||
.add_systems(Startup, startup)
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use bevy::{prelude::*};
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::{prelude::*, Script};
|
||||
|
||||
#[derive(Component)]
|
||||
|
|
@ -7,12 +7,12 @@ struct Player;
|
|||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_plugin(ScriptingPlugin::default())
|
||||
.add_plugins(ScriptingPlugin::default())
|
||||
.add_script_function(
|
||||
String::from("get_player_name"),
|
||||
|player_names: Query<&Name, With<Player>>| player_names.single().to_string(),
|
||||
)
|
||||
.add_startup_system(startup)
|
||||
.add_systems(Startup, startup)
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
use bevy::{
|
||||
asset::{AssetLoader, LoadContext, LoadedAsset},
|
||||
reflect::TypeUuid,
|
||||
reflect::{TypePath, TypeUuid},
|
||||
utils::BoxedFuture,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
|
||||
/// 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"]
|
||||
pub struct RhaiScript(pub String);
|
||||
|
||||
|
|
|
|||
29
src/lib.rs
29
src/lib.rs
|
|
@ -19,7 +19,7 @@
|
|||
//!
|
||||
//! App::new()
|
||||
//! .add_plugins(DefaultPlugins)
|
||||
//! .add_plugin(ScriptingPlugin::default())
|
||||
//! .add_plugins(ScriptingPlugin::default())
|
||||
//! .add_script_function(String::from("hello_bevy"), || {
|
||||
//! println!("hello bevy, called from script");
|
||||
//! });
|
||||
|
|
@ -40,7 +40,7 @@
|
|||
//!
|
||||
//! App::new()
|
||||
//! .add_plugins(DefaultPlugins)
|
||||
//! .add_plugin(ScriptingPlugin::default())
|
||||
//! .add_plugins(ScriptingPlugin::default())
|
||||
//! .add_script_function(
|
||||
//! String::from("print_player_names"),
|
||||
//! |players: Query<&Name, With<Player>>| {
|
||||
|
|
@ -59,7 +59,7 @@
|
|||
//!
|
||||
//! App::new()
|
||||
//! .add_plugins(DefaultPlugins)
|
||||
//! .add_plugin(ScriptingPlugin::default())
|
||||
//! .add_plugins(ScriptingPlugin::default())
|
||||
//! .add_script_function(
|
||||
//! String::from("fun_with_string_param"),
|
||||
//! |In((x,)): In<(ImmutableString,)>| {
|
||||
|
|
@ -91,7 +91,7 @@
|
|||
//!
|
||||
//! App::new()
|
||||
//! .add_plugins(DefaultPlugins)
|
||||
//! .add_plugin(ScriptingPlugin::default())
|
||||
//! .add_plugins(ScriptingPlugin::default())
|
||||
//! .run();
|
||||
//! ```
|
||||
//!
|
||||
|
|
@ -104,7 +104,7 @@
|
|||
//!
|
||||
//! App::new()
|
||||
//! .add_plugins(DefaultPlugins)
|
||||
//! .add_plugin(ScriptingPlugin::default())
|
||||
//! .add_plugins(ScriptingPlugin::default())
|
||||
//! .add_script_function(
|
||||
//! String::from("my_print"),
|
||||
//! |In((x,)): In<(ImmutableString,)>| {
|
||||
|
|
@ -126,7 +126,7 @@
|
|||
//! use bevy_scriptum::Script;
|
||||
//!
|
||||
//! 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")));
|
||||
//! });
|
||||
//! ```
|
||||
|
|
@ -221,13 +221,16 @@ impl Plugin for ScriptingPlugin {
|
|||
.init_asset_loader::<RhaiScriptLoader>()
|
||||
.init_resource::<Callbacks>()
|
||||
.insert_resource(ScriptingRuntime::default())
|
||||
.add_startup_system(init_engine.pipe(log_errors))
|
||||
.add_systems((
|
||||
reload_scripts,
|
||||
process_calls.pipe(log_errors).after(process_new_scripts),
|
||||
init_callbacks.pipe(log_errors),
|
||||
process_new_scripts.pipe(log_errors).after(init_callbacks),
|
||||
));
|
||||
.add_systems(Startup, init_engine.pipe(log_errors))
|
||||
.add_systems(
|
||||
Update,
|
||||
(
|
||||
reload_scripts,
|
||||
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