From 05d0cc4bc2e757a1c2e21aed2c48bd4b6cf5f08f Mon Sep 17 00:00:00 2001 From: Coster Date: Tue, 3 Dec 2024 12:55:56 +0000 Subject: [PATCH 1/3] Update for Bevy 0.15 --- Cargo.toml | 8 ++++---- RELEASES.md | 4 ++++ examples/custom_asset_lifecycle.rs | 22 ++++++++++------------ examples/entities_from_manifests.rs | 23 ++++++++++++----------- src/plugin.rs | 8 ++++---- 5 files changed, 34 insertions(+), 31 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5b908e0..45b7868 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leafwing_manifest" -version = "0.2.0" +version = "0.3.0" authors = ["Leafwing Studios"] homepage = "https://leafwing-studios.com/" repository = "https://github.com/leafwing-studios/leafwing_manifest" @@ -15,11 +15,11 @@ exclude = ["assets/**/*", "tools/**/*", ".github/**/*"] members = ["./", "tools/ci"] [dependencies] -bevy = { version = "0.14", default-features = false, features = [ +bevy = { version = "0.15", default-features = false, features = [ "bevy_asset", "bevy_state", ] } -bevy_common_assets = { version = "0.11.0", default-features = false } +bevy_common_assets = { version = "0.12.0", default-features = false } serde = "1.0.195" thiserror = "1.0.58" @@ -62,7 +62,7 @@ ron = "0.8" # Enables non-default features for examples and tests. leafwing_manifest = { path = ".", features = ["ron"] } # Give us access to the full Bevy default features for examples. -bevy = { version = "0.14" } +bevy = { version = "0.15" } [workspace.lints.rust] unsafe_code = "forbid" diff --git a/RELEASES.md b/RELEASES.md index 83b6202..5abaac1 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,5 +1,9 @@ # Release Notes +## 0.3 + +- Now support Bevy 0.15 + ## 0.2 - Now support Bevy 0.14 diff --git a/examples/custom_asset_lifecycle.rs b/examples/custom_asset_lifecycle.rs index 030d8e9..5244c7f 100644 --- a/examples/custom_asset_lifecycle.rs +++ b/examples/custom_asset_lifecycle.rs @@ -6,10 +6,8 @@ //! As this example demonstrates, you can bypass the [`ManifestPlugin`](leafwing_manifest::plugin::ManifestPlugin) entirely, and load your assets however you like, //! calling the publicly exposed methods yourself to replicate the work it does. -use std::future::Future; - use bevy::{ - asset::{io::Reader, AssetLoader, AsyncReadExt, LoadContext, LoadState}, + asset::{io::Reader, AssetLoader, LoadContext, LoadState}, prelude::*, utils::ConditionalSendFuture, }; @@ -126,14 +124,14 @@ impl AssetLoader for ItemAssetLoader { type Settings = (); type Error = RonLoaderError; - fn load<'a>( - &'a self, - reader: &'a mut Reader, - _settings: &'a Self::Settings, - _load_context: &'a mut LoadContext, - ) -> impl ConditionalSendFuture - + Future::Asset, ::Error>> - { + fn load( + &self, + reader: &mut dyn Reader, + _settings: &Self::Settings, + _load_context: &mut LoadContext, + ) -> impl ConditionalSendFuture< + Output = Result<::Asset, ::Error>, + > { Box::pin(async move { let mut bytes = Vec::new(); reader.read_to_end(&mut bytes).await?; @@ -212,7 +210,7 @@ fn manage_manifests( // We're deferring the actual work with commands to avoid blocking the whole world // every time this system runs. - commands.add(|world: &mut World| { + commands.queue(|world: &mut World| { let item_manifest = ItemManifest::from_raw_manifest(raw_manifest, world).unwrap(); world.insert_resource(item_manifest); diff --git a/examples/entities_from_manifests.rs b/examples/entities_from_manifests.rs index 5852c83..55b89bc 100644 --- a/examples/entities_from_manifests.rs +++ b/examples/entities_from_manifests.rs @@ -11,7 +11,7 @@ //! If you need to spawn a scene hierarchy (such as for levels or 3D models), storing a handle to that scene can work well, //! or a scene bundle can be added to your custom bundle type. -use bevy::{prelude::*, sprite::Mesh2dHandle, utils::HashMap}; +use bevy::{prelude::*, utils::HashMap}; use leafwing_manifest::{ asset_state::SimpleAssetState, identifier::Id, @@ -37,7 +37,7 @@ pub struct Tile { color_material: Handle, // The same square mesh is used for all tiles, // and can be procedurally generated during . - mesh: Mesh2dHandle, + mesh: Mesh2d, tile_type: TileType, } @@ -56,10 +56,10 @@ pub struct TileBundle { // It also serves as a nice way to filter for tiles in queries. id: Id, tile_type: TileType, - material: Handle, - mesh: Mesh2dHandle, - // Add all of the components needed to render the tile. - spatial_bundle: SpatialBundle, + material: MeshMaterial2d, + mesh: Mesh2d, + transform: Transform, + visibility: Visibility, } impl TileBundle { @@ -74,12 +74,13 @@ impl TileBundle { tile_type: tile.tile_type, // We can use weak clones here and save a tiny bit of work, // since the manifest will always store a canonical strong handle to the assets. - material: tile.color_material.clone_weak(), + material: MeshMaterial2d(tile.color_material.clone_weak()), // While the value of the mesh is the same for all tiles, passing around `&Assets` everywhere // is miserable. Instead, we sacrifice a little bit of memory to redundantly store the mesh handle in the manifest: // like always, the mesh itself is only stored once in the asset storage. mesh: tile.mesh.clone(), - spatial_bundle: SpatialBundle::from_transform(transform), + transform, + visibility: Visibility::default(), } } } @@ -113,7 +114,7 @@ impl Manifest for TileManifest { let mut meshes = world.resource_mut::>(); let mesh = meshes.add(Mesh::from(Rectangle::new(1.0, 1.0))); // This is a thin wrapper around a `Handle`, used in 2D rendering. - let mesh_2d = Mesh2dHandle::from(mesh.clone()); + let mesh_2d = Mesh2d(mesh.clone()); let mut color_materials = world.resource_mut::>(); @@ -151,8 +152,8 @@ pub fn spawn_tiles(mut commands: Commands, tile_manifest: Res) { info!("Spawning tiles..."); - // Remember to add the camera bundle to the world, or you won't see anything! - commands.spawn(Camera2dBundle::default()); + // Remember to add the camera to the world, or you won't see anything! + commands.spawn(Camera2d); for (i, tile) in tile_manifest.tiles.values().enumerate() { info!("Spawning tile: {:?}", tile); diff --git a/src/plugin.rs b/src/plugin.rs index 836574c..2e89918 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -99,7 +99,7 @@ impl RegisterManifest for App { .add_systems( Update, report_failed_raw_manifest_loading:: - .run_if(on_event::>()), + .run_if(on_event::>), ) .add_systems( PreUpdate, @@ -188,7 +188,7 @@ pub enum ProcessingStatus { } /// Information about the loading status of a raw manifest. -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone)] pub struct RawManifestStatus { /// The path to the manifest file. pub path: PathBuf, @@ -247,7 +247,7 @@ impl RawManifestTracker { self.raw_manifests .values() - .all(|status| status.load_state == LoadState::Loaded) + .all(|status| status.load_state.is_loaded()) } /// Returns true if any registered raw manifests have failed to load. @@ -256,7 +256,7 @@ impl RawManifestTracker { self.raw_manifests .values() - .any(|status| matches!(status.load_state, LoadState::Failed(..))) + .any(|status| status.load_state.is_failed()) } /// Returns the [`ProcessingStatus`] of the raw manifests. From 2f338d9444ba9cea2edfe5ab4c38f3dbdc567049 Mon Sep 17 00:00:00 2001 From: Coster Date: Tue, 3 Dec 2024 14:19:35 +0000 Subject: [PATCH 2/3] Fix examples using MinimalPlugins --- examples/items_by_name.rs | 9 +++++++-- examples/simple.rs | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/examples/items_by_name.rs b/examples/items_by_name.rs index b2eb351..f023994 100644 --- a/examples/items_by_name.rs +++ b/examples/items_by_name.rs @@ -12,7 +12,7 @@ //! //! This code is largely copied from the `simple.rs` example: we're just adding constants and a new system to demonstrate the name-based lookups. -use bevy::{log::LogPlugin, prelude::*, utils::HashMap}; +use bevy::{log::LogPlugin, prelude::*, state::app::StatesPlugin, utils::HashMap}; use leafwing_manifest::{ asset_state::SimpleAssetState, identifier::Id, @@ -67,7 +67,12 @@ impl Manifest for ItemManifest { fn main() { App::new() - .add_plugins((MinimalPlugins, AssetPlugin::default(), LogPlugin::default())) + .add_plugins(( + MinimalPlugins, + AssetPlugin::default(), + LogPlugin::default(), + StatesPlugin, + )) .init_state::() .add_plugins(ManifestPlugin::::default()) .register_manifest::("items.ron") diff --git a/examples/simple.rs b/examples/simple.rs index 106632e..ddbefd3 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -6,7 +6,7 @@ //! See the other examples for more advanced use cases! //! The `raw_manifest.rs` example is a good next step that builds upon this example. -use bevy::{app::AppExit, log::LogPlugin, prelude::*, utils::HashMap}; +use bevy::{app::AppExit, log::LogPlugin, prelude::*, state::app::StatesPlugin, utils::HashMap}; use leafwing_manifest::{ asset_state::SimpleAssetState, identifier::Id, @@ -69,9 +69,9 @@ impl Manifest for ItemManifest { fn main() { App::new() - // leafwing_manifest requires `AssetPlugin` to function + // leafwing_manifest requires `AssetPlugin`, and `StatesPlugin` to function // This is included in `DefaultPlugins`, but this example is very small, so it only uses the `MinimalPlugins` - .add_plugins((MinimalPlugins, AssetPlugin::default(), LogPlugin::default())) + .add_plugins((MinimalPlugins, AssetPlugin::default(), LogPlugin::default(), StatesPlugin)) // This is our simple state, used to navigate the asset loading process. .init_state::() // Coordinates asset loading and state transitions. From 1947ca432efb0dc504d5ff5b81f66531c39f05ce Mon Sep 17 00:00:00 2001 From: Alice I Cecile Date: Thu, 5 Dec 2024 17:16:03 -0800 Subject: [PATCH 3/3] Cargo fmt --- examples/simple.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/simple.rs b/examples/simple.rs index ddbefd3..7533bdf 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -71,7 +71,12 @@ fn main() { App::new() // leafwing_manifest requires `AssetPlugin`, and `StatesPlugin` to function // This is included in `DefaultPlugins`, but this example is very small, so it only uses the `MinimalPlugins` - .add_plugins((MinimalPlugins, AssetPlugin::default(), LogPlugin::default(), StatesPlugin)) + .add_plugins(( + MinimalPlugins, + AssetPlugin::default(), + LogPlugin::default(), + StatesPlugin, + )) // This is our simple state, used to navigate the asset loading process. .init_state::() // Coordinates asset loading and state transitions.