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 6 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
6 changes: 3 additions & 3 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,7 +14,7 @@ pub(crate) fn command_execution_plugin(app: &mut App) {
);
}

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

fn clone_events(
world: &World,
reader: &mut ManualEventReader<ExecuteCommandEvent>,
reader: &mut EventCursor<ExecuteCommandEvent>,
) -> Vec<ExecuteCommandEvent> {
let events = world.resource::<Events<ExecuteCommandEvent>>();
reader.read(events).cloned().collect()
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_reader: Arc<RwLock<EventCursor<AssetEvent<StringsFile>>>>,
}

impl UnderlyingTextProvider for StringsFileTextProvider {
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
10 changes: 5 additions & 5 deletions crates/bevy_plugin/src/localization/strings_file/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion crates/bevy_plugin/src/plugin/yarn_file_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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
10 changes: 5 additions & 5 deletions crates/bevy_plugin/src/yarn_file_asset.rs
Original file line number Diff line number Diff line change
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
18 changes: 9 additions & 9 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_reader: EventCursor<PresentLineEvent>,
pub present_options_reader: EventCursor<PresentOptionsEvent>,
pub dialogue_start_reader: EventCursor<DialogueStartEvent>,
pub dialogue_complete_reader: EventCursor<DialogueCompleteEvent>,
pub node_start_reader: EventCursor<NodeStartEvent>,
pub node_complete_reader: EventCursor<NodeCompleteEvent>,
pub line_hints_reader: EventCursor<LineHintsEvent>,
pub execute_command_reader: EventCursor<ExecuteCommandEvent>,
}

impl EventAsserter {
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
4 changes: 2 additions & 2 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "yarnspinner_core"
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,7 +18,7 @@ bevy = ["dep:bevy"]
yarnspinner_macros = { path = "../macros", version = "0.1" }
prost = "0.12"
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 }

[dev-dependencies]
static_assertions = "1.1.0"
10 changes: 6 additions & 4 deletions crates/example_dialogue_view/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_yarnspinner_example_dialogue_view"
version = "0.3.0"
version = "0.4.0"
edition = "2021"
repository = "https://github.com/YarnSpinnerTool/YarnSpinner-Rust"
homepage = "https://docs.yarnspinner.dev/"
Expand All @@ -14,16 +14,18 @@ readme = "../../readme.md"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy_yarnspinner = { path = "../bevy_plugin", version = "0.3.0" }
bevy_yarnspinner = { path = "../bevy_plugin", version = "0.4.0" }
unicode-segmentation = "1"

[dependencies.bevy]
version = "0.14.0"
version = "0.15.0"
default-features = false
features = [
"bevy_ui",
"bevy_text",
"bevy_render",
"png",
"bevy_asset"
"bevy_asset",
"bevy_window",
"bevy_winit"
]
2 changes: 1 addition & 1 deletion crates/example_dialogue_view/src/assets.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bevy::asset::load_internal_binary_asset;
use bevy::image::{CompressedImageFormats, ImageSampler, ImageType};
use bevy::prelude::*;
use bevy::render::render_asset::RenderAssetUsages;
use bevy::render::texture::{CompressedImageFormats, ImageSampler, ImageType};

pub(crate) fn ui_assets_plugin(app: &mut App) {
load_internal_binary_asset!(
Expand Down
38 changes: 21 additions & 17 deletions crates/example_dialogue_view/src/option_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use crate::ExampleYarnSpinnerDialogueViewSystemSet;
use bevy::color::palettes::css;
use bevy::prelude::*;
use bevy::utils::HashMap;
use bevy::window::PrimaryWindow;
use bevy::window::{PrimaryWindow, SystemCursorIcon};
use bevy::winit::cursor::CursorIcon;
use bevy_yarnspinner::{events::*, prelude::*};

pub(crate) fn option_selection_plugin(app: &mut App) {
Expand All @@ -14,10 +15,7 @@ pub(crate) fn option_selection_plugin(app: &mut App) {
create_options.run_if(resource_added::<OptionSelection>),
show_options,
select_option
.run_if(
resource_exists::<OptionSelection>
.and_then(any_with_component::<PrimaryWindow>),
)
.run_if(resource_exists::<OptionSelection>.and(any_with_component::<PrimaryWindow>))
.before(typewriter::despawn),
despawn_options,
)
Expand Down Expand Up @@ -51,7 +49,7 @@ fn create_options(
option_selection: Res<OptionSelection>,
mut commands: Commands,
children: Query<&Children>,
mut options_node: Query<(Entity, &mut Style, &mut Visibility), With<OptionsNode>>,
mut options_node: Query<(Entity, &mut Node, &mut Visibility), With<OptionsNode>>,
mut root_visibility: Query<&mut Visibility, (With<UiRootNode>, Without<OptionsNode>)>,
) {
let (entity, mut style, mut visibility) = options_node.single_mut();
wiggleforlife marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -75,16 +73,18 @@ fn show_options(
}

fn select_option(
mut commands: Commands,
keys: Res<ButtonInput<KeyCode>>,
typewriter: Res<Typewriter>,
mut buttons: Query<
(&Interaction, &OptionButton, &Children),
(With<Button>, Changed<Interaction>),
>,
mut dialogue_runners: Query<&mut DialogueRunner>,
mut text: Query<&mut Text, Without<DialogueNode>>,
text_entities: Query<Entity, (With<Text>, Without<DialogueNode>)>,
mut text_writer: TextUiWriter,
option_selection: Res<OptionSelection>,
mut windows: Query<&mut Window, With<PrimaryWindow>>,
windows: Query<Entity, With<PrimaryWindow>>,
mut selected_option_event: EventWriter<HasSelectedOptionEvent>,
) {
if !typewriter.is_finished() {
Expand All @@ -103,20 +103,24 @@ fn select_option(
break;
}
}
let mut window = windows.single_mut();

for (interaction, button, children) in buttons.iter_mut() {
let (color, icon) = match *interaction {
Interaction::Pressed if selection.is_none() => {
selection = Some(button.0);
(css::TOMATO.into(), CursorIcon::Default)
(css::TOMATO.into(), SystemCursorIcon::Default)
}
Interaction::Hovered => (Color::WHITE, CursorIcon::Pointer),
_ => (css::TOMATO.into(), CursorIcon::Default),
Interaction::Hovered => (Color::WHITE, SystemCursorIcon::Pointer),
_ => (css::TOMATO.into(), SystemCursorIcon::Default),
};
window.cursor.icon = icon;
let text_entity = children.iter().find(|&e| text.contains(*e)).unwrap();
let mut text = text.get_mut(*text_entity).unwrap();
text.sections[1].style.color = color;
commands
.entity(windows.single())
.insert(CursorIcon::System(icon));
let text_entity = children
.iter()
.find(|&e| text_entities.contains(*e))
.unwrap();
*text_writer.color(*text_entity, 2) = TextColor(color);
}
let has_selected_id = selection.is_some();
if let Some(id) = selection {
Expand All @@ -133,7 +137,7 @@ fn despawn_options(
mut has_selected_option_event: EventReader<HasSelectedOptionEvent>,
mut dialogue_complete_event: EventReader<DialogueCompleteEvent>,
mut commands: Commands,
mut options_node: Query<(Entity, &mut Style, &mut Visibility), With<OptionsNode>>,
mut options_node: Query<(Entity, &mut Node, &mut Visibility), With<OptionsNode>>,
mut dialogue_node_text: Query<&mut Text, With<DialogueNode>>,
mut root_visibility: Query<&mut Visibility, (With<UiRootNode>, Without<OptionsNode>)>,
) {
Expand Down
Loading
Loading