Skip to content
Open
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
22 changes: 9 additions & 13 deletions crates/bevy_asset/src/io/embedded/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ mod embedded_watcher;

#[cfg(feature = "embedded_watcher")]
pub use embedded_watcher::*;
use tracing::error;

use crate::io::{
memory::{Dir, MemoryAssetReader, Value},
AssetSourceBuilder, AssetSourceBuilders,
AssetSourceBuilder, AssetSources,
};
use crate::AssetServer;
use alloc::boxed::Box;
Expand All @@ -19,8 +20,7 @@ use std::path::{Path, PathBuf};
#[cfg(feature = "embedded_watcher")]
use alloc::borrow::ToOwned;

/// The name of the `embedded` [`AssetSource`](crate::io::AssetSource),
/// as stored in the [`AssetSourceBuilders`] resource.
/// The name of the `embedded` [`AssetSource`](crate::io::AssetSource).
pub const EMBEDDED: &str = "embedded";

/// A [`Resource`] that manages "rust source files" in a virtual in memory [`Dir`], which is intended
Expand Down Expand Up @@ -83,18 +83,12 @@ impl EmbeddedAssetRegistry {
self.dir.remove_asset(full_path)
}

/// Registers the [`EMBEDDED`] [`AssetSource`](crate::io::AssetSource) with the given [`AssetSourceBuilders`].
pub fn register_source(&self, sources: &mut AssetSourceBuilders) {
/// Registers the [`EMBEDDED`] [`AssetSource`](crate::io::AssetSource) with the given
/// [`AssetSources`].
pub fn register_source(&self, sources: &mut AssetSources) {
let dir = self.dir.clone();
let processed_dir = self.dir.clone();

#[cfg_attr(
not(feature = "embedded_watcher"),
expect(
unused_mut,
reason = "Variable is only mutated when `embedded_watcher` feature is enabled."
)
)]
let mut source =
AssetSourceBuilder::new(move || Box::new(MemoryAssetReader { root: dir.clone() }))
.with_processed_reader(move || {
Expand Down Expand Up @@ -132,7 +126,9 @@ impl EmbeddedAssetRegistry {
)))
});
}
sources.insert(EMBEDDED, source);
if let Err(err) = sources.add(EMBEDDED, &mut source) {
error!("Failed to register asset source: {err}");
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_asset/src/io/file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl FileAssetReader {
/// Returns the base path of the assets directory, which is normally the executable's parent
/// directory.
///
/// To change this, set [`AssetPlugin::file_path`][crate::AssetPlugin::file_path].
/// To change this, set [`DefaultAssetSource::Paths::file_path`][crate::DefaultAssetSource::Paths::file_path].
pub fn get_base_path() -> PathBuf {
get_base_path()
}
Expand Down
Loading