Struct bones_framework::asset::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)where
F: FnMut(&mut AssetServer, UntypedHandle),
pub fn handle_asset_changes<F>(&mut self, handle_change: F)where F: FnMut(&mut AssetServer, UntypedHandle),
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§
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
.§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
Auto Trait Implementations§
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
§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
.