use bevy::{
asset::{AssetPath, LoadedFolder},
prelude::*,
};
use super::{color::ColorPlugin, conversion::convert_bbcode, font::FontPlugin};
#[derive(Debug, Default)]
pub struct BbcodePlugin {
font_folder_path: Option<AssetPath<'static>>,
}
impl BbcodePlugin {
pub fn new() -> Self {
Self {
font_folder_path: None,
}
}
pub fn with_fonts<P: Into<AssetPath<'static>>>(mut self, folder_path: P) -> Self {
self.font_folder_path = Some(folder_path.into());
self
}
}
impl Plugin for BbcodePlugin {
fn build(&self, app: &mut App) {
app.add_plugins((FontPlugin, ColorPlugin))
.add_systems(Update, convert_bbcode);
let asset_server = app.world().resource::<AssetServer>();
if let Some(folder_path) = &self.font_folder_path {
let handle = asset_server.load_folder(folder_path.clone());
app.insert_resource(FontFolder { _handle: handle });
}
}
}
#[derive(Debug, Resource)]
struct FontFolder {
_handle: Handle<LoadedFolder>,
}