Struct jumpy::prelude::AssetServer
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§
§impl AssetServer
impl AssetServer
pub 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
.
pub 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.
pub 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.
pub 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()
.
pub fn handle_asset_changes<F>(&mut self, handle_change: F)
pub fn handle_asset_changes<F>(&mut self, handle_change: F)
pub 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.
pub 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
.
pub async fn load_core_pack(&self) -> Result<AssetPackSpec, Error>
pub async fn load_core_pack(&self) -> Result<AssetPackSpec, Error>
Load the core asset pack.
pub fn load_asset(&self, loc: AssetLocRef<'_>) -> UntypedHandle
pub fn load_asset(&self, loc: AssetLocRef<'_>) -> UntypedHandle
Load an asset.
pub 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.
pub 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.
pub 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.
pub 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
.
pub 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.
pub 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
.
pub fn packs(&self) -> &DashMap<AssetPackSpec, AssetPack>
pub fn packs(&self) -> &DashMap<AssetPackSpec, AssetPack>
Read the loaded asset packs.
pub 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
.
pub fn get_untyped(
&self,
handle: UntypedHandle,
) -> MappedRef<'_, Cid, LoadedAsset, SchemaBox>
pub fn get_untyped( &self, handle: UntypedHandle, ) -> MappedRef<'_, Cid, LoadedAsset, SchemaBox>
pub fn get_untyped_mut(
&self,
handle: UntypedHandle,
) -> MappedRefMut<'_, Cid, LoadedAsset, SchemaBox>
pub fn get_untyped_mut( &self, handle: UntypedHandle, ) -> MappedRefMut<'_, Cid, LoadedAsset, SchemaBox>
pub 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.
pub 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.
pub 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.
pub 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
.
pub 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
.
pub 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
.
pub 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
.
pub 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
.
pub 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.
pub 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§
§impl AssetServerExt for &mut AssetServer
impl AssetServerExt for &mut AssetServer
§fn register_default_assets(self) -> &mut AssetServer
fn register_default_assets(self) -> &mut AssetServer
bones_framework
.§impl Clone for AssetServer
impl Clone for AssetServer
§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 more§impl Default for AssetServer
impl Default for AssetServer
§fn default() -> AssetServer
fn default() -> AssetServer
§impl Deref for AssetServer
impl Deref for AssetServer
§type Target = Arc<AssetServerInner>
type Target = Arc<AssetServerInner>
§fn deref(&self) -> &<AssetServer as Deref>::Target
fn deref(&self) -> &<AssetServer as Deref>::Target
§impl DerefMut for AssetServer
impl DerefMut for AssetServer
§fn deref_mut(&mut self) -> &mut <AssetServer as Deref>::Target
fn deref_mut(&mut self) -> &mut <AssetServer as Deref>::Target
§impl HasSchema for AssetServer
impl HasSchema for AssetServer
§fn register_schema()
fn register_schema()
§fn cast<T>(this: &Self) -> &Twhere
T: HasSchema,
fn cast<T>(this: &Self) -> &Twhere
T: HasSchema,
§fn try_cast<T>(this: &Self) -> Result<&T, SchemaMismatchError>where
T: HasSchema,
fn try_cast<T>(this: &Self) -> Result<&T, SchemaMismatchError>where
T: HasSchema,
§fn cast_mut<T>(this: &mut Self) -> &mut Twhere
T: HasSchema,
fn cast_mut<T>(this: &mut Self) -> &mut Twhere
T: HasSchema,
§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,
§fn as_schema_ref(&self) -> SchemaRef<'_>where
Self: Sized,
fn as_schema_ref(&self) -> SchemaRef<'_>where
Self: Sized,
T
to a SchemaRef
§fn as_schema_mut(&mut self) -> SchemaRefMut<'_>where
Self: Sized,
fn as_schema_mut(&mut self) -> SchemaRefMut<'_>where
Self: Sized,
T
to a SchemaRefMut
source§impl MatchAssetServerExt for &mut AssetServer
impl MatchAssetServerExt for &mut AssetServer
source§fn register_match_assets(self) -> Self
fn register_match_assets(self) -> Self
bones_framework
.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<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
§fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
T
[ShaderType
] for self
. When used in [AsBindGroup
]
derives, it is safe to assume that all images in self
exist.§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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync 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
§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Self
using data from the given [World]§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
§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>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§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.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> RawDefault for Twhere
T: Default,
impl<T> RawDefault for Twhere
T: Default,
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.§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.