Skip to content

Commit

Permalink
Merge pull request #156 from yarn-slinger/155-bevy-v0.11
Browse files Browse the repository at this point in the history
Update Bevy to v0.11
  • Loading branch information
janhohenheim authored Aug 16, 2023
2 parents e4f5673 + 4b65e41 commit 67ce061
Show file tree
Hide file tree
Showing 73 changed files with 1,102 additions and 879 deletions.
1,531 changes: 853 additions & 678 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions crates/bevy_plugin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,28 @@ audio_assets = ["bevy/bevy_audio", "bevy/vorbis"]
[dependencies]
anyhow = "1"
csv = "1"
seldom_fn_plugin = "0.3"
seldom_fn_plugin = "0.4"
serde = { version = "1", features = ["derive"] }
yarn_slinger = { path = "../yarn_slinger", features = ["bevy", "serde"] }
sha2 = "0.10"
rand = { version = "0.8", features = ["small_rng"] }

[dependencies.bevy]
version = "0.10"
version = "0.11"
default-features = false
features = ["bevy_asset", "serialize"]

[dev-dependencies]
tempfile = "3"

[dev-dependencies.bevy]
version = "0.10"
version = "0.11"
default-features = false
features = ["bevy_core_pipeline", "bevy_render", "bevy_winit", "filesystem_watcher", "x11", "bevy_audio"]
features = [
"bevy_core_pipeline",
"bevy_render",
"bevy_winit",
"filesystem_watcher",
"x11",
"bevy_audio",
]
5 changes: 1 addition & 4 deletions crates/bevy_plugin/src/commands/command_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,6 @@ 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::function_system::In<(f32, f32)>)"
);
assert_eq!(element, "{\"test\": fn(bevy_ecs::system::In<(f32, f32)>)");
}
}
2 changes: 1 addition & 1 deletion crates/bevy_plugin/src/commands/command_registry/wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::time::Duration;

pub(crate) fn wait_command_plugin(app: &mut App) {
app.init_resource::<Wait>()
.add_system(update_wait.in_set(YarnSlingerSystemSet));
.add_systems(Update, update_wait.in_set(YarnSlingerSystemSet));
}

#[derive(Debug, Clone, Resource, Default)]
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_plugin/src/commands/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use bevy::ecs::event::ManualEventReader;
use bevy::prelude::*;

pub(crate) fn command_execution_plugin(app: &mut App) {
app.add_system(
app.add_systems(
Update,
execute_commands
.after(DialogueExecutionSystemSet)
.in_set(YarnSlingerSystemSet),
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_plugin/src/development_file_generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub(crate) fn development_file_generation_plugin(app: &mut App) {

/// The kind of development experience you wish when creating yarn files and dealing with missing localizations.
/// Defaults to [`DevelopmentFileGeneration::TRY_FULL`] in debug builds, [`DevelopmentFileGeneration::None`] otherwise.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Reflect, FromReflect, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Reflect, Serialize, Deserialize)]
#[reflect(Debug, Default, PartialEq, Hash, Serialize, Deserialize)]
#[non_exhaustive]
pub enum DevelopmentFileGeneration {
Expand Down
16 changes: 8 additions & 8 deletions crates/bevy_plugin/src/dialogue_runner/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub(crate) fn dialogue_runner_events_plugin(app: &mut App) {
/// An event that is fired after a dialogue advances and wishes to present a line to the user.
/// A dialogue view should listen for this event and draw it to the screen.
/// Handling this event is **mandatory** for dialogue views.
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Event)]
pub struct PresentLineEvent {
/// The line to present to the user.
pub line: LocalizedLine,
Expand All @@ -28,7 +28,7 @@ pub struct PresentLineEvent {
/// A dialogue view should listen for this event and draw it to the screen.
/// You need to handle this event by calling [`DialogueRunner::select_option`] with the ID found in the provided [`DialogueOption`]s.
/// Handling this event is **mandatory** for dialogue views.
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Event)]
pub struct PresentOptionsEvent {
/// The options to present to the user.
pub options: Vec<DialogueOption>,
Expand All @@ -42,7 +42,7 @@ pub struct PresentOptionsEvent {
/// However, a command is allowed much more freedom in its syntax than one might think, and as such, not all commands are registerable.
/// Thus, you can listen for this event and handle it yourself if you wish to build your own command syntax for e.g. a DSL.
/// Handling this event is optional for dialogue views.
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Event)]
pub struct ExecuteCommandEvent {
/// The command to execute.
pub command: UnderlyingYarnCommand,
Expand All @@ -52,7 +52,7 @@ pub struct ExecuteCommandEvent {

/// An event that is fired after a node has been completed, i.e. all of its lines, commands, options, etc. have been exhausted.
/// Handling this event is **optional** for dialogue views.
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Event)]
pub struct NodeCompleteEvent {
/// The name of the node that has been completed.
pub node_name: String,
Expand All @@ -62,7 +62,7 @@ pub struct NodeCompleteEvent {

/// An event that is fired after a node has been started, i.e. the first line, command, option, etc. has been executed.
/// Handling this event is **optional** for dialogue views
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Event)]
pub struct NodeStartEvent {
/// The name of the node that has been started.
pub node_name: String,
Expand All @@ -73,7 +73,7 @@ pub struct NodeStartEvent {
/// An event that is fired when a new node has been started. Contains the IDs of all lines in the node as a general hint
/// for asset providing systems to pre-load the lines. The lines are not guaranteed to be presented in the order of the IDs or at all.
/// Handling this event is **optional** for dialogue views.
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Event)]
pub struct LineHintsEvent {
/// The IDs of all lines in the node.
pub line_ids: Vec<LineId>,
Expand All @@ -83,14 +83,14 @@ pub struct LineHintsEvent {

/// An event that is fired when a dialogue has been started via [`DialogueRunner::start_node`]/
/// Handling this event is **optional** for dialogue views.
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Event)]
pub struct DialogueStartEvent {
/// The [`DialogueRunner`] that has started this dialogue.
pub source: Entity,
}

/// An event that is fired when a dialogue has been completed or stopped via [`DialogueRunner::stop`].
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Event)]
pub struct DialogueCompleteEvent {
/// The [`DialogueRunner`] that has completed this dialogue.
pub source: Entity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use bevy::utils::HashMap;

pub(crate) fn runtime_interaction_plugin(app: &mut App) {
app.add_systems(
Update,
(
continue_runtime
.pipe(panic_on_err)
Expand Down
19 changes: 11 additions & 8 deletions crates/bevy_plugin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,18 @@
//! app.add_plugins(DefaultPlugins)
//! // Register the Yarn Slinger plugin using its default settings, which will look for Yarn files in the "dialogue" folder
//! // If this app should support Wasm or Android, we cannot load files without specifying them, so use the following instead.
//! // .add_plugin(YarnSlingerPlugin::with_yarn_source(YarnFileSource::file("dialogue/hello_world.yarn")))
//! .add_plugin(YarnSlingerPlugin::new())
//! // .add_plugins(YarnSlingerPlugin::with_yarn_source(YarnFileSource::file("dialogue/hello_world.yarn")))
//! .add_plugins(YarnSlingerPlugin::new())
//! // Initialize the bundled example UI. Requires the `bevy_yarn_slinger_example_dialogue_view` crate.
//! // .add_plugin(ExampleYarnSlingerDialogueViewPlugin::new())
//! .add_systems((
//! setup_camera.on_startup(),
//! // Spawn dialogue runner once the Yarn project has finished compiling
//! spawn_dialogue_runner.run_if(resource_added::<YarnProject>()),
//! ))
//! // .add_plugins(ExampleYarnSlingerDialogueViewPlugin::new())
//! .add_systems(
//! Update,
//! (
//! setup_camera.on_startup(),
//! // Spawn dialogue runner once the Yarn project has finished compiling
//! spawn_dialogue_runner.run_if(resource_added::<YarnProject>()),
//! )
//! )
//! .run();
//! }
//!
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_plugin/src/line_provider/text_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ mod strings_file_text_provider;
pub(crate) fn text_provider_plugin(app: &mut App) {
app.fn_plugin(shared_text_provider::shared_text_provider_plugin)
.fn_plugin(strings_file_text_provider::strings_file_text_provider_plugin)
.add_system(
.add_systems(
Update,
fetch_resources
.in_set(LineProviderSystemSet)
.in_set(YarnSlingerSystemSet),
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_plugin/src/localization/line_id_generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub(crate) struct LineIdUpdateSystemSet;

pub(crate) fn line_id_generation_plugin(app: &mut App) {
app.add_systems(
Update,
(
handle_yarn_file_events
.pipe(panic_on_err)
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_plugin/src/localization/strings_file/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::prelude::*;
use anyhow::{anyhow, bail};
use bevy::asset::{AssetLoader, BoxedFuture, LoadContext, LoadedAsset};
use bevy::prelude::*;
use bevy::reflect::TypeUuid;
use bevy::reflect::{TypePath, TypeUuid};
use bevy::utils::HashMap;
use sha2::{Digest, Sha256};
use std::fs;
Expand Down Expand Up @@ -39,7 +39,7 @@ impl AssetLoader for StringsFileAssetLoader {
}
}

#[derive(Debug, Clone, Eq, PartialEq, Default, Serialize, Deserialize, TypeUuid)]
#[derive(Debug, Clone, Eq, PartialEq, Default, Serialize, Deserialize, TypeUuid, TypePath)]
#[uuid = "2e897914-f0f7-4b7f-b181-4d84b8ff6164"]
#[non_exhaustive]
pub(crate) struct StringsFile(HashMap<LineId, StringsFileRecord>);
Expand Down Expand Up @@ -261,7 +261,7 @@ pub(crate) struct StringsFileRecord {
pub(crate) comment: String,
}

#[derive(Debug, Clone, Eq, PartialEq, Hash, Reflect, Serialize, Deserialize, FromReflect)]
#[derive(Debug, Clone, Eq, PartialEq, Hash, Reflect, Serialize, Deserialize)]
#[reflect(Debug, PartialEq, Hash, Serialize, Deserialize)]
pub(crate) struct Lock(String);

Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_plugin/src/localization/strings_file/updating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use bevy::utils::{HashMap, HashSet};
pub(crate) fn strings_file_updating_plugin(app: &mut App) {
app.add_event::<UpdateAllStringsFilesForStringTableEvent>()
.add_systems(
Update,
(update_all_strings_files_for_string_table
.pipe(panic_on_err)
.after(LineIdUpdateSystemSet)
Expand All @@ -20,7 +21,7 @@ pub(crate) fn strings_file_updating_plugin(app: &mut App) {
);
}

#[derive(Debug, Clone, PartialEq, Eq, Default, Reflect, FromReflect)]
#[derive(Debug, Clone, PartialEq, Eq, Default, Reflect, Event)]
#[reflect(Debug, Default, PartialEq)]
pub(crate) struct UpdateAllStringsFilesForStringTableEvent(
pub(crate) std::collections::HashMap<LineId, StringInfo>,
Expand Down
7 changes: 4 additions & 3 deletions crates/bevy_plugin/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mod yarn_file_source;
/// App::new()
/// .add_plugins(DefaultPlugins)
/// // Load all Yarn files from the "assets/dialogue" folder by default.
/// .add_plugin(YarnSlingerPlugin::new());
/// .add_plugins(YarnSlingerPlugin::new());
/// ```
///
/// Note that the above does not work on Wasm or Android, since Bevy cannot query folders on these platforms. See [`YarnSlingerPlugin::new`] for more information.
Expand Down Expand Up @@ -162,7 +162,7 @@ impl Plugin for YarnSlingerPlugin {
Did you call `YarnSlingerPlugin::with_yarn_files()` without any Yarn file sources? \
If you really want to load no Yarn files right now and do that later, use `YarnSlingerPlugin::deferred()` instead.\
If you wanted to load from the default directory instead, use `YarnSlingerPlugin::default()`.");
app.add_plugin(Self::deferred())
app.add_plugins(Self::deferred())
.world
.send_event(self.project.clone());
}
Expand Down Expand Up @@ -237,6 +237,7 @@ impl YarnApp for App {
let asset_plugins: Vec<&AssetPlugin> = self.get_added_plugins();
let asset_plugin: &AssetPlugin = asset_plugins.into_iter().next().expect("Yarn Slinger requires access to the Bevy asset plugin. \
Please add `YarnSlingerPlugin` after `AssetPlugin`, which is commonly added as part of the `DefaultPlugins`");
asset_plugin.watch_for_changes

asset_plugin.watch_for_changes.is_some()
}
}
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
@@ -1,9 +1,9 @@
use crate::prelude::*;
use bevy::prelude::*;
use bevy::{prelude::*, reflect::TypePath};
use std::path::PathBuf;

/// Possible sources to load a [`YarnFile`] from.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, TypePath)]
pub enum YarnFileSource {
/// A [`YarnFile`] that is already present in the asset server, addressed by its [`Handle`].
Handle(Handle<YarnFile>),
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_plugin/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub(crate) struct CompilationSystemSet;
/// # use bevy::prelude::*;
/// # use bevy_yarn_slinger::prelude::*;
/// # let mut app = App::new();
/// app.add_system(setup_dialogue_runners.run_if(resource_added::<YarnProject>()));
/// app.add_systems(Update, setup_dialogue_runners.run_if(resource_added::<YarnProject>()));
///
/// fn setup_dialogue_runners(mut commands: Commands, project: Res<YarnProject>) {
/// commands.spawn(project.create_dialogue_runner());
Expand Down Expand Up @@ -107,7 +107,7 @@ impl YarnProject {

/// Used to late initialize a [`YarnProject`] with a set of Yarn files when using [`YarnSlingerPlugin::deferred`].
/// If you know the yarn files at the start of the game, you should use [`YarnSlingerPlugin::with_yarn_sources`] instead.
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Event)]
pub struct LoadYarnProjectEvent {
pub(crate) localizations: Option<Localizations>,
pub(crate) yarn_files: HashSet<YarnFileSource>,
Expand Down
7 changes: 4 additions & 3 deletions crates/bevy_plugin/src/project/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub(crate) fn project_compilation_plugin(app: &mut App) {
.init_resource::<YarnFilesBeingLoaded>()
.add_event::<RecompileLoadedYarnFilesEvent>()
.add_systems(
Update,
(
load_project.pipe(panic_on_err),
add_yarn_files_to_load_queue
Expand All @@ -38,11 +39,11 @@ pub(crate) struct YarnProjectConfigToLoad {
pub(crate) development_file_generation: DevelopmentFileGeneration,
}

#[derive(Debug, Clone, PartialEq, Eq, Default, Resource, Reflect, FromReflect)]
#[derive(Debug, Clone, PartialEq, Eq, Default, Resource, Reflect)]
#[reflect(Debug, Resource, Default, PartialEq)]
pub(crate) struct YarnFilesToLoad(pub(crate) HashSet<YarnFileSource>);

#[derive(Debug, Clone, PartialEq, Eq, Default, Resource, Reflect, FromReflect)]
#[derive(Debug, Clone, PartialEq, Eq, Default, Resource, Reflect)]
#[reflect(Debug, Resource, Default, PartialEq)]
pub(crate) struct YarnFilesBeingLoaded(pub(crate) HashSet<Handle<YarnFile>>);

Expand Down Expand Up @@ -95,7 +96,7 @@ fn add_yarn_files_to_load_queue(
yarn_files_being_loaded.0.extend(handles);
}

#[derive(Debug, Clone, PartialEq, Eq, Default, Reflect, FromReflect)]
#[derive(Debug, Clone, PartialEq, Eq, Default, Reflect, Event)]
#[reflect(Debug, Default, PartialEq)]
pub(crate) struct RecompileLoadedYarnFilesEvent;

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_plugin/src/yarn_file_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::hash::Hash;
use yarn_slinger::prelude::YarnFile as InnerYarnFile;

/// A Yarn file. These will mostly be created by loading them from disk with the [`AssetServer`].
#[derive(Debug, Clone, Eq, PartialEq, Reflect, FromReflect, TypeUuid, Serialize, Deserialize)]
#[derive(Debug, Clone, Eq, PartialEq, Reflect, TypeUuid, Serialize, Deserialize)]
#[reflect(Debug, PartialEq, Hash, Serialize, Deserialize)]
#[uuid = "32570e61-d69d-4f87-9552-9da2a62ecfd1"]
pub struct YarnFile {
Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_plugin/tests/test_asset_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn does_not_load_asset_without_localizations() -> Result<()> {
let mut app = App::new();

app.setup_default_plugins()
.add_plugin(YarnSlingerPlugin::with_yarn_source(YarnFileSource::file(
.add_plugins(YarnSlingerPlugin::with_yarn_source(YarnFileSource::file(
"lines_with_ids.yarn",
)));

Expand All @@ -40,7 +40,7 @@ fn does_not_load_asset_without_localizations() -> Result<()> {
fn does_not_load_invalid_asset_id() -> Result<()> {
let mut app = App::new();

app.setup_default_plugins().add_plugin(
app.setup_default_plugins().add_plugins(
YarnSlingerPlugin::with_yarn_source(YarnFileSource::file("lines_with_ids.yarn"))
.with_localizations(Localizations {
base_localization: "en-US".into(),
Expand Down Expand Up @@ -69,7 +69,7 @@ fn does_not_load_invalid_asset_id() -> Result<()> {
fn loads_asset_from_base_language_localization() -> Result<()> {
let mut app = App::new();

app.setup_default_plugins().add_plugin(
app.setup_default_plugins().add_plugins(
YarnSlingerPlugin::with_yarn_source(YarnFileSource::file("lines_with_ids.yarn"))
.with_localizations(Localizations {
base_localization: "en-US".into(),
Expand Down Expand Up @@ -103,7 +103,7 @@ fn loads_asset_from_base_language_localization() -> Result<()> {
fn loads_asset_from_translated_localization() -> Result<()> {
let mut app = App::new();

app.setup_default_plugins().add_plugin(
app.setup_default_plugins().add_plugins(
YarnSlingerPlugin::with_yarn_source(YarnFileSource::file("lines_with_ids.yarn"))
.with_localizations(Localizations {
base_localization: "en-US".into(),
Expand Down Expand Up @@ -139,7 +139,7 @@ fn loads_asset_from_translated_localization() -> Result<()> {
fn panics_on_invalid_language() {
let mut app = App::new();

app.setup_default_plugins().add_plugin(
app.setup_default_plugins().add_plugins(
YarnSlingerPlugin::with_yarn_source(YarnFileSource::file("lines_with_ids.yarn"))
.with_localizations(Localizations {
base_localization: "en-US".into(),
Expand All @@ -164,7 +164,7 @@ fn panics_on_invalid_language() {
fn does_not_load_asset_with_invalid_type() -> Result<()> {
let mut app = App::new();

app.setup_default_plugins().add_plugin(
app.setup_default_plugins().add_plugins(
YarnSlingerPlugin::with_yarn_source(YarnFileSource::file("lines_with_ids.yarn"))
.with_localizations(Localizations {
base_localization: "en-US".into(),
Expand Down
Loading

0 comments on commit 67ce061

Please sign in to comment.