Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/bevy_animation/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use bevy_ecs::{
system::{Res, ResMut},
};
use bevy_platform::collections::HashMap;
use bevy_reflect::{prelude::ReflectDefault, Reflect};
use bevy_reflect::{prelude::ReflectDefault, Reflect, TypePath};
use derive_more::derive::From;
use petgraph::{
graph::{DiGraph, NodeIndex},
Expand Down Expand Up @@ -238,7 +238,7 @@ pub enum AnimationNodeType {
///
/// The canonical extension for [`AnimationGraph`]s is `.animgraph.ron`. Plain
/// `.animgraph` is supported as well.
#[derive(Default)]
#[derive(Default, TypePath)]
pub struct AnimationGraphAssetLoader;

/// Errors that can occur when serializing animation graphs to RON.
Expand Down
16 changes: 15 additions & 1 deletion crates/bevy_asset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ mod tests {
pub sub_texts: Vec<String>,
}

#[derive(Default)]
#[derive(Default, TypePath)]
pub struct CoolTextLoader;

#[derive(Error, Debug)]
Expand Down Expand Up @@ -1934,6 +1934,7 @@ mod tests {
.init_asset::<SubText>()
.register_asset_loader(CoolTextLoader);

#[derive(TypePath)]
struct NestedLoadOfSubassetLoader;

impl AssetLoader for NestedLoadOfSubassetLoader {
Expand Down Expand Up @@ -1986,6 +1987,7 @@ mod tests {
// Extension "rsp" for Recursive Self Path (RSP).
dir.insert_asset_text(Path::new("abc.rsp"), "");

#[derive(TypePath)]
struct ImmediateSelfLoader;

impl AssetLoader for ImmediateSelfLoader {
Expand Down Expand Up @@ -2040,6 +2042,7 @@ mod tests {

dir.insert_asset_text(Path::new("abc.rsp"), "");

#[derive(TypePath)]
struct ImmediateSelfLoader;

impl AssetLoader for ImmediateSelfLoader {
Expand Down Expand Up @@ -2103,6 +2106,8 @@ mod tests {

#[derive(Asset, TypePath)]
pub struct TestAsset(Handle<TestAsset>);

#[derive(TypePath)]
struct DeferredSelfLoader;

impl AssetLoader for DeferredSelfLoader {
Expand Down Expand Up @@ -2186,6 +2191,7 @@ mod tests {

dir.insert_asset_text(Path::new("abc.rsp"), "");

#[derive(TypePath)]
struct ReadBytesSelfLoader;

impl AssetLoader for ReadBytesSelfLoader {
Expand Down Expand Up @@ -2270,6 +2276,8 @@ mod tests {

#[derive(Asset, TypePath)]
pub struct TestAssetUD(Handle<crate::LoadedUntypedAsset>);

#[derive(TypePath)]
struct ImmediateSelfLoader;

impl AssetLoader for ImmediateSelfLoader {
Expand Down Expand Up @@ -2531,6 +2539,7 @@ mod tests {
// Note: we can't just use the GatedReader, since currently we hold the handle until after
// we've selected the reader. The GatedReader blocks this process, so we need to wait until
// we gate in the loader instead.
#[derive(TypePath)]
struct GatedLoader {
in_loader_sender: Sender<()>,
gate_receiver: Receiver<()>,
Expand Down Expand Up @@ -2834,6 +2843,7 @@ mod tests {
#[derive(Serialize, Deserialize, Default)]
struct U8LoaderSettings(u8);

#[derive(TypePath)]
struct U8Loader;

impl AssetLoader for U8Loader {
Expand Down Expand Up @@ -2912,6 +2922,7 @@ mod tests {
let (mut app, dir) = create_app();
dir.insert_asset(Path::new("test.txt"), &[]);

#[derive(TypePath)]
struct TwoSubassetLoader;

impl AssetLoader for TwoSubassetLoader {
Expand Down Expand Up @@ -2952,6 +2963,7 @@ mod tests {
}

/// A loader that immediately returns a [`TestAsset`].
#[derive(TypePath)]
struct TrivialLoader;

impl AssetLoader for TrivialLoader {
Expand Down Expand Up @@ -3030,6 +3042,7 @@ mod tests {
#[derive(Asset, TypePath)]
struct DeferredNested(Handle<TestAsset>);

#[derive(TypePath)]
struct DeferredNestedLoader;

impl AssetLoader for DeferredNestedLoader {
Expand Down Expand Up @@ -3057,6 +3070,7 @@ mod tests {
#[derive(Asset, TypePath)]
struct ImmediateNested(Handle<TestAsset>);

#[derive(TypePath)]
struct ImmediateNestedLoader;

impl AssetLoader for ImmediateNestedLoader {
Expand Down
13 changes: 7 additions & 6 deletions crates/bevy_asset/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use alloc::{
use atomicow::CowArc;
use bevy_ecs::{error::BevyError, world::World};
use bevy_platform::collections::{HashMap, HashSet};
use bevy_reflect::TypePath;
use bevy_tasks::{BoxedFuture, ConditionalSendFuture};
use core::any::{Any, TypeId};
use downcast_rs::{impl_downcast, Downcast};
Expand All @@ -28,7 +29,7 @@ use thiserror::Error;
/// This trait is generally used in concert with [`AssetReader`](crate::io::AssetReader) to load assets from a byte source.
///
/// For a complementary version of this trait that can save assets, see [`AssetSaver`](crate::saver::AssetSaver).
pub trait AssetLoader: Send + Sync + 'static {
pub trait AssetLoader: TypePath + Send + Sync + 'static {
/// The top level [`Asset`] loaded by this [`AssetLoader`].
type Asset: Asset;
/// The settings type used by this [`AssetLoader`].
Expand Down Expand Up @@ -66,8 +67,8 @@ pub trait ErasedAssetLoader: Send + Sync + 'static {
fn deserialize_meta(&self, meta: &[u8]) -> Result<Box<dyn AssetMetaDyn>, DeserializeMetaError>;
/// Returns the default meta value for the [`AssetLoader`] (erased as [`Box<dyn AssetMetaDyn>`]).
fn default_meta(&self) -> Box<dyn AssetMetaDyn>;
/// Returns the type name of the [`AssetLoader`].
fn type_name(&self) -> &'static str;
/// Returns the type path of the [`AssetLoader`].
fn type_path(&self) -> &'static str;
/// Returns the [`TypeId`] of the [`AssetLoader`].
fn type_id(&self) -> TypeId;
/// Returns the type name of the top-level [`Asset`] loaded by the [`AssetLoader`].
Expand Down Expand Up @@ -111,13 +112,13 @@ where

fn default_meta(&self) -> Box<dyn AssetMetaDyn> {
Box::new(AssetMeta::<L, ()>::new(crate::meta::AssetAction::Load {
loader: self.type_name().to_string(),
loader: self.type_path().to_string(),
settings: L::Settings::default(),
}))
}

fn type_name(&self) -> &'static str {
core::any::type_name::<L>()
fn type_path(&self) -> &'static str {
L::type_path()
}

fn type_id(&self) -> TypeId {
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_asset/src/loader_builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ impl NestedLoader<'_, '_, StaticTyped, Immediate<'_, '_>> {
path,
requested: TypeId::of::<A>(),
actual_asset_name: loader.asset_type_name(),
loader_name: loader.type_name(),
loader_name: loader.type_path(),
},
})
})
Expand Down
Loading