support bevy 0.14 (#20)

* support bevy 0.14
This commit is contained in:
Jarosław Konik 2024-07-05 17:16:06 +02:00 committed by GitHub
parent eaffce5c6d
commit 7488de076b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 61 additions and 89 deletions

View file

@ -1,7 +1,7 @@
[package]
name = "bevy_scriptum"
authors = ["Jaroslaw Konik <konikjar@gmail.com>"]
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"

View file

@ -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

View file

@ -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

View file

@ -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.

View file

@ -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

View file

@ -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

View file

@ -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::<AppExit>::default();
loop {
if let Some(app_exit_events) = app.world.get_resource_mut::<Events<AppExit>>() {
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::<LuaRuntime>(|runtime| {
runtime.add_function(String::from("quit"), |mut exit: EventWriter<AppExit>| {
exit.send(AppExit);
exit.send(AppExit::Success);
});
})
.run();

View file

@ -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::<AppExit>::default();
loop {
if let Some(app_exit_events) = app.world.get_resource_mut::<Events<AppExit>>() {
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<AppExi
for e in &query {
println!("{}", e);
}
exit.send(AppExit);
exit.send(AppExit::Success);
}
}

View file

@ -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::*;
@ -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::<AppExit>::default();
loop {
if let Some(app_exit_events) = app.world.get_resource_mut::<Events<AppExit>>() {
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::<RhaiRuntime>(|runtime| {
runtime.add_function(String::from("quit"), |mut exit: EventWriter<AppExit>| {
exit.send(AppExit);
exit.send(AppExit::Success);
});
})
.run();

View file

@ -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::<AppExit>::default();
loop {
if let Some(app_exit_events) = app.world.get_resource_mut::<Events<AppExit>>() {
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<AppExi
for e in &query {
println!("{}", e);
}
exit.send(AppExit);
exit.send(AppExit::Success);
}
}

View file

@ -2,7 +2,7 @@ use std::marker::PhantomData;
use bevy::{
asset::{io::Reader, Asset, AssetLoader, AsyncReadExt as _, LoadContext},
utils::BoxedFuture,
utils::ConditionalSendFuture,
};
/// A loader for script assets.
@ -34,7 +34,7 @@ impl<A: Asset + From<String> + GetExtensions> AssetLoader for ScriptLoader<A> {
reader: &'a mut Reader,
_settings: &'a Self::Settings,
_load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, anyhow::Result<A, anyhow::Error>> {
) -> impl ConditionalSendFuture<Output = Result<Self::Asset, Self::Error>> {
Box::pin(async move {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;

View file

@ -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<R: Runtime>(&mut self, f: impl Fn(ScriptingRuntimeBuilder<R>)) -> &mut Self {
self.world
self.world_mut()
.resource_mut::<MainScheduleOrder>()
.insert_after(Update, R::Schedule::default());
@ -395,7 +396,7 @@ impl BuildScriptingRuntime for App {
),
);
let runtime = ScriptingRuntimeBuilder::<R>::new(&mut self.world);
let runtime = ScriptingRuntimeBuilder::<R>::new(self.world_mut());
f(runtime);

View file

@ -25,12 +25,12 @@ fn run_script<R: Runtime, Out, Marker>(
path: String,
system: impl IntoSystem<(), Out, Marker>,
) -> Entity {
let asset_server = app.world.get_resource_mut::<AssetServer>().unwrap();
let asset_server = app.world_mut().get_resource_mut::<AssetServer>().unwrap();
let asset = asset_server.load::<R::ScriptAsset>(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::<IntResource>();
app.world_mut().init_resource::<IntResource>();
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::<IntResource>().unwrap().my_int, 5);
assert_eq!(app.world().get_resource::<IntResource>().unwrap().my_int, 5);
}
#[test]
@ -125,7 +125,7 @@ macro_rules! scripting_tests {
b: String,
}
app.world.init_resource::<TestResource>();
app.world_mut().init_resource::<TestResource>();
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::<TestResource>().unwrap().a, 5);
assert_eq!(app.world().get_resource::<TestResource>().unwrap().a, 5);
assert_eq!(
app.world.get_resource::<TestResource>().unwrap().b,
app.world().get_resource::<TestResource>().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::<TimesCalled>();
app.world_mut().init_resource::<TimesCalled>();
app.add_scripting::<$runtime>(|runtime| {
runtime.add_function(String::from("rust_func"), |mut res: ResMut<TimesCalled>| {
@ -390,7 +390,7 @@ macro_rules! scripting_tests {
);
assert_eq!(
app.world
app.world()
.get_resource::<TimesCalled>()
.unwrap()
.times_called,