bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Add more load_direct implementations

Open ricky26 opened this issue 1 year ago • 2 comments

Objective

  • Introduce variants of LoadContext::load_direct which allow picking asset type & configuring settings.
  • Fixes #12963.

Solution

  • Implements ErasedLoadedAsset::downcast and adds some accessors to LoadedAsset<A>.
  • Changes load_direct/load_direct_with_reader to be typed, and introduces load_direct_untyped/load_direct_untyped_with_reader.
  • Introduces load_direct_with_settings and load_direct_with_reader_and_settings.

Testing

  • I've run cargo test and played with the examples which use load_direct.
  • I also extended the asset_processing example to use the new typed version of load_direct and use load_direct_with_settings.

Changelog

  • Introduced new load_direct methods in LoadContext to allow specifying type & settings

Migration Guide

  • LoadContext::load_direct has been renamed to LoadContext::load_direct_untyped. You may find the new load_direct is more appropriate for your use case (and the migration may only be moving one type parameter).
  • LoadContext::load_direct_with_reader has been renamed to LoadContext::load_direct_untyped_with_reader.

This might not be an obvious win as a solution because it introduces quite a few new load_direct alternatives - but it does follow the existing pattern pretty well. I'm very open to alternatives. :sweat_smile:

ricky26 avatar May 17 '24 14:05 ricky26

@alice-i-cecile I've had a go at implementing a builder-style API. I suspect this is more open to bike-shedding (in particular .load_direct().load() isn't my favourite), and more likely to have other issues. However, I did the simpler tidy-up in the prior commits, in case this proves to be more controversial.

ricky26 avatar May 18 '24 03:05 ricky26

Hmm, I don't think that's an improvement 😅 Neat to see, but I would probably revert the builder experiment. I'll ask folks for more opinions / ideas.

alice-i-cecile avatar May 18 '24 12:05 alice-i-cecile