diff --git a/examples/custom_asset_lifecycle.rs b/examples/custom_asset_lifecycles.rs similarity index 76% rename from examples/custom_asset_lifecycle.rs rename to examples/custom_asset_lifecycles.rs index 6ba3512..5a9e790 100644 --- a/examples/custom_asset_lifecycle.rs +++ b/examples/custom_asset_lifecycles.rs @@ -6,12 +6,7 @@ //! As this example demonstrates, you can bypass the [`ManifestPlugin`](leafwing_manifest::plugin::ManifestPlugin) entirely, and load your assets however you like, //! calling the publicly exposed methods yourself to replicate the work it does. -use bevy::{ - asset::{io::Reader, AssetLoader, AsyncReadExt, LoadContext, LoadState}, - prelude::*, - utils::BoxedFuture, -}; -use bevy_common_assets::ron::RonLoaderError; +use bevy::{asset::LoadState, prelude::*}; use leafwing_manifest::manifest::Manifest; use manifest_definition::{ItemManifest, RawItemManifest}; @@ -105,46 +100,11 @@ mod manifest_definition { fn main() { App::new() .add_plugins(DefaultPlugins) - // Check out this system for all the fancy state management .add_systems(PreUpdate, manage_manifests) - // Remember to initialize your asset types! - .init_asset::() - // Remember to add the required asset loaders! - .register_asset_loader(ItemAssetLoader) .run(); } -// Writing your own asset loaders is quite a bit of boilerplate: -// you need a unique asset loader for each manifest type you want to load. -// Many thanks to bevy_common_assets for showing us how to do this! -struct ItemAssetLoader; - -impl AssetLoader for ItemAssetLoader { - type Asset = RawItemManifest; - type Settings = (); - type Error = RonLoaderError; - - fn load<'a>( - &'a self, - reader: &'a mut Reader, - _settings: &'a Self::Settings, - _load_context: &'a mut LoadContext, - ) -> BoxedFuture<'a, Result> { - Box::pin(async move { - let mut bytes = Vec::new(); - reader.read_to_end(&mut bytes).await?; - let asset = ron::de::from_bytes::(&bytes)?; - Ok(asset) - }) - } - - // The extensions method is ultimately used as a fallback: it isn't helpful for our workflow. - fn extensions(&self) -> &[&str] { - &[] - } -} - -// The same basic workflow applies when managing manifests manually, but you have more control over the process.: +// The same basic workflow applies: // 1. Start loading the raw manifest // 2. Wait for the raw manifest to load // 3. Convert it into a usable form @@ -160,7 +120,7 @@ enum ManifestProgress { /// Handles the entire lifecycle of the manifest. /// -/// This is done here with a tiny and pretty janky single system for simplicity: the core steps can be arranged however you'd like. +/// This is a tiny simple systems for simplicity: the core steps can be arranged however you'd like. /// See the source code of the [`plugin`](leafwing_manifest::plugin) module for further inspiration. fn manage_manifests( mut progress: Local, @@ -168,7 +128,6 @@ fn manage_manifests( mut commands: Commands, asset_server: Res, raw_manifest_assets: Res>, - maybe_final_manifest: Option>, ) { match *progress { // Step 1: Start loading the raw manifest. @@ -216,11 +175,7 @@ fn manage_manifests( }); *progress = ManifestProgress::Processed; } - // Let's double check that this worked! - ManifestProgress::Processed => { - if let Some(final_manifest) = maybe_final_manifest { - info_once!("Final manifest is ready: {:?}", final_manifest); - } - } + // All done: no more work to do! + ManifestProgress::Processed => (), } }