From 01a0263c6beefc36e804c5f93b1cba9e43b60cfe Mon Sep 17 00:00:00 2001 From: Coster Date: Tue, 3 Dec 2024 12:55:56 +0000 Subject: [PATCH] Update for Bevy 0.15 --- Cargo.toml | 8 ++++---- examples/custom_asset_lifecycle.rs | 22 ++++++++++------------ examples/entities_from_manifests.rs | 23 ++++++++++++----------- src/plugin.rs | 8 ++++---- 4 files changed, 30 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/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.