use crate::render::NannouRenderPlugin;
use bevy::prelude::*;
use draw::Draw;
use text::font::SharedTextCx;
pub mod color;
pub mod draw;
pub mod render;
pub mod text;
pub struct NannouDrawPlugin;
impl Plugin for NannouDrawPlugin {
fn build(&self, app: &mut App) {
if !app.is_plugin_added::<bevy::text::TextPlugin>() {
app.add_plugins(bevy::text::TextPlugin);
}
text::font::init_shared_text_cx(app);
app.add_plugins(NannouRenderPlugin)
.add_systems(First, (spawn_draw, reset_draw).chain());
}
}
fn reset_draw(mut draw_q: Query<&mut Draw>) {
for mut draw in draw_q.iter_mut() {
draw.reset();
}
}
fn spawn_draw(
mut commands: Commands,
query: Query<Entity, (Without<Draw>, With<Window>)>,
text_cx: Res<SharedTextCx>,
) {
for entity in query.iter() {
commands
.entity(entity)
.insert(Draw::new(entity, text_cx.clone()));
}
}