Skip to content

Commit

Permalink
support bevy 0.14 (#20)
Browse files Browse the repository at this point in the history
* support bevy 0.14
  • Loading branch information
jarkonik authored Jul 5, 2024
1 parent eaffce5 commit 7488de0
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 89 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion book/src/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion book/src/lua/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion book/src/rhai/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 5 additions & 12 deletions examples/lua/call_function_from_rust.rs
Original file line number Diff line number Diff line change
@@ -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::*;

Expand All @@ -7,26 +7,19 @@ 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)
.add_systems(Startup, startup)
.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();
Expand Down
17 changes: 5 additions & 12 deletions examples/lua/side_effects.rs
Original file line number Diff line number Diff line change
@@ -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::*;

Expand All @@ -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)
Expand All @@ -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);
}
}
17 changes: 5 additions & 12 deletions examples/rhai/call_function_from_rust.rs
Original file line number Diff line number Diff line change
@@ -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::*;

Expand All @@ -7,26 +7,19 @@ 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)
.add_systems(Startup, startup)
.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();
Expand Down
21 changes: 6 additions & 15 deletions examples/rhai/side_effects.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
use bevy::{app::AppExit, ecs::event::ManualEventReader, prelude::*};
use bevy::{app::AppExit, prelude::*};
use bevy_scriptum::prelude::*;
use bevy_scriptum::runtimes::rhai::prelude::*;

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)
Expand All @@ -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);
}
}
4 changes: 2 additions & 2 deletions src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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?;
Expand Down
15 changes: 8 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
//!
Expand Down Expand Up @@ -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());

Expand All @@ -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);

Expand Down
Loading

0 comments on commit 7488de0

Please sign in to comment.