bevy/crates
Zachary Harrold afa7b5cba5
Added Support for Extension-less Assets (#10153)
# Objective

- Addresses **Support processing and loading files without extensions**
from #9714
- Addresses **More runtime loading configuration** from #9714
- Fixes #367
- Fixes #10703

## Solution

`AssetServer::load::<A>` and `AssetServer::load_with_settings::<A>` can
now use the `Asset` type parameter `A` to select a registered
`AssetLoader` without inspecting the provided `AssetPath`. This change
cascades onto `LoadContext::load` and `LoadContext::load_with_settings`.
This allows the loading of assets which have incorrect or ambiguous file
extensions.

```rust
// Allow the type to be inferred by context
let handle = asset_server.load("data/asset_no_extension");

// Hint the type through the handle
let handle: Handle<CustomAsset> = asset_server.load("data/asset_no_extension");

// Explicit through turbofish
let handle = asset_server.load::<CustomAsset>("data/asset_no_extension");
```

Since a single `AssetPath` no longer maps 1:1 with an `Asset`, I've also
modified how assets are loaded to permit multiple asset types to be
loaded from a single path. This allows for two different `AssetLoaders`
(which return different types of assets) to both load a single path (if
requested).

```rust
// Uses GltfLoader
let model = asset_server.load::<Gltf>("cube.gltf");

// Hypothetical Blob loader for data transmission (for example)
let blob = asset_server.load::<Blob>("cube.gltf");
```

As these changes are reflected in the `LoadContext` as well as the
`AssetServer`, custom `AssetLoaders` can also take advantage of this
behaviour to create more complex assets.

---

## Change Log

- Updated `custom_asset` example to demonstrate extension-less assets.
- Added `AssetServer::get_handles_untyped` and Added
`AssetServer::get_path_ids`

## Notes

As a part of that refactor, I chose to store `AssetLoader`s (within
`AssetLoaders`) using a `HashMap<TypeId, ...>` instead of a `Vec<...>`.
My reasoning for this was I needed to add a relationship between `Asset`
`TypeId`s and the `AssetLoader`, so instead of having a `Vec` and a
`HashMap`, I combined the two, removing the `usize` index from the
adjacent maps.

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
2024-01-31 14:58:08 +00:00
..
bevy_a11y resolve all internal ambiguities (#10411) 2024-01-09 19:08:15 +00:00
bevy_animation Replace the cubic_spline_interpolation macro with a generic function (#11605) 2024-01-29 19:50:30 +00:00
bevy_app Expressively define plugins using functions (#11080) 2024-01-27 02:40:15 +00:00
bevy_asset Added Support for Extension-less Assets (#10153) 2024-01-31 14:58:08 +00:00
bevy_audio Optional override for global spatial scale (#10419) 2024-01-25 16:29:35 +00:00
bevy_core Derive Debug for Framecount (#11573) 2024-01-28 13:25:49 +00:00
bevy_core_pipeline RenderGraph Labelization (#10644) 2024-01-31 14:51:19 +00:00
bevy_derive Reexport winit::platform::android::activity::* in bevy_winit (#11011) 2023-12-19 20:15:03 +00:00
bevy_diagnostic Replace DiagnosticId by DiagnosticPath (#9266) 2024-01-20 15:42:51 +00:00
bevy_dylib Add [lints] table, fix adding #![allow(clippy::type_complexity)] everywhere (#10011) 2023-11-18 20:58:48 +00:00
bevy_dynamic_plugin Mark DynamicPluginLoadError internal error types as source (#11618) 2024-01-30 23:37:00 +00:00
bevy_ecs Add a doctest example for EntityMapper (#11583) 2024-01-29 16:56:44 +00:00
bevy_ecs_compile_fail_tests Dynamic queries and builder API (#9774) 2024-01-16 19:16:49 +00:00
bevy_encase_derive Add [lints] table, fix adding #![allow(clippy::type_complexity)] everywhere (#10011) 2023-11-18 20:58:48 +00:00
bevy_gilrs Remove unnecessary path prefixes (#10749) 2023-11-28 23:43:40 +00:00
bevy_gizmos RenderAssetPersistencePolicy → RenderAssetUsages (#11399) 2024-01-30 13:22:10 +00:00
bevy_gltf RenderAssetPersistencePolicy → RenderAssetUsages (#11399) 2024-01-30 13:22:10 +00:00
bevy_hierarchy Make the MapEntities trait generic over Mappers, and add a simpler EntityMapper (#11428) 2024-01-28 19:51:46 +00:00
bevy_input Fix cyclic dep (#11523) 2024-01-25 17:44:32 +00:00
bevy_internal Add Accessibility plugin to default plugins docs (#11512) 2024-01-28 10:04:43 +00:00
bevy_log move once from bevy_log to bevy_utils, to allow for it's use in bevy_ecs (#11419) 2024-01-19 06:07:41 +00:00
bevy_macro_utils Bump toml_edit in build-template-pages tool (#11342) 2024-01-16 05:23:18 +00:00
bevy_macros_compile_fail_tests Standardize toml format with taplo (#10594) 2023-11-21 01:04:14 +00:00
bevy_math Add Capsule2d primitive (#11585) 2024-01-29 17:52:04 +00:00
bevy_mikktspace Enable the unsafe_op_in_unsafe_fn lint (#11591) 2024-01-28 23:18:11 +00:00
bevy_pbr RenderGraph Labelization (#10644) 2024-01-31 14:51:19 +00:00
bevy_ptr bevy_ptr: fix unsafe_op_in_unsafe_fn lint (#11610) 2024-01-30 23:37:29 +00:00
bevy_reflect reflection: replace impl_reflect_struct with impl_reflect (#11437) 2024-01-30 14:39:01 +00:00
bevy_reflect_compile_fail_tests bevy_reflect: Type parameter bounds (#9046) 2024-01-28 16:24:03 +00:00
bevy_render RenderGraph Labelization (#10644) 2024-01-31 14:51:19 +00:00
bevy_scene Make the MapEntities trait generic over Mappers, and add a simpler EntityMapper (#11428) 2024-01-28 19:51:46 +00:00
bevy_sprite RenderAssetPersistencePolicy → RenderAssetUsages (#11399) 2024-01-30 13:22:10 +00:00
bevy_tasks Fix wrong transmuted type in TaskPool::scope_with_executor_inner (#11455) 2024-01-21 18:08:45 +00:00
bevy_text RenderAssetPersistencePolicy → RenderAssetUsages (#11399) 2024-01-30 13:22:10 +00:00
bevy_time Add paused run condition (#11313) 2024-01-12 22:18:57 +00:00
bevy_transform refactor: Simplify lifetimes for Commands and related types (#11445) 2024-01-22 15:35:42 +00:00
bevy_ui RenderGraph Labelization (#10644) 2024-01-31 14:51:19 +00:00
bevy_utils impl Borrow and AsRef for CowArc (#11616) 2024-01-30 14:27:53 +00:00
bevy_window Update cursor.rs (#11617) 2024-01-30 16:34:17 +00:00
bevy_winit Cleanup bevy winit (#11489) 2024-01-28 21:09:23 +00:00