Skip to content

Commit

Permalink
Fix tests and unused imports
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasEi committed Nov 1, 2023
1 parent ab26599 commit a531458
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
4 changes: 2 additions & 2 deletions bevy_asset_loader/tests/mapped_path_use_slash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use bevy_asset_loader::loading_state::{LoadingState, LoadingStateAppExt};
not(feature = "progress_tracking")
))]
#[test]
fn multiple_asset_collections() {
fn mapped_path_use_slash() {
App::new()
.add_state::<MyStates>()
.add_plugins((
Expand Down Expand Up @@ -56,7 +56,7 @@ fn expect(collection: Option<Res<AudioCollection>>, mut exit: EventWriter<AppExi

#[derive(AssetCollection, Resource, Debug)]
struct AudioCollection {
#[asset(path = "audio/test", collection(typed, mapped))]
#[asset(path = "audio", collection(typed, mapped))]
files: HashMap<String, Handle<AudioSource>>,
#[asset(path = "audio/yipee.ogg")]
single_file: Handle<AudioSource>,
Expand Down
2 changes: 1 addition & 1 deletion bevy_asset_loader/tests/ui/no_default.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ error[E0277]: the trait bound `NoDefault: std::default::Default` is not satisfie
SceneLoader
MsaaWritebackNode
Material2dPipeline<M>
BlitPipeline
Mesh2dPipeline
and $N others
= note: required for `NoDefault` to implement `FromWorld`
help: consider annotating `NoDefault` with `#[derive(Default)]`
Expand Down
10 changes: 5 additions & 5 deletions bevy_asset_loader_derive/src/assets.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{ParseFieldError, TextureAtlasAttribute, TEXTURE_ATLAS_ATTRIBUTE};
use crate::{ParseFieldError, TextureAtlasAttribute};
use proc_macro2::{Ident, TokenStream};
use quote::quote;

Expand Down Expand Up @@ -509,28 +509,28 @@ impl AssetBuilder {
if self.tile_size_x.is_none() {
missing_fields.push(format!(
"{}/{}",
TEXTURE_ATLAS_ATTRIBUTE,
TextureAtlasAttribute::ATTRIBUTE_NAME,
TextureAtlasAttribute::TILE_SIZE_X
));
}
if self.tile_size_y.is_none() {
missing_fields.push(format!(
"{}/{}",
TEXTURE_ATLAS_ATTRIBUTE,
TextureAtlasAttribute::ATTRIBUTE_NAME,
TextureAtlasAttribute::TILE_SIZE_Y
));
}
if self.columns.is_none() {
missing_fields.push(format!(
"{}/{}",
TEXTURE_ATLAS_ATTRIBUTE,
TextureAtlasAttribute::ATTRIBUTE_NAME,
TextureAtlasAttribute::COLUMNS
));
}
if self.rows.is_none() {
missing_fields.push(format!(
"{}/{}",
TEXTURE_ATLAS_ATTRIBUTE,
TextureAtlasAttribute::ATTRIBUTE_NAME,
TextureAtlasAttribute::ROWS
));
}
Expand Down
24 changes: 16 additions & 8 deletions bevy_asset_loader_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ use crate::assets::*;
use proc_macro2::Ident;
use quote::{quote, quote_spanned, ToTokens, TokenStreamExt};
use syn::punctuated::Punctuated;
use syn::{Data, Expr, ExprLit, ExprPath, Field, Fields, Index, Lit, LitStr, Meta, Token};
#[cfg(any(feature = "2d", feature = "3d"))]
use syn::ExprPath;
use syn::{Data, Expr, ExprLit, Field, Fields, Index, Lit, LitStr, Meta, Token};

/// Derive macro for [`AssetCollection`]
///
Expand All @@ -37,9 +39,9 @@ pub(crate) const PATH_ATTRIBUTE: &str = "path";
pub(crate) const KEY_ATTRIBUTE: &str = "key";
pub(crate) const OPTIONAL_ATTRIBUTE: &str = "optional";

pub(crate) const TEXTURE_ATLAS_ATTRIBUTE: &str = "texture_atlas";
pub(crate) struct TextureAtlasAttribute;
impl TextureAtlasAttribute {
pub const ATTRIBUTE_NAME: &'static str = "texture_atlas";
pub const TILE_SIZE_X: &'static str = "tile_size_x";
pub const TILE_SIZE_Y: &'static str = "tile_size_y";
pub const COLUMNS: &'static str = "columns";
Expand All @@ -54,9 +56,10 @@ impl TextureAtlasAttribute {
pub const OFFSET_Y: &'static str = "offset_y";
}

pub(crate) const IMAGE_ATTRIBUTE: &str = "image";
pub(crate) struct ImageAttribute;
impl ImageAttribute {
pub const ATTRIBUTE_NAME: &'static str = "image";
#[allow(dead_code)]
pub const SAMPLER: &'static str = "sampler";
}

Expand Down Expand Up @@ -183,11 +186,10 @@ fn impl_asset_collection(
}
};

let mut prepare_from_world = quote! {};
prepare_from_world.append_all(from_world_fields.iter().fold(
let prepare_from_world = from_world_fields.iter().fold(
quote!(),
|es, ident| quote_spanned! {ident.span() => #es ::bevy::ecs::world::FromWorld::from_world(world),},
));
);

let mut asset_creation = assets.iter().fold(quote!(), |token_stream, asset| {
asset.attach_token_stream_for_creation(token_stream, name.to_string())
Expand Down Expand Up @@ -256,7 +258,11 @@ fn parse_field(field: &Field) -> Result<AssetField, Vec<ParseFieldError>> {

for attribute in asset_meta_list.unwrap() {
match attribute {
Meta::List(meta_list) if meta_list.path.is_ident(TEXTURE_ATLAS_ATTRIBUTE) => {
Meta::List(meta_list)
if meta_list
.path
.is_ident(TextureAtlasAttribute::ATTRIBUTE_NAME) =>
{
#[cfg(not(feature = "2d"))]
errors.push(ParseFieldError::Missing2dFeature(
meta_list.into_token_stream(),
Expand Down Expand Up @@ -433,7 +439,9 @@ fn parse_field(field: &Field) -> Result<AssetField, Vec<ParseFieldError>> {
}
builder.asset_paths = Some(paths);
}
Meta::List(meta_list) if meta_list.path.is_ident(IMAGE_ATTRIBUTE) => {
Meta::List(meta_list)
if meta_list.path.is_ident(ImageAttribute::ATTRIBUTE_NAME) =>
{
#[cfg(all(not(feature = "2d"), not(feature = "3d")))]
errors.push(ParseFieldError::Missing2dOr3dFeature(
meta_list.into_token_stream(),
Expand Down

0 comments on commit a531458

Please sign in to comment.