Struct bones_asset::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: AssetIo + 'static>(io: Io, version: Version) -> Self
pub fn new<Io: AssetIo + 'static>(io: Io, version: Version) -> Self
Initialize a new AssetServer
.
sourcepub async fn load_asset_bytes(&self, loc: AssetLoc, force: bool) -> Result<Cid>
pub async fn load_asset_bytes(&self, loc: AssetLoc, force: bool) -> Result<Cid>
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: AssetIo + 'static>(&mut self, io: Io)
pub fn set_io<Io: AssetIo + 'static>(&mut self, io: Io)
Set the AssetIo
implementation.
This should almost always be called before calling load_assets()
.
sourcepub fn handle_asset_changes<F: FnMut(&mut AssetServer, UntypedHandle)>(
&mut self,
handle_change: F,
)
pub fn handle_asset_changes<F: FnMut(&mut AssetServer, UntypedHandle)>( &mut self, handle_change: F, )
sourcepub async fn load_assets(&self) -> Result<()>
pub async fn load_assets(&self) -> Result<()>
Load all assets. This is usually done in an async task.
sourcepub async fn load_pack(&self, pack: Option<&str>) -> Result<AssetPackSpec>
pub async fn load_pack(&self, pack: Option<&str>) -> Result<AssetPackSpec>
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>
pub async fn load_core_pack(&self) -> Result<AssetPackSpec>
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<MapRef<'_, Cid, LoadedAsset>>
pub fn get_asset_untyped( &self, handle: UntypedHandle, ) -> Option<MapRef<'_, Cid, LoadedAsset>>
Borrow a LoadedAsset
associated to the given handle.
sourcepub fn get_asset_untyped_mut(
&self,
handle: UntypedHandle,
) -> Option<MapRefMut<'_, Cid, LoadedAsset>>
pub fn get_asset_untyped_mut( &self, handle: UntypedHandle, ) -> Option<MapRefMut<'_, Cid, LoadedAsset>>
Borrow a LoadedAsset
associated to the given handle.
sourcepub fn core(&self) -> MappedMutexGuard<'_, AssetPack>
pub fn core(&self) -> MappedMutexGuard<'_, AssetPack>
Read the core asset pack.
§Panics
Panics if the assets have not be loaded yet with AssetServer::load_assets
.
sourcepub fn root<T: HasSchema>(&self) -> MappedMapRef<'_, Cid, LoadedAsset, T>
pub fn root<T: HasSchema>(&self) -> MappedMapRef<'_, Cid, LoadedAsset, T>
Get the core asset pack’s root asset.
sourcepub fn untyped_root(&self) -> MappedMapRef<'_, Cid, LoadedAsset, SchemaBox>
pub fn untyped_root(&self) -> MappedMapRef<'_, 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: HasSchema>(
&self,
handle: Handle<T>,
) -> MappedMapRef<'_, Cid, LoadedAsset, T>
pub fn get<T: HasSchema>( &self, handle: Handle<T>, ) -> MappedMapRef<'_, Cid, LoadedAsset, T>
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,
) -> MappedMapRef<'_, Cid, LoadedAsset, SchemaBox>
pub fn get_untyped( &self, handle: UntypedHandle, ) -> MappedMapRef<'_, Cid, LoadedAsset, SchemaBox>
sourcepub fn get_untyped_mut(
&self,
handle: UntypedHandle,
) -> MappedMapRefMut<'_, Cid, LoadedAsset, SchemaBox>
pub fn get_untyped_mut( &self, handle: UntypedHandle, ) -> MappedMapRefMut<'_, Cid, LoadedAsset, SchemaBox>
sourcepub fn try_get<T: HasSchema>(
&self,
handle: Handle<T>,
) -> Option<Result<MappedMapRef<'_, Cid, LoadedAsset, T, RandomState>, SchemaMismatchError>>
pub fn try_get<T: HasSchema>( &self, handle: Handle<T>, ) -> Option<Result<MappedMapRef<'_, Cid, LoadedAsset, T, RandomState>, SchemaMismatchError>>
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<MappedMapRef<'_, Cid, LoadedAsset, SchemaBox>>
pub fn try_get_untyped( &self, handle: UntypedHandle, ) -> Option<MappedMapRef<'_, Cid, LoadedAsset, SchemaBox>>
Borrow a loaded asset.
sourcepub fn try_get_untyped_mut(
&self,
handle: UntypedHandle,
) -> Option<MappedMapRefMut<'_, Cid, LoadedAsset, SchemaBox>>
pub fn try_get_untyped_mut( &self, handle: UntypedHandle, ) -> Option<MappedMapRefMut<'_, 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: HasSchema>(
&mut self,
handle: &Handle<T>,
) -> MappedMapRefMut<'_, Cid, LoadedAsset, T>
pub fn get_mut<T: HasSchema>( &mut self, handle: &Handle<T>, ) -> MappedMapRefMut<'_, Cid, LoadedAsset, T>
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 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§impl Deref for AssetServer
impl Deref for AssetServer
source§impl DerefMut for AssetServer
impl DerefMut for AssetServer
source§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
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§
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
)