2020-05-16 02:46:09 +00:00
|
|
|
use crate::Font;
|
|
|
|
use anyhow::Result;
|
2020-10-18 20:48:15 +00:00
|
|
|
use bevy_asset::{AssetLoader, LoadContext, LoadedAsset};
|
2020-10-20 00:29:31 +00:00
|
|
|
use bevy_utils::BoxedFuture;
|
2020-05-16 02:46:09 +00:00
|
|
|
|
2020-05-22 00:21:33 +00:00
|
|
|
#[derive(Default)]
|
2020-05-16 02:46:09 +00:00
|
|
|
pub struct FontLoader;
|
|
|
|
|
2020-10-18 20:48:15 +00:00
|
|
|
impl AssetLoader for FontLoader {
|
2020-10-20 00:29:31 +00:00
|
|
|
fn load<'a>(
|
|
|
|
&'a self,
|
|
|
|
bytes: &'a [u8],
|
|
|
|
load_context: &'a mut LoadContext,
|
|
|
|
) -> BoxedFuture<'a, Result<()>> {
|
|
|
|
Box::pin(async move {
|
|
|
|
let font = Font::try_from_bytes(bytes.into())?;
|
|
|
|
load_context.set_default_asset(LoadedAsset::new(font));
|
|
|
|
Ok(())
|
|
|
|
})
|
2020-05-16 02:46:09 +00:00
|
|
|
}
|
2020-07-28 21:24:03 +00:00
|
|
|
|
2020-05-16 02:46:09 +00:00
|
|
|
fn extensions(&self) -> &[&str] {
|
2021-01-03 20:10:23 +00:00
|
|
|
&["ttf", "otf"]
|
2020-05-16 02:46:09 +00:00
|
|
|
}
|
|
|
|
}
|