Skip to content
Snippets Groups Projects
Verified Commit d9d86899 authored by Louis's avatar Louis :fire:
Browse files

Update examples to bevy 0.13

parent 11217539
No related branches found
No related tags found
No related merge requests found
[package] [package]
name = "micro_games_macros" name = "micro_games_macros"
version = "0.3.0" version = "0.3.1"
edition = "2021" edition = "2021"
authors = ["Louis Capitanchik <contact@louiscap.co>"] authors = ["Louis Capitanchik <contact@louiscap.co>"]
description = "Utility macros to make it easier to build complex systems with Bevy" description = "Utility macros to make it easier to build complex systems with Bevy"
...@@ -16,19 +16,19 @@ default = ["kayak"] ...@@ -16,19 +16,19 @@ default = ["kayak"]
kayak = [] kayak = []
[dependencies] [dependencies]
proc-macro2 = "1.0.66" proc-macro2 = "1.0"
quote = "1.0.33" quote = "1.0"
syn = "2.0.29" syn = "2.0"
[dev-dependencies] [dev-dependencies]
test-case = "3.1.0" test-case = "3.3.1"
serde = { version = "1.0.176", features = ["derive"]} serde = { version = "1.0", features = ["derive"]}
serde_json = "1.0.96" serde_json = "1.0"
anyhow = "1.0.72" anyhow = "1.0"
[dev-dependencies.bevy] [dev-dependencies.bevy]
version = "0.12.0" version = "0.13"
default-features = false default-features = false
features = [ features = [
"bevy_asset", "bevy_asset",
......
...@@ -58,8 +58,7 @@ pub fn define_index_type( ...@@ -58,8 +58,7 @@ pub fn define_index_type(
}: &IdentContext, }: &IdentContext,
) -> TokenStream { ) -> TokenStream {
quote! { quote! {
#[derive(#FQDebug, #BevyTypePath, #BevyTypeUuid, #BevyDeref, #BevyDerefMut, #BevyAsset)] #[derive(#FQDebug, #BevyTypePath, #BevyDeref, #BevyDerefMut, #BevyAsset)]
#[uuid = #uuid]
#vis struct #index_name(pub #FQHashMap<String, #BevyHandle<#asset_name>>); #vis struct #index_name(pub #FQHashMap<String, #BevyHandle<#asset_name>>);
} }
} }
...@@ -211,7 +210,7 @@ pub fn define_load_handler( ...@@ -211,7 +210,7 @@ pub fn define_load_handler(
let mut removed_containers = #FQVec::with_capacity(4); let mut removed_containers = #FQVec::with_capacity(4);
let mut removed_assets = #FQVec::with_capacity(4); let mut removed_assets = #FQVec::with_capacity(4);
for event in events.iter() { for event in events.read() {
match event { match event {
#BevyAssetEvent::LoadedWithDependencies { id } | #BevyAssetEvent::Added { id } | #BevyAssetEvent::Modified { id } => { #BevyAssetEvent::LoadedWithDependencies { id } | #BevyAssetEvent::Added { id } | #BevyAssetEvent::Modified { id } => {
let handle = #BevyHandle::Weak(*id); let handle = #BevyHandle::Weak(*id);
...@@ -233,6 +232,7 @@ pub fn define_load_handler( ...@@ -233,6 +232,7 @@ pub fn define_load_handler(
} }
}); });
} }
#BevyAssetEvent::Unused { .. } => {}
} }
} }
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
//! to the generated asset system //! to the generated asset system
//! //!
//! ```rust //! ```rust
//! use bevy::prelude::{App, DefaultPlugins, Image, Plugin, Res, ResMut, Resource, Assets, Asset, TextureAtlas}; //! use bevy::prelude::{App, DefaultPlugins, Image, Plugin, Res, ResMut, Resource, Assets, Asset, TextureAtlasLayout};
//! use bevy::reflect::{TypePath, TypeUuid}; //! use bevy::reflect::{TypePath};
//! use micro_games_macros::{asset_system, JsonLoader}; //! use micro_games_macros::{asset_system, JsonLoader};
//! use serde::{Deserialize, Serialize}; //! use serde::{Deserialize, Serialize};
//! //!
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
//! // a regular type that derives SystemParam (including lifetimes) //! // a regular type that derives SystemParam (including lifetimes)
//! //!
//! #[asset_system] //! #[asset_system]
//! #[loader_property(pub sheets: ResMut<'w, Assets<TextureAtlas>>)] //! #[loader_property(pub sheets: ResMut<'w, Assets<TextureAtlasLayout>>)]
//! pub struct AssetHandles { //! pub struct AssetHandles {
//! // For non-JsonLoader assets, you just need to specify a name -> AssetType property. //! // 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> //! // The generated asset handles type will contain a hashmap of name -> Handle<AssetType>
...@@ -38,10 +38,9 @@ ...@@ -38,10 +38,9 @@
//! some_index_of_resources: MyCoolResourceIndex, //! 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", //! #[loader(extension = "mcr", uuid = "00000000-0000-0000-0000-000000000000",
//! asset_name = some_resource, index_name = some_index_of_resources)] //! asset_name = some_resource, index_name = some_index_of_resources)]
//! #[uuid = "10000000-0000-0000-0000-000000000001"]
//! pub struct MyCoolResource { //! pub struct MyCoolResource {
//! // You must include exactly one of either a property named "id", or another property annotated //! // You must include exactly one of either a property named "id", or another property annotated
//! // with the "asset_id" attribute. //! // with the "asset_id" attribute.
...@@ -130,7 +129,7 @@ pub(crate) mod std_traits; ...@@ -130,7 +129,7 @@ pub(crate) mod std_traits;
/// # use std::collections::HashMap; /// # use std::collections::HashMap;
/// # use bevy::asset::{Handle, Asset}; /// # use bevy::asset::{Handle, Asset};
/// # use bevy::prelude::Resource; /// # use bevy::prelude::Resource;
/// # use bevy::reflect::{TypePath, TypeUuid}; /// # use bevy::reflect::{TypePath};
/// # use serde::{Deserialize, Serialize}; /// # use serde::{Deserialize, Serialize};
/// # use micro_games_macros::JsonLoader; /// # use micro_games_macros::JsonLoader;
/// ///
...@@ -140,9 +139,8 @@ pub(crate) mod std_traits; ...@@ -140,9 +139,8 @@ pub(crate) mod std_traits;
/// simple_asset_index: HashMap<String, Handle<SimpleAssetIndex>>, /// 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")] /// #[loader(extension = "satt", uuid = "00000000-0000-0000-0000-000000000000")]
/// #[uuid = "00000000-0000-0000-0000-000000000001"]
/// pub struct SimpleAsset { /// pub struct SimpleAsset {
/// id: String, /// id: String,
/// widget: usize, /// widget: usize,
...@@ -161,17 +159,16 @@ pub(crate) mod std_traits; ...@@ -161,17 +159,16 @@ pub(crate) mod std_traits;
/// # use std::collections::HashMap; /// # use std::collections::HashMap;
/// # use bevy::asset::{Handle, Asset}; /// # use bevy::asset::{Handle, Asset};
/// # use bevy::prelude::Resource; /// # use bevy::prelude::Resource;
/// # use bevy::reflect::{TypePath, TypeUuid}; /// # use bevy::reflect::{TypePath};
/// # use serde::{Deserialize, Serialize}; /// # use serde::{Deserialize, Serialize};
/// # use micro_games_macros::JsonLoader; /// # use micro_games_macros::JsonLoader;
/// ///
/// #[derive(JsonLoader, TypePath, TypeUuid, Serialize, Deserialize, Asset)] /// #[derive(JsonLoader, TypePath, Serialize, Deserialize, Asset)]
/// #[loader( /// #[loader(
/// extension = "asset.json", uuid = "00000000-0000-0000-0000-000000000000", /// extension = "asset.json", uuid = "00000000-0000-0000-0000-000000000000",
/// storage = inner_module::SimpleAssetLocator, /// storage = inner_module::SimpleAssetLocator,
/// asset_name = some_asset_prop, index_name = set_of_assets /// asset_name = some_asset_prop, index_name = set_of_assets
/// )] /// )]
/// #[uuid = "00000000-0000-0000-0000-000000000001"]
/// pub struct MyAsset { /// pub struct MyAsset {
/// /// The asset identifier needs to implement [std::fmt::Display] /// /// The asset identifier needs to implement [std::fmt::Display]
/// #[asset_id] /// #[asset_id]
...@@ -228,14 +225,14 @@ pub fn json_loader(input: TokenStream) -> TokenStream { ...@@ -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 /// Annotate any property with a `skip` attribute to omit it from the resulting loader
/// ///
/// ```rust /// ```rust
/// use bevy::prelude::{Image, TextureAtlas}; /// use bevy::prelude::{Image, TextureAtlas, TextureAtlasLayout};
/// use micro_games_macros::asset_system; /// use micro_games_macros::asset_system;
/// ///
/// #[asset_system] /// #[asset_system]
/// pub struct AssetHandles { /// pub struct AssetHandles {
/// image: Image, /// image: Image,
/// #[skip] /// #[skip]
/// spritesheet: TextureAtlas, /// spritesheet: TextureAtlasLayout,
/// } /// }
/// ///
/// impl<'w> AssetHandlesLoader<'w> { /// impl<'w> AssetHandlesLoader<'w> {
...@@ -251,7 +248,7 @@ pub fn json_loader(input: TokenStream) -> TokenStream { ...@@ -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 /// The included property must be a `SystemParam`, and has access to the `'w` lifetime
/// ///
/// ```rust /// ```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}; /// use micro_games_macros::{asset_system, loader_property};
/// ///
/// #[derive(Event)] /// #[derive(Event)]
...@@ -261,17 +258,17 @@ pub fn json_loader(input: TokenStream) -> TokenStream { ...@@ -261,17 +258,17 @@ pub fn json_loader(input: TokenStream) -> TokenStream {
/// ///
/// #[asset_system] /// #[asset_system]
/// #[loader_property(pub load_events: EventWriter<'w, LoadingEvent>)] /// #[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 { /// pub struct AssetHandles {
/// image: Image, /// image: Image,
/// #[skip] /// #[skip]
/// spritesheet: TextureAtlas, /// spritesheet: TextureAtlasLayout,
/// } /// }
/// ///
/// impl<'w> AssetHandlesLoader<'w> { /// 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 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); /// let sheet_handle = self.sheets.add(sheet);
/// ///
/// self.storage /// self.storage
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment