Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Bevy 0.15 #217

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,713 changes: 1,060 additions & 653 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions crates/bevy_plugin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_yarnspinner"
version = "0.3.1"
version = "0.4.0"
edition = "2021"
repository = "https://github.com/YarnSpinnerTool/YarnSpinner-Rust"
homepage = "https://docs.yarnspinner.dev/"
Expand All @@ -20,13 +20,13 @@ audio_assets = ["bevy/bevy_audio", "bevy/vorbis"]
anyhow = "1"
csv = "1"
serde = { version = "1", features = ["derive"] }
yarnspinner = { path = "../yarnspinner", features = ["bevy", "serde"], version = "0.3.0" }
yarnspinner = { path = "../yarnspinner", features = ["bevy", "serde"], version = "0.4.0" }
sha2 = "0.10"
rand = { version = "0.8", features = ["small_rng"] }


[dependencies.bevy]
version = "0.14.0"
version = "0.15.0"
default-features = false
features = [
"bevy_asset",
Expand All @@ -38,7 +38,7 @@ tempfile = "3"
static_assertions = "1.1.0"

[dev-dependencies.bevy]
version = "0.14.0"
version = "0.15.0"
default-features = false
features = [
"bevy_core_pipeline",
Expand Down
5 changes: 4 additions & 1 deletion crates/bevy_plugin/src/commands/command_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ mod tests {
let element = &debug_string[element_start..element_end];

// Not testing the part after because its stability is not guaranteed.
assert_eq!(element, "{\"test\": fn(bevy_ecs::system::In<(f32, f32)>)");
assert_eq!(
element,
"{\"test\": fn(bevy_ecs::system::input::In<(f32, f32)>)"
);
}
}
2 changes: 1 addition & 1 deletion crates/bevy_plugin/src/commands/command_wrapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub(crate) fn command_wrapping_plugin(_app: &mut App) {}
/// commands.add_command("add_player", add_player);
///
/// fn add_player(_: In<()>, time: Res<Time>) {
/// println!("Time since game start: {}", time.elapsed_seconds());
/// println!("Time since game start: {}", time.elapsed_secs());
/// }
/// ```
/// This command can be called from Yarn with `<<print_time>>`. Note how because we accept no parameters from Yarn, we use `In<()>` as the first parameter.
Expand Down
10 changes: 5 additions & 5 deletions crates/bevy_plugin/src/commands/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::commands::UntypedYarnCommand;
use crate::dialogue_runner::DialogueExecutionSystemSet;
use crate::events::ExecuteCommandEvent;
use crate::prelude::*;
use bevy::ecs::event::ManualEventReader;
use bevy::ecs::event::EventCursor;
use bevy::prelude::*;

pub(crate) fn command_execution_plugin(app: &mut App) {
Expand All @@ -14,8 +14,8 @@ pub(crate) fn command_execution_plugin(app: &mut App) {
);
}

fn execute_commands(world: &mut World, mut reader: Local<ManualEventReader<ExecuteCommandEvent>>) {
let events = clone_events(world, &mut reader);
fn execute_commands(world: &mut World, mut cursor: Local<EventCursor<ExecuteCommandEvent>>) {
let events = clone_events(world, &mut cursor);
for event in events {
let Some(mut command) = clone_command(world, &event) else {
continue;
Expand All @@ -30,10 +30,10 @@ fn execute_commands(world: &mut World, mut reader: Local<ManualEventReader<Execu

fn clone_events(
world: &World,
reader: &mut ManualEventReader<ExecuteCommandEvent>,
cursor: &mut EventCursor<ExecuteCommandEvent>,
) -> Vec<ExecuteCommandEvent> {
let events = world.resource::<Events<ExecuteCommandEvent>>();
reader.read(events).cloned().collect()
cursor.read(events).cloned().collect()
}

fn clone_command(
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_plugin/src/dialogue_runner/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct InnerDialogue<'a>(pub(crate) &'a Dialogue);
#[derive(Debug)]
pub struct InnerDialogueMut<'a>(pub(crate) &'a mut Dialogue);

impl<'a> InnerDialogue<'a> {
impl InnerDialogue<'_> {
/// Proxy for [`Dialogue::node_names`].
pub fn node_names(&self) -> impl Iterator<Item = &str> {
self.0.node_names().unwrap()
Expand All @@ -33,7 +33,7 @@ impl<'a> InnerDialogue<'a> {
}
}

impl<'a> InnerDialogueMut<'a> {
impl InnerDialogueMut<'_> {
/// Proxy for [`Dialogue::node_names`].
pub fn node_names(&self) -> impl Iterator<Item = &str> {
self.0.node_names().unwrap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::fmt_utils::SkipDebug;
use crate::prelude::*;
use crate::UnderlyingTextProvider;

use bevy::ecs::event::ManualEventReader;
use bevy::ecs::event::EventCursor;
use bevy::prelude::*;
use std::any::Any;
use std::collections::HashMap;
Expand All @@ -23,7 +23,7 @@ pub struct StringsFileTextProvider {
base_string_table: HashMap<LineId, StringInfo>,
strings_file_handle: Option<Handle<StringsFile>>,
translation_string_table: Option<HashMap<LineId, String>>,
event_reader: Arc<RwLock<ManualEventReader<AssetEvent<StringsFile>>>>,
event_cursor: Arc<RwLock<EventCursor<AssetEvent<StringsFile>>>>,
}

impl UnderlyingTextProvider for StringsFileTextProvider {
Expand Down Expand Up @@ -115,7 +115,7 @@ impl StringsFileTextProvider {
base_string_table: yarn_project.compilation.string_table.clone(),
strings_file_handle: None,
translation_string_table: None,
event_reader: Default::default(),
event_cursor: Default::default(),
}
}
fn set_language_invalidating_translation(&mut self, language: impl Into<Option<Language>>) {
Expand Down Expand Up @@ -158,8 +158,8 @@ impl TextProvider for StringsFileTextProvider {
}
let asset_events = world.resource::<Events<AssetEvent<StringsFile>>>();
let strings_file_has_changed = || {
let mut reader = self.event_reader.write().unwrap();
reader.read(asset_events).any(|event| match event {
let mut cursor = self.event_cursor.write().unwrap();
cursor.read(asset_events).any(|event| match event {
AssetEvent::Modified { id } => *id == handle.id(),
_ => false,
})
Expand Down
5 changes: 2 additions & 3 deletions crates/bevy_plugin/src/localization/line_id_generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ pub(crate) fn line_id_generation_plugin(app: &mut App) {
(
handle_yarn_file_events
.pipe(panic_on_err)
.run_if(in_development.and_then(has_localizations)),
.run_if(in_development.and(has_localizations)),
handle_yarn_file_events_outside_development.run_if(
resource_exists::<YarnProject>
.and_then(not(in_development.and_then(has_localizations))),
resource_exists::<YarnProject>.and(not(in_development.and(has_localizations))),
),
)
.chain()
Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_plugin/src/localization/strings_file/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::prelude::*;
use anyhow::{anyhow, bail};
use bevy::asset::{io::Reader, AssetLoader, AsyncReadExt, LoadContext};
use bevy::asset::{io::Reader, AssetLoader, LoadContext};
use bevy::prelude::*;
use bevy::reflect::TypePath;
use bevy::utils::HashMap;
Expand All @@ -23,11 +23,11 @@ impl AssetLoader for StringsFileAssetLoader {
type Asset = StringsFile;
type Settings = ();
type Error = anyhow::Error;
async fn load<'a>(
&'a self,
reader: &'a mut Reader<'_>,
_settings: &'a (),
_load_context: &'a mut LoadContext<'_>,
async fn load(
&self,
reader: &mut dyn Reader,
_settings: &(),
_load_context: &mut LoadContext<'_>,
) -> Result<Self::Asset, Self::Error> {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_plugin/src/localization/strings_file/updating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ pub(crate) fn strings_file_updating_plugin(app: &mut App) {
.in_set(YarnSpinnerSystemSet)
.run_if(
in_development
.and_then(has_localizations)
.and_then(resource_exists::<YarnProject>)
.and_then(events_in_queue::<UpdateAllStringsFilesForStringTableEvent>()),
.and(has_localizations)
.and(resource_exists::<YarnProject>)
.and(events_in_queue::<UpdateAllStringsFilesForStringTableEvent>()),
),)
.chain(),
);
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_plugin/src/plugin/yarn_file_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use crate::plugin::AssetRoot;
use crate::prelude::*;
#[cfg(not(any(target_arch = "wasm32", target_os = "android")))]
use anyhow::ensure;
use bevy::{prelude::*, reflect::TypePath};
use bevy::prelude::*;
#[cfg(not(any(target_arch = "wasm32", target_os = "android")))]
use glob::glob;
use std::path::PathBuf;

/// Possible sources to load a [`YarnFile`] from.
#[derive(Debug, Clone, PartialEq, Eq, Hash, TypePath)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Reflect)]
pub enum YarnFileSource {
/// A [`YarnFile`] that is already present in the asset server, addressed by its [`Handle`].
Handle(Handle<YarnFile>),
Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_plugin/src/yarn_file_asset.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::prelude::*;
use bevy::asset::{io::Reader, AsyncReadExt};
use bevy::asset::io::Reader;
use bevy::prelude::*;

use bevy::asset::{AssetLoader, LoadContext};
Expand Down Expand Up @@ -77,11 +77,11 @@ impl AssetLoader for YarnFileAssetLoader {
type Asset = YarnFile;
type Settings = ();
type Error = anyhow::Error;
async fn load<'a>(
&'a self,
reader: &'a mut Reader<'_>,
_settings: &'a (),
load_context: &'a mut LoadContext<'_>,
async fn load(
&self,
reader: &mut dyn Reader,
_settings: &(),
load_context: &mut LoadContext<'_>,
) -> Result<Self::Asset, Self::Error> {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
Expand Down
3 changes: 1 addition & 2 deletions crates/bevy_plugin/tests/test_strings_tables.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use bevy::asset::LoadState;
use bevy::prelude::*;
use bevy_yarnspinner::prelude::*;
use std::fs;
Expand Down Expand Up @@ -176,7 +175,7 @@ fn appends_to_pre_existing_strings_file() -> anyhow::Result<()> {
.world()
.resource::<AssetServer>()
.get_load_state(&handle)
!= Some(LoadState::Loaded)
.is_some_and(|state| state.is_loaded())
{
app.update();
}
Expand Down
56 changes: 28 additions & 28 deletions crates/bevy_plugin/tests/utils/assertion.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use bevy::ecs::event::ManualEventReader;
use bevy::ecs::event::EventCursor;
use bevy::prelude::*;
use bevy_yarnspinner::events::*;

#[derive(Debug, Default)]
pub struct EventAsserter {
pub present_line_reader: ManualEventReader<PresentLineEvent>,
pub present_options_reader: ManualEventReader<PresentOptionsEvent>,
pub dialogue_start_reader: ManualEventReader<DialogueStartEvent>,
pub dialogue_complete_reader: ManualEventReader<DialogueCompleteEvent>,
pub node_start_reader: ManualEventReader<NodeStartEvent>,
pub node_complete_reader: ManualEventReader<NodeCompleteEvent>,
pub line_hints_reader: ManualEventReader<LineHintsEvent>,
pub execute_command_reader: ManualEventReader<ExecuteCommandEvent>,
pub present_line_cursor: EventCursor<PresentLineEvent>,
pub present_options_cursor: EventCursor<PresentOptionsEvent>,
pub dialogue_start_cursor: EventCursor<DialogueStartEvent>,
pub dialogue_complete_cursor: EventCursor<DialogueCompleteEvent>,
pub node_start_cursor: EventCursor<NodeStartEvent>,
pub node_complete_cursor: EventCursor<NodeCompleteEvent>,
pub line_hints_cursor: EventCursor<LineHintsEvent>,
pub execute_command_cursor: EventCursor<ExecuteCommandEvent>,
}

impl EventAsserter {
Expand All @@ -20,50 +20,50 @@ impl EventAsserter {
}

pub fn clear_events(&mut self, app: &mut App) {
self.present_line_reader
self.present_line_cursor
.clear(app.world().resource::<Events<PresentLineEvent>>());
self.present_options_reader
self.present_options_cursor
.clear(app.world().resource::<Events<PresentOptionsEvent>>());
self.dialogue_start_reader
self.dialogue_start_cursor
.clear(app.world().resource::<Events<DialogueStartEvent>>());
self.dialogue_complete_reader
self.dialogue_complete_cursor
.clear(app.world().resource::<Events<DialogueCompleteEvent>>());
self.node_start_reader
self.node_start_cursor
.clear(app.world().resource::<Events<NodeStartEvent>>());
self.node_complete_reader
self.node_complete_cursor
.clear(app.world().resource::<Events<NodeCompleteEvent>>());
self.line_hints_reader
self.line_hints_cursor
.clear(app.world().resource::<Events<LineHintsEvent>>());
self.execute_command_reader
self.execute_command_cursor
.clear(app.world().resource::<Events<ExecuteCommandEvent>>());
}
}

#[macro_export]
macro_rules! get_reader {
macro_rules! get_cursor {
($asserter:ident, PresentLineEvent) => {
&mut $asserter.present_line_reader
&mut $asserter.present_line_cursor
};
($asserter:ident, PresentOptionsEvent) => {
&mut $asserter.present_options_reader
&mut $asserter.present_options_cursor
};
($asserter:ident, DialogueStartEvent) => {
&mut $asserter.dialogue_start_reader
&mut $asserter.dialogue_start_cursor
};
($asserter:ident, DialogueCompleteEvent) => {
&mut $asserter.dialogue_complete_reader
&mut $asserter.dialogue_complete_cursor
};
($asserter:ident, NodeStartEvent) => {
&mut $asserter.node_start_reader
&mut $asserter.node_start_cursor
};
($asserter:ident, NodeCompleteEvent) => {
&mut $asserter.node_complete_reader
&mut $asserter.node_complete_cursor
};
($asserter:ident, LineHintsEvent) => {
&mut $asserter.line_hints_reader
&mut $asserter.line_hints_cursor
};
($asserter:ident, ExecuteCommandEvent) => {
&mut $asserter.execute_command_reader
&mut $asserter.execute_command_cursor
};
}

Expand All @@ -79,8 +79,8 @@ macro_rules! assert_events {
};
($asserter:ident, $app:ident contains $event:ident (n = $num:expr) $(with $pred:expr)?) => {
let events = $app.world().resource::<bevy::prelude::Events<$event>>();
let reader = $crate::get_reader!($asserter, $event);
let events: Vec<&$event> = reader.read(&events).collect();
let cursor = $crate::get_cursor!($asserter, $event);
let events: Vec<&$event> = cursor.read(&events).collect();
assert_eq!($num, events.len(), "Expected {} events of type {}, but found {}: {events:#?}", stringify!($num), stringify!($event), events.len());
$(
{
Expand Down
6 changes: 3 additions & 3 deletions crates/compiler/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "yarnspinner_compiler"
version = "0.3.0"
version = "0.4.0"
edition = "2021"
repository = "https://github.com/YarnSpinnerTool/YarnSpinner-Rust"
homepage = "https://docs.yarnspinner.dev/"
Expand All @@ -18,10 +18,10 @@ bevy = ["dep:bevy", "yarnspinner_core/bevy"]
antlr-rust = "=0.3.0-beta"
better_any = "=0.2.0"
regex = "1"
yarnspinner_core = { path = "../core", version = "0.3.0" }
yarnspinner_core = { path = "../core", version = "0.4.0" }
annotate-snippets = "0.10"
serde = { version = "1", features = ["derive"], optional = true }
bevy = { version = "0.14.0", default-features = false, optional = true }
bevy = { version = "0.15.0", default-features = false, optional = true }
rand = { version = "0.8", features = ["small_rng"] }

[target.'cfg(target_arch = "wasm32")'.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/compiler/src/listeners/compiler_listener/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use antlr_rust::token::Token;
use yarnspinner_core::prelude::OpCode;
use yarnspinner_core::prelude::*;

impl<'input> CompilerListener<'input> {
impl CompilerListener<'_> {
/// Creates a new instruction, and appends it to a node in the [`Program`].
pub(crate) fn emit(&mut self, emit: Emit) {
let instruction = Instruction {
Expand Down
4 changes: 2 additions & 2 deletions crates/compiler/src/listeners/error_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,5 @@ impl<'input, T: Recognizer<'input>> ErrorListener<'input, T> for ParserErrorList
}
}

impl<'input> ParseTreeListener<'input, YarnSpinnerParserContextType> for ParserErrorListener {}
impl<'input> YarnSpinnerParserListener<'input> for ParserErrorListener {}
impl ParseTreeListener<'_, YarnSpinnerParserContextType> for ParserErrorListener {}
impl YarnSpinnerParserListener<'_> for ParserErrorListener {}
Loading
Loading