Struct bones_framework::prelude::AssetServer
source · pub struct AssetServer {
pub inner: Arc<AssetServerInner>,
pub io: Arc<dyn AssetIo>,
}
Expand description
Struct responsible for loading assets into it’s contained AssetStore
, using an AssetIo
implementation.
Fields§
§inner: Arc<AssetServerInner>
The asset server inner state.
io: Arc<dyn AssetIo>
The AssetIo
implementation used to load assets.
Implementations§
source§impl AssetServer
impl AssetServer
sourcepub fn new<Io>(io: Io, version: Version) -> AssetServerwhere
Io: AssetIo + 'static,
pub fn new<Io>(io: Io, version: Version) -> AssetServerwhere
Io: AssetIo + 'static,
Initialize a new AssetServer
.
sourcepub async fn load_asset_bytes(
&self,
loc: AssetLoc,
force: bool,
) -> Result<Cid, Error>
pub async fn load_asset_bytes( &self, loc: AssetLoc, force: bool, ) -> Result<Cid, Error>
Load the bytes of the asset at the given path, but return only the Cid
.
The loaded bytes can be accessed from asset_server.store.asset_data
using the Cid
.
If force
is false, the bytes will be loaded from cache if possible.
sourcepub fn watch_for_changes(&self)
pub fn watch_for_changes(&self)
Tell the asset backend to watch for changes and trigger hot reloads for changed assets.
sourcepub fn set_io<Io>(&mut self, io: Io)where
Io: AssetIo + 'static,
pub fn set_io<Io>(&mut self, io: Io)where
Io: AssetIo + 'static,
Set the AssetIo
implementation.
This should almost always be called before calling load_assets()
.
sourcepub fn handle_asset_changes<F>(&mut self, handle_change: F)
pub fn handle_asset_changes<F>(&mut self, handle_change: F)
sourcepub async fn load_assets(&self) -> Result<(), Error>
pub async fn load_assets(&self) -> Result<(), Error>
Load all assets. This is usually done in an async task.
sourcepub async fn load_pack(
&self,
pack: Option<&str>,
) -> Result<AssetPackSpec, Error>
pub async fn load_pack( &self, pack: Option<&str>, ) -> Result<AssetPackSpec, Error>
Load the asset pack with the given folder name, or else the default pack if None
.
sourcepub async fn load_core_pack(&self) -> Result<AssetPackSpec, Error>
pub async fn load_core_pack(&self) -> Result<AssetPackSpec, Error>
Load the core asset pack.
sourcepub fn load_asset(&self, loc: AssetLocRef<'_>) -> UntypedHandle
pub fn load_asset(&self, loc: AssetLocRef<'_>) -> UntypedHandle
Load an asset.
sourcepub fn load_asset_forced(&self, loc: AssetLocRef<'_>) -> UntypedHandle
pub fn load_asset_forced(&self, loc: AssetLocRef<'_>) -> UntypedHandle
Like load_asset()
but forces the asset to reload, even it if has
already been loaded.
sourcepub fn get_asset_untyped(
&self,
handle: UntypedHandle,
) -> Option<Ref<'_, Cid, LoadedAsset>>
pub fn get_asset_untyped( &self, handle: UntypedHandle, ) -> Option<Ref<'_, Cid, LoadedAsset>>
Borrow a LoadedAsset
associated to the given handle.
sourcepub fn get_asset_untyped_mut(
&self,
handle: UntypedHandle,
) -> Option<RefMut<'_, Cid, LoadedAsset>>
pub fn get_asset_untyped_mut( &self, handle: UntypedHandle, ) -> Option<RefMut<'_, Cid, LoadedAsset>>
Borrow a LoadedAsset
associated to the given handle.
sourcepub fn core(&self) -> MappedMutexGuard<'_, RawMutex, AssetPack>
pub fn core(&self) -> MappedMutexGuard<'_, RawMutex, AssetPack>
Read the core asset pack.
§Panics
Panics if the assets have not be loaded yet with AssetServer::load_assets
.
sourcepub fn root<T>(&self) -> MappedRef<'_, Cid, LoadedAsset, T>where
T: HasSchema,
pub fn root<T>(&self) -> MappedRef<'_, Cid, LoadedAsset, T>where
T: HasSchema,
Get the core asset pack’s root asset.
sourcepub fn untyped_root(&self) -> MappedRef<'_, Cid, LoadedAsset, SchemaBox>
pub fn untyped_root(&self) -> MappedRef<'_, Cid, LoadedAsset, SchemaBox>
Get the core asset pack’s root asset as a type-erased SchemaBox
.
sourcepub fn packs(&self) -> &DashMap<AssetPackSpec, AssetPack>
pub fn packs(&self) -> &DashMap<AssetPackSpec, AssetPack>
Read the loaded asset packs.
sourcepub fn get<T>(&self, handle: Handle<T>) -> MappedRef<'_, Cid, LoadedAsset, T>where
T: HasSchema,
pub fn get<T>(&self, handle: Handle<T>) -> MappedRef<'_, Cid, LoadedAsset, T>where
T: HasSchema,
Borrow a loaded asset.
§Panics
Panics if the asset is not loaded or if the asset asset with the given handle doesn’t have a
schema matching T
.
sourcepub fn get_untyped(
&self,
handle: UntypedHandle,
) -> MappedRef<'_, Cid, LoadedAsset, SchemaBox>
pub fn get_untyped( &self, handle: UntypedHandle, ) -> MappedRef<'_, Cid, LoadedAsset, SchemaBox>
sourcepub fn get_untyped_mut(
&self,
handle: UntypedHandle,
) -> MappedRefMut<'_, Cid, LoadedAsset, SchemaBox>
pub fn get_untyped_mut( &self, handle: UntypedHandle, ) -> MappedRefMut<'_, Cid, LoadedAsset, SchemaBox>
sourcepub fn try_get<T>(
&self,
handle: Handle<T>,
) -> Option<Result<MappedRef<'_, Cid, LoadedAsset, T>, SchemaMismatchError>>where
T: HasSchema,
pub fn try_get<T>(
&self,
handle: Handle<T>,
) -> Option<Result<MappedRef<'_, Cid, LoadedAsset, T>, SchemaMismatchError>>where
T: HasSchema,
Borrow a loaded asset.
Returns None if asset not found and Some(SchemaMismatchError
) if type cast fails.
sourcepub fn try_get_untyped(
&self,
handle: UntypedHandle,
) -> Option<MappedRef<'_, Cid, LoadedAsset, SchemaBox>>
pub fn try_get_untyped( &self, handle: UntypedHandle, ) -> Option<MappedRef<'_, Cid, LoadedAsset, SchemaBox>>
Borrow a loaded asset.
sourcepub fn try_get_untyped_mut(
&self,
handle: UntypedHandle,
) -> Option<MappedRefMut<'_, Cid, LoadedAsset, SchemaBox>>
pub fn try_get_untyped_mut( &self, handle: UntypedHandle, ) -> Option<MappedRefMut<'_, Cid, LoadedAsset, SchemaBox>>
Borrow a loaded asset.
sourcepub fn get_handle_from_cid<T>(&self, cid: &Cid) -> Handle<T>
pub fn get_handle_from_cid<T>(&self, cid: &Cid) -> Handle<T>
Get handle of loaded asset from content id Cid
.
sourcepub fn get_untyped_handle_from_cid(&self, cid: &Cid) -> UntypedHandle
pub fn get_untyped_handle_from_cid(&self, cid: &Cid) -> UntypedHandle
Get untyped handle of loaded asset from content id Cid
.
sourcepub fn try_get_handle_from_cid<T>(&self, cid: &Cid) -> Option<Handle<T>>
pub fn try_get_handle_from_cid<T>(&self, cid: &Cid) -> Option<Handle<T>>
Try to get handle of loaded asset from content id Cid
.
sourcepub fn try_get_untyped_handle_from_cid(
&self,
cid: &Cid,
) -> Option<UntypedHandle>
pub fn try_get_untyped_handle_from_cid( &self, cid: &Cid, ) -> Option<UntypedHandle>
Try to get untyped handle of loaded asset from content id Cid
.
sourcepub fn get_mut<T>(
&mut self,
handle: &Handle<T>,
) -> MappedRefMut<'_, Cid, LoadedAsset, T>where
T: HasSchema,
pub fn get_mut<T>(
&mut self,
handle: &Handle<T>,
) -> MappedRefMut<'_, Cid, LoadedAsset, T>where
T: HasSchema,
Mutably borrow a loaded asset.
§Panics
Panics if the asset is not loaded or if the asset asset with the given handle doesn’t have a
schema matching T
.
sourcepub fn game_version(&self) -> Version
pub fn game_version(&self) -> Version
Get the game version config, used when making sure asset packs are compatible with this game version.
sourcepub fn set_game_version(&self, version: Version)
pub fn set_game_version(&self, version: Version)
Set the game version config, used when making sure asset packs are compatible with this game version.
Trait Implementations§
source§impl AssetServerExt for &mut AssetServer
impl AssetServerExt for &mut AssetServer
source§fn register_default_assets(self) -> Self
fn register_default_assets(self) -> Self
bones_framework
.source§impl Clone for AssetServer
impl Clone for AssetServer
source§fn clone(&self) -> AssetServer
fn clone(&self) -> AssetServer
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Default for AssetServer
impl Default for AssetServer
source§fn default() -> AssetServer
fn default() -> AssetServer
source§impl Deref for AssetServer
impl Deref for AssetServer
§type Target = Arc<AssetServerInner>
type Target = Arc<AssetServerInner>
source§impl DerefMut for AssetServer
impl DerefMut for AssetServer
source§impl HasSchema for AssetServer
impl HasSchema for AssetServer
source§fn register_schema()
fn register_schema()
source§fn cast<T>(this: &Self) -> &Twhere
T: HasSchema,
fn cast<T>(this: &Self) -> &Twhere
T: HasSchema,
source§fn try_cast<T>(this: &Self) -> Result<&T, SchemaMismatchError>where
T: HasSchema,
fn try_cast<T>(this: &Self) -> Result<&T, SchemaMismatchError>where
T: HasSchema,
source§fn cast_mut<T>(this: &mut Self) -> &mut Twhere
T: HasSchema,
fn cast_mut<T>(this: &mut Self) -> &mut Twhere
T: HasSchema,
source§fn try_cast_mut<T>(this: &mut Self) -> Result<&mut T, SchemaMismatchError>where
T: HasSchema,
fn try_cast_mut<T>(this: &mut Self) -> Result<&mut T, SchemaMismatchError>where
T: HasSchema,
source§fn as_schema_ref(&self) -> SchemaRef<'_>where
Self: Sized,
fn as_schema_ref(&self) -> SchemaRef<'_>where
Self: Sized,
T
to a SchemaRef
source§fn as_schema_mut(&mut self) -> SchemaRefMut<'_>where
Self: Sized,
fn as_schema_mut(&mut self) -> SchemaRefMut<'_>where
Self: Sized,
T
to a SchemaRefMut
Auto Trait Implementations§
impl Freeze for AssetServer
impl !RefUnwindSafe for AssetServer
impl Send for AssetServer
impl Sync for AssetServer
impl Unpin for AssetServer
impl !UnwindSafe for AssetServer
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
source§fn from_world(_world: &World) -> T
fn from_world(_world: &World) -> T
Self
using data from the given World
.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> IntoArcAny for T
impl<T> IntoArcAny for T
§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.source§impl<T> RawDefault for Twhere
T: Default,
impl<T> RawDefault for Twhere
T: Default,
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.