From d9d8689952e9f957bce942618ddafade1a074aa6 Mon Sep 17 00:00:00 2001 From: Louis Capitanchik <contact@louiscap.co> Date: Sat, 24 Feb 2024 04:01:59 +0000 Subject: [PATCH] Update examples to bevy 0.13 --- Cargo.toml | 18 +++++++++--------- src/json_loader/components.rs | 6 +++--- src/lib.rs | 33 +++++++++++++++------------------ 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 357fa71..17b589b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "micro_games_macros" -version = "0.3.0" +version = "0.3.1" edition = "2021" authors = ["Louis Capitanchik <contact@louiscap.co>"] description = "Utility macros to make it easier to build complex systems with Bevy" @@ -16,19 +16,19 @@ default = ["kayak"] kayak = [] [dependencies] -proc-macro2 = "1.0.66" -quote = "1.0.33" -syn = "2.0.29" +proc-macro2 = "1.0" +quote = "1.0" +syn = "2.0" [dev-dependencies] -test-case = "3.1.0" -serde = { version = "1.0.176", features = ["derive"]} -serde_json = "1.0.96" -anyhow = "1.0.72" +test-case = "3.3.1" +serde = { version = "1.0", features = ["derive"]} +serde_json = "1.0" +anyhow = "1.0" [dev-dependencies.bevy] -version = "0.12.0" +version = "0.13" default-features = false features = [ "bevy_asset", diff --git a/src/json_loader/components.rs b/src/json_loader/components.rs index 7b331b3..754a7cf 100644 --- a/src/json_loader/components.rs +++ b/src/json_loader/components.rs @@ -58,8 +58,7 @@ pub fn define_index_type( }: &IdentContext, ) -> TokenStream { quote! { - #[derive(#FQDebug, #BevyTypePath, #BevyTypeUuid, #BevyDeref, #BevyDerefMut, #BevyAsset)] - #[uuid = #uuid] + #[derive(#FQDebug, #BevyTypePath, #BevyDeref, #BevyDerefMut, #BevyAsset)] #vis struct #index_name(pub #FQHashMap<String, #BevyHandle<#asset_name>>); } } @@ -211,7 +210,7 @@ pub fn define_load_handler( let mut removed_containers = #FQVec::with_capacity(4); let mut removed_assets = #FQVec::with_capacity(4); - for event in events.iter() { + for event in events.read() { match event { #BevyAssetEvent::LoadedWithDependencies { id } | #BevyAssetEvent::Added { id } | #BevyAssetEvent::Modified { id } => { let handle = #BevyHandle::Weak(*id); @@ -233,6 +232,7 @@ pub fn define_load_handler( } }); } + #BevyAssetEvent::Unused { .. } => {} } } diff --git a/src/lib.rs b/src/lib.rs index 4a5d491..40c8d66 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,8 +5,8 @@ //! to the generated asset system //! //! ```rust -//! use bevy::prelude::{App, DefaultPlugins, Image, Plugin, Res, ResMut, Resource, Assets, Asset, TextureAtlas}; -//! use bevy::reflect::{TypePath, TypeUuid}; +//! use bevy::prelude::{App, DefaultPlugins, Image, Plugin, Res, ResMut, Resource, Assets, Asset, TextureAtlasLayout}; +//! use bevy::reflect::{TypePath}; //! use micro_games_macros::{asset_system, JsonLoader}; //! use serde::{Deserialize, Serialize}; //! @@ -16,7 +16,7 @@ //! // a regular type that derives SystemParam (including lifetimes) //! //! #[asset_system] -//! #[loader_property(pub sheets: ResMut<'w, Assets<TextureAtlas>>)] +//! #[loader_property(pub sheets: ResMut<'w, Assets<TextureAtlasLayout>>)] //! pub struct AssetHandles { //! // For non-JsonLoader assets, you just need to specify a name -> AssetType property. //! // The generated asset handles type will contain a hashmap of name -> Handle<AssetType> @@ -38,10 +38,9 @@ //! some_index_of_resources: MyCoolResourceIndex, //! } //! -//! #[derive(JsonLoader, TypePath, TypeUuid, Serialize, Deserialize, Asset)] +//! #[derive(JsonLoader, TypePath, Serialize, Deserialize, Asset)] //! #[loader(extension = "mcr", uuid = "00000000-0000-0000-0000-000000000000", //! asset_name = some_resource, index_name = some_index_of_resources)] -//! #[uuid = "10000000-0000-0000-0000-000000000001"] //! pub struct MyCoolResource { //! // You must include exactly one of either a property named "id", or another property annotated //! // with the "asset_id" attribute. @@ -130,7 +129,7 @@ pub(crate) mod std_traits; /// # use std::collections::HashMap; /// # use bevy::asset::{Handle, Asset}; /// # use bevy::prelude::Resource; -/// # use bevy::reflect::{TypePath, TypeUuid}; +/// # use bevy::reflect::{TypePath}; /// # use serde::{Deserialize, Serialize}; /// # use micro_games_macros::JsonLoader; /// @@ -140,9 +139,8 @@ pub(crate) mod std_traits; /// simple_asset_index: HashMap<String, Handle<SimpleAssetIndex>>, /// } /// -/// #[derive(JsonLoader, TypePath, TypeUuid, Serialize, Deserialize, Asset)] +/// #[derive(JsonLoader, TypePath, Serialize, Deserialize, Asset)] /// #[loader(extension = "satt", uuid = "00000000-0000-0000-0000-000000000000")] -/// #[uuid = "00000000-0000-0000-0000-000000000001"] /// pub struct SimpleAsset { /// id: String, /// widget: usize, @@ -161,17 +159,16 @@ pub(crate) mod std_traits; /// # use std::collections::HashMap; /// # use bevy::asset::{Handle, Asset}; /// # use bevy::prelude::Resource; -/// # use bevy::reflect::{TypePath, TypeUuid}; +/// # use bevy::reflect::{TypePath}; /// # use serde::{Deserialize, Serialize}; /// # use micro_games_macros::JsonLoader; /// -/// #[derive(JsonLoader, TypePath, TypeUuid, Serialize, Deserialize, Asset)] +/// #[derive(JsonLoader, TypePath, Serialize, Deserialize, Asset)] /// #[loader( /// extension = "asset.json", uuid = "00000000-0000-0000-0000-000000000000", /// storage = inner_module::SimpleAssetLocator, /// asset_name = some_asset_prop, index_name = set_of_assets /// )] -/// #[uuid = "00000000-0000-0000-0000-000000000001"] /// pub struct MyAsset { /// /// The asset identifier needs to implement [std::fmt::Display] /// #[asset_id] @@ -228,14 +225,14 @@ pub fn json_loader(input: TokenStream) -> TokenStream { /// Annotate any property with a `skip` attribute to omit it from the resulting loader /// /// ```rust -/// use bevy::prelude::{Image, TextureAtlas}; +/// use bevy::prelude::{Image, TextureAtlas, TextureAtlasLayout}; /// use micro_games_macros::asset_system; /// /// #[asset_system] /// pub struct AssetHandles { /// image: Image, /// #[skip] -/// spritesheet: TextureAtlas, +/// spritesheet: TextureAtlasLayout, /// } /// /// impl<'w> AssetHandlesLoader<'w> { @@ -251,7 +248,7 @@ pub fn json_loader(input: TokenStream) -> TokenStream { /// The included property must be a `SystemParam`, and has access to the `'w` lifetime /// /// ```rust -/// use bevy::prelude::{Assets, Event, EventWriter, Handle, Image, ResMut, TextureAtlas, Vec2}; +/// use bevy::prelude::{Assets, Event, EventWriter, Handle, Image, ResMut, TextureAtlasLayout, Vec2}; /// use micro_games_macros::{asset_system, loader_property}; /// /// #[derive(Event)] @@ -261,17 +258,17 @@ pub fn json_loader(input: TokenStream) -> TokenStream { /// /// #[asset_system] /// #[loader_property(pub load_events: EventWriter<'w, LoadingEvent>)] -/// #[loader_property(pub sheets: ResMut<'w, Assets<TextureAtlas>>)] +/// #[loader_property(pub sheets: ResMut<'w, Assets<TextureAtlasLayout>>)] /// pub struct AssetHandles { /// image: Image, /// #[skip] -/// spritesheet: TextureAtlas, +/// spritesheet: TextureAtlasLayout, /// } /// /// impl<'w> AssetHandlesLoader<'w> { -/// pub fn load_spritesheet(&mut self, path: String, name: String) -> Handle<TextureAtlas> { +/// pub fn load_spritesheet(&mut self, path: String, name: String) -> Handle<TextureAtlasLayout> { /// let image_handle = self.load_image(path, name.clone()); -/// let sheet = TextureAtlas::new_empty(image_handle, Vec2::ZERO); +/// let sheet = TextureAtlasLayout::new_empty(Vec2::ZERO); /// let sheet_handle = self.sheets.add(sheet); /// /// self.storage -- GitLab