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

Support Bevy 0.14

parent 3cf1e7d4
No related branches found
No related tags found
No related merge requests found
[package]
name = "micro_games_macros"
version = "0.4.0"
version = "0.5.0"
edition = "2021"
authors = ["Louis Capitanchik <contact@louiscap.co>"]
description = "Utility macros to make it easier to build complex systems with Bevy"
......@@ -25,13 +25,14 @@ test-case = "3.3.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
anyhow = "1.0"
micro_bevy_world_utils = "0.4.0"
micro_bevy_world_utils = "0.5"
[dev-dependencies.bevy]
version = "0.13"
version = "0.14"
default-features = false
features = [
"bevy_asset",
"bevy_sprite",
"bevy_core_pipeline",
"serialize"
]
......@@ -5,7 +5,7 @@
A collection of utility macros for building games
**Current Version Support: 0.2.x -> Bevy 0.12**
**Current Version Support: 0.5.x -> Bevy 0.14**
## Macros
......@@ -13,8 +13,10 @@ For executable examples, visit the rustdoc and/or read the doctests in `src/lib.
### JSON Loader
Generate a Bevy asset loader for a given asset, supporting JSON files that define a single instance of that asset type, or a
list of that asset type. Instances of an asset need to be identifiable, though the property that is used to identify a particular
Generate a Bevy asset loader for a given asset, supporting JSON files that define a single instance of that asset type,
or a
list of that asset type. Instances of an asset need to be identifiable, though the property that is used to identify a
particular
asset is customisable
```rust
......@@ -26,9 +28,9 @@ asset is customisable
)]
#[uuid = "00000000-0000-0000-0000-000000000001"]
pub struct MyAsset {
/// The asset identifier needs to implement [std::fmt::Display]
#[asset_id]
uniq_ident: usize,
/// The asset identifier needs to implement [std::fmt::Display]
#[asset_id]
uniq_ident: usize,
}
```
......@@ -42,14 +44,14 @@ use micro_games_macros::asset_system;
#[asset_system]
pub struct AssetHandles {
my_asset: Image,
my_asset: Image,
}
pub fn loading_system(mut loader: AssetHandlesLoader) {
loader.load_my_asset("path/to/asset.png", "Asset");
loader.load_my_asset("path/to/asset.png", "Asset");
}
pub fn use_asset_system(assets: Res<AssetHandles>) {
let handle = assets.my_asset("Asset");
let handle = assets.my_asset("Asset");
}
```
......
......@@ -56,7 +56,6 @@ fq!(BevyAsset => ::bevy::asset::Asset);
fq!(BevyAssets => ::bevy::asset::Assets);
fq!(BevyAssetEvent => ::bevy::asset::AssetEvent);
fq!(BevyAssetLoader => ::bevy::asset::AssetLoader);
fq!(BevyBoxedFuture => ::bevy::asset::BoxedFuture);
fq!(BevyLoadContext => ::bevy::asset::LoadContext);
fq!(BevyLoadedAsset => ::bevy::asset::LoadedAsset);
fq!(BevyAssetServer => ::bevy::asset::AssetServer);
......
......@@ -122,20 +122,28 @@ pub fn define_loader(
type Settings = ();
type Error = #error_name;
fn load<'a>(
async fn load<'a>(
&'a self,
mut reader: &'a mut #BevyAssetReader,
mut reader: &'a mut #BevyAssetReader<'_>,
_settings: &'a Self::Settings,
load_context: &'a mut #BevyLoadContext,
) -> #BevyBoxedFuture<'a, #FQResult<Self::Asset, Self::Error>> {
#FQBox::pin(async move {
let mut bytes = #FQVec::new();
#BevyAsyncRead::read_to_end(&mut reader, &mut bytes).await?;
let data: #set_name = ::serde_json::from_slice(bytes.as_slice())?;
let mut asset_map = #FQHashMap::new();
match data {
#set_name::One(single_asset) => {
load_context: &'a mut #BevyLoadContext<'_>,
) -> #FQResult<Self::Asset, Self::Error> {
let mut bytes = #FQVec::new();
#BevyAsyncRead::read_to_end(&mut reader, &mut bytes).await?;
let data: #set_name = ::serde_json::from_slice(bytes.as_slice())?;
let mut asset_map = #FQHashMap::new();
match data {
#set_name::One(single_asset) => {
let asset_id = format!("{}", &single_asset.#id_field);
let handle = load_context.add_labeled_asset(
asset_id.clone(),
single_asset,
);
asset_map.insert(asset_id, handle);
}
#set_name::Many(asset_list) => {
for single_asset in asset_list.into_iter() {
let asset_id = format!("{}", &single_asset.#id_field);
let handle = load_context.add_labeled_asset(
asset_id.clone(),
......@@ -143,19 +151,9 @@ pub fn define_loader(
);
asset_map.insert(asset_id, handle);
}
#set_name::Many(asset_list) => {
for single_asset in asset_list.into_iter() {
let asset_id = format!("{}", &single_asset.#id_field);
let handle = load_context.add_labeled_asset(
asset_id.clone(),
single_asset,
);
asset_map.insert(asset_id, handle);
}
}
}
Ok(#index_name(asset_map))
})
}
Ok(#index_name(asset_map))
}
fn extensions(&self) -> &[&str] {
......@@ -213,7 +211,7 @@ pub fn define_load_handler(
match event {
#BevyAssetEvent::LoadedWithDependencies { id } | #BevyAssetEvent::Added { id } | #BevyAssetEvent::Modified { id } => {
let handle = #BevyHandle::Weak(*id);
if let Some(asset_container) = asset_data.get(handle) {
if let Some(asset_container) = asset_data.get(&handle) {
for (id, handle) in asset_container.iter() {
asset_storage.#storage_asset_name.insert(id.clone(), handle.clone());
}
......
......@@ -249,7 +249,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, TextureAtlasLayout, Vec2};
/// use bevy::prelude::{Assets, Event, EventWriter, Handle, Image, ResMut, TextureAtlasLayout, UVec2};
/// use micro_games_macros::{asset_system, loader_property};
///
/// #[derive(Event)]
......@@ -269,7 +269,7 @@ pub fn json_loader(input: TokenStream) -> TokenStream {
/// impl<'w> AssetHandlesLoader<'w> {
/// pub fn load_spritesheet(&mut self, path: String, name: String) -> Handle<TextureAtlasLayout> {
/// let image_handle = self.load_image(path, name.clone());
/// let sheet = TextureAtlasLayout::new_empty(Vec2::ZERO);
/// let sheet = TextureAtlasLayout::new_empty(UVec2::ZERO);
/// let sheet_handle = self.sheets.add(sheet);
///
/// self.storage
......
......@@ -29,7 +29,7 @@ fn event_system_correctly_generates_and_dispatches_events() {
);
dispatch_my_events(
&mut app.world,
app.world_mut(),
MyEvents::Wait(WaitEvent {
source: Entity::from_raw(0),
}),
......@@ -37,5 +37,5 @@ fn event_system_correctly_generates_and_dispatches_events() {
app.update();
assert!(app.world.resource::<HasRun>().0);
assert!(app.world().resource::<HasRun>().0);
}
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