diff --git a/Cargo.toml b/Cargo.toml index 3ffcf70c..d0c03c11 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bevy_scriptum" authors = ["Jaroslaw Konik "] -version = "0.5.0" +version = "0.6.0" edition = "2021" license = "MIT OR Apache-2.0" readme = "README.md" @@ -15,7 +15,7 @@ lua = ["mlua/luajit"] rhai = ["dep:rhai"] [dependencies] -bevy = { default-features = false, version = "0.13.0", features = [ +bevy = { default-features = false, version = "0.14", features = [ "bevy_asset", ] } serde = "1.0.162" diff --git a/README.md b/README.md index cceaa42a..e6a3ca3a 100644 --- a/README.md +++ b/README.md @@ -163,11 +163,12 @@ The examples live in `examples` directory and their corresponding scripts live i ### Bevy compatibility | bevy version | bevy_scriptum version | -|--------------|----------------------| -| 0.13 | 0.4-0.5 | -| 0.12 | 0.3 | -| 0.11 | 0.2 | -| 0.10 | 0.1 | +|--------------|-----------------------| +| 0.14 | 0.6 | +| 0.13 | 0.4-0.5 | +| 0.12 | 0.3 | +| 0.11 | 0.2 | +| 0.10 | 0.1 | ### Promises - getting return values from scripts diff --git a/SECURITY.md b/SECURITY.md index 526e30c3..f8f7e4d7 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -7,7 +7,7 @@ currently being supported with security updates. | Version | Supported | | ------- | ------------------ | -| 0.5 | :white_check_mark: | +| 0.6 | :white_check_mark: | ## Reporting a Vulnerability diff --git a/book/src/introduction.md b/book/src/introduction.md index d617e751..05babec4 100644 --- a/book/src/introduction.md +++ b/book/src/introduction.md @@ -94,7 +94,7 @@ Add the following to your `Cargo.toml`: ```toml [dependencies] -bevy_scriptum = { version = "0.5", features = ["lua"] } +bevy_scriptum = { version = "0.6", features = ["lua"] } ``` or execute `cargo add bevy_scriptum --features lua` from your project directory. diff --git a/book/src/lua/installation.md b/book/src/lua/installation.md index 09e4bc76..8dfdc57f 100644 --- a/book/src/lua/installation.md +++ b/book/src/lua/installation.md @@ -5,7 +5,7 @@ Add the following to your `Cargo.toml`: ```toml [dependencies] bevy = "0.13" -bevy_scriptum = { version = "0.5", features = ["lua"] } +bevy_scriptum = { version = "0.6", features = ["lua"] } ``` If you need a different version of bevy you need to use a matching bevy_scriptum diff --git a/book/src/rhai/installation.md b/book/src/rhai/installation.md index f76e8990..24e2010f 100644 --- a/book/src/rhai/installation.md +++ b/book/src/rhai/installation.md @@ -5,7 +5,7 @@ Add the following to your `Cargo.toml`: ```toml [dependencies] bevy = "0.13" -bevy_scriptum = { version = "0.5", features = ["rhai"] } +bevy_scriptum = { version = "0.6", features = ["rhai"] } ``` If you need a different version of bevy you need to use a matching bevy_scriptum diff --git a/examples/lua/call_function_from_rust.rs b/examples/lua/call_function_from_rust.rs index 2ec78c81..24d57874 100644 --- a/examples/lua/call_function_from_rust.rs +++ b/examples/lua/call_function_from_rust.rs @@ -1,4 +1,4 @@ -use bevy::{app::AppExit, ecs::event::ManualEventReader, prelude::*}; +use bevy::{app::AppExit, prelude::*}; use bevy_scriptum::prelude::*; use bevy_scriptum::runtimes::lua::prelude::*; @@ -7,18 +7,11 @@ fn main() { // This is just needed for headless console app, not needed for a regular bevy game // that uses a winit window .set_runner(move |mut app: App| { - let mut app_exit_event_reader = ManualEventReader::::default(); loop { - if let Some(app_exit_events) = app.world.get_resource_mut::>() { - if app_exit_event_reader - .read(&app_exit_events) - .last() - .is_some() - { - break; - } - } app.update(); + if let Some(exit) = app.should_exit() { + return exit; + } } }) .add_plugins(DefaultPlugins) @@ -26,7 +19,7 @@ fn main() { .add_systems(Update, call_lua_on_update_from_rust) .add_scripting::(|runtime| { runtime.add_function(String::from("quit"), |mut exit: EventWriter| { - exit.send(AppExit); + exit.send(AppExit::Success); }); }) .run(); diff --git a/examples/lua/side_effects.rs b/examples/lua/side_effects.rs index 12d9003f..49eef1be 100644 --- a/examples/lua/side_effects.rs +++ b/examples/lua/side_effects.rs @@ -1,4 +1,4 @@ -use bevy::{app::AppExit, ecs::event::ManualEventReader, prelude::*}; +use bevy::{app::AppExit, prelude::*}; use bevy_scriptum::prelude::*; use bevy_scriptum::runtimes::lua::prelude::*; @@ -7,18 +7,11 @@ fn main() { // This is just needed for headless console app, not needed for a regular bevy game // that uses a winit window .set_runner(move |mut app: App| { - let mut app_exit_event_reader = ManualEventReader::::default(); loop { - if let Some(app_exit_events) = app.world.get_resource_mut::>() { - if app_exit_event_reader - .read(&app_exit_events) - .last() - .is_some() - { - break; - } - } app.update(); + if let Some(exit) = app.should_exit() { + return exit; + } } }) .add_plugins(DefaultPlugins) @@ -45,6 +38,6 @@ fn print_entity_names_and_quit(query: Query<&Name>, mut exit: EventWriter::default(); loop { - if let Some(app_exit_events) = app.world.get_resource_mut::>() { - if app_exit_event_reader - .read(&app_exit_events) - .last() - .is_some() - { - break; - } - } app.update(); + if let Some(exit) = app.should_exit() { + return exit; + } } }) .add_plugins(DefaultPlugins) @@ -26,7 +19,7 @@ fn main() { .add_systems(Update, call_rhai_on_update_from_rust) .add_scripting::(|runtime| { runtime.add_function(String::from("quit"), |mut exit: EventWriter| { - exit.send(AppExit); + exit.send(AppExit::Success); }); }) .run(); diff --git a/examples/rhai/side_effects.rs b/examples/rhai/side_effects.rs index 6964c01d..a83dd323 100644 --- a/examples/rhai/side_effects.rs +++ b/examples/rhai/side_effects.rs @@ -1,4 +1,4 @@ -use bevy::{app::AppExit, ecs::event::ManualEventReader, prelude::*}; +use bevy::{app::AppExit, prelude::*}; use bevy_scriptum::prelude::*; use bevy_scriptum::runtimes::rhai::prelude::*; @@ -6,19 +6,10 @@ fn main() { App::new() // This is just needed for headless console app, not needed for a regular bevy game // that uses a winit window - .set_runner(move |mut app: App| { - let mut app_exit_event_reader = ManualEventReader::::default(); - loop { - if let Some(app_exit_events) = app.world.get_resource_mut::>() { - if app_exit_event_reader - .read(&app_exit_events) - .last() - .is_some() - { - break; - } - } - app.update(); + .set_runner(move |mut app: App| loop { + app.update(); + if let Some(exit) = app.should_exit() { + return exit; } }) .add_plugins(DefaultPlugins) @@ -45,6 +36,6 @@ fn print_entity_names_and_quit(query: Query<&Name>, mut exit: EventWriter + GetExtensions> AssetLoader for ScriptLoader { reader: &'a mut Reader, _settings: &'a Self::Settings, _load_context: &'a mut LoadContext, - ) -> BoxedFuture<'a, anyhow::Result> { + ) -> impl ConditionalSendFuture> { Box::pin(async move { let mut bytes = Vec::new(); reader.read_to_end(&mut bytes).await?; diff --git a/src/lib.rs b/src/lib.rs index 91be466a..c208bc20 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -161,11 +161,12 @@ //! ## Bevy compatibility //! //! | bevy version | bevy_scriptum version | -//! |--------------|----------------------| -//! | 0.13 | 0.4-0.5 | -//! | 0.12 | 0.3 | -//! | 0.11 | 0.2 | -//! | 0.10 | 0.1 | +//! |--------------|-----------------------| +//! | 0.14 | 0.6 | +//! | 0.13 | 0.4-0.5 | +//! | 0.12 | 0.3 | +//! | 0.11 | 0.2 | +//! | 0.10 | 0.1 | //! //! ## Promises - getting return values from scripts //! @@ -372,7 +373,7 @@ impl BuildScriptingRuntime for App { /// Adds a scripting runtime. Registers required bevy systems that take /// care of processing and running the scripts. fn add_scripting(&mut self, f: impl Fn(ScriptingRuntimeBuilder)) -> &mut Self { - self.world + self.world_mut() .resource_mut::() .insert_after(Update, R::Schedule::default()); @@ -395,7 +396,7 @@ impl BuildScriptingRuntime for App { ), ); - let runtime = ScriptingRuntimeBuilder::::new(&mut self.world); + let runtime = ScriptingRuntimeBuilder::::new(self.world_mut()); f(runtime); diff --git a/tests/tests.rs b/tests/tests.rs index 5b18f4d7..13202042 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -25,12 +25,12 @@ fn run_script( path: String, system: impl IntoSystem<(), Out, Marker>, ) -> Entity { - let asset_server = app.world.get_resource_mut::().unwrap(); + let asset_server = app.world_mut().get_resource_mut::().unwrap(); let asset = asset_server.load::(path); - let entity_id = app.world.spawn(Script::new(asset)).id(); + let entity_id = app.world_mut().spawn(Script::new(asset)).id(); app.update(); // let `ScriptData` resources be added to entities - app.world.run_system_once(system); + app.world_mut().run_system_once(system); app.update(); // let callbacks be executed entity_id @@ -91,7 +91,7 @@ macro_rules! scripting_tests { my_int: i64, } - app.world.init_resource::(); + app.world_mut().init_resource::(); app.add_scripting::<$runtime>(|runtime| { runtime.add_function( @@ -112,7 +112,7 @@ macro_rules! scripting_tests { call_script_on_update_from_rust::<$runtime>, ); - assert_eq!(app.world.get_resource::().unwrap().my_int, 5); + assert_eq!(app.world().get_resource::().unwrap().my_int, 5); } #[test] @@ -125,7 +125,7 @@ macro_rules! scripting_tests { b: String, } - app.world.init_resource::(); + app.world_mut().init_resource::(); app.add_scripting::<$runtime>(|runtime| { runtime.add_function( @@ -147,9 +147,9 @@ macro_rules! scripting_tests { call_script_on_update_from_rust::<$runtime>, ); - assert_eq!(app.world.get_resource::().unwrap().a, 5); + assert_eq!(app.world().get_resource::().unwrap().a, 5); assert_eq!( - app.world.get_resource::().unwrap().b, + app.world().get_resource::().unwrap().b, String::from("test") ); } @@ -176,7 +176,7 @@ macro_rules! scripting_tests { }, ); - <$runtime>::assert_state_key_value_i32(&app.world, entity_id, "a_value", 1i32); + <$runtime>::assert_state_key_value_i32(&app.world(), entity_id, "a_value", 1i32); } #[test] @@ -206,9 +206,9 @@ macro_rules! scripting_tests { }, ); - <$runtime>::assert_state_key_value_i32(&app.world, entity_id, "a_value", 1i32); + <$runtime>::assert_state_key_value_i32(&app.world(), entity_id, "a_value", 1i32); <$runtime>::assert_state_key_value_string( - &app.world, + &app.world(), entity_id, "b_value", &String::from("abc"), @@ -237,8 +237,8 @@ macro_rules! scripting_tests { }, ); - <$runtime>::assert_state_key_value_i32(&app.world, entity_id, "a_value", 1i32); - <$runtime>::assert_state_key_value_i32(&app.world, entity_id, "b_value", 2i32); + <$runtime>::assert_state_key_value_i32(&app.world(), entity_id, "a_value", 1i32); + <$runtime>::assert_state_key_value_i32(&app.world(), entity_id, "b_value", 2i32); } #[test] @@ -303,7 +303,7 @@ macro_rules! scripting_tests { call_script_on_update_from_rust::<$runtime>, ); - <$runtime>::assert_state_key_value_i64(&app.world, entity_id, "times_called", 1i64); + <$runtime>::assert_state_key_value_i64(&app.world(), entity_id, "times_called", 1i64); } #[test] @@ -320,7 +320,7 @@ macro_rules! scripting_tests { call_script_on_update_from_rust::<$runtime>, ); - <$runtime>::assert_state_key_value_i32(&app.world, entity_id, "x", 123i32); + <$runtime>::assert_state_key_value_i32(&app.world(), entity_id, "x", 123i32); } #[test] @@ -357,7 +357,7 @@ macro_rules! scripting_tests { call_script_on_update_from_rust::<$runtime>, ); - app.world.run_system_once(|tagged: Query<&MyTag>| { + app.world_mut().run_system_once(|tagged: Query<&MyTag>| { tagged.single(); }); } @@ -371,7 +371,7 @@ macro_rules! scripting_tests { times_called: u8, } - app.world.init_resource::(); + app.world_mut().init_resource::(); app.add_scripting::<$runtime>(|runtime| { runtime.add_function(String::from("rust_func"), |mut res: ResMut| { @@ -390,7 +390,7 @@ macro_rules! scripting_tests { ); assert_eq!( - app.world + app.world() .get_resource::() .unwrap() .times_called,