diff --git a/bevy-jornet/examples/whac-a-square.rs b/bevy-jornet/examples/whac-a-square.rs index 4522c36..d7362c1 100644 --- a/bevy-jornet/examples/whac-a-square.rs +++ b/bevy-jornet/examples/whac-a-square.rs @@ -21,6 +21,7 @@ fn main() { option_env!("JORNET_LEADERBOARD_ID").unwrap_or("a920de64-3bdb-4f8e-87a8-e7bf20f00f81"), option_env!("JORNET_LEADERBOARD_KEY").unwrap_or("a797039b-a91d-43e6-8e1c-94f9ca0aa1d6"), )) + .add_plugin(debug::DebugPlugin) .add_startup_system(setup) .add_state(GameState::Menu) .add_plugin(menu::MenuPlugin) @@ -29,6 +30,105 @@ fn main() { .run(); } +mod debug { + use crate::{BACKGROUND, TEXT}; + use bevy::prelude::*; + use bevy_jornet::ErrorEvent; + + pub struct DebugPlugin; + + impl Plugin for DebugPlugin { + fn build(&self, app: &mut bevy::prelude::App) { + app.add_startup_system(setup) + .add_system_to_stage(CoreStage::PostUpdate, react_to_errors) + .add_system(despawn_after); + } + } + + #[derive(Component)] + struct DebugContainer; + + /// Despawns recursively host entity when `Time.seconds_since_startup()` exceeds than value + #[derive(Component)] + struct DespawnAfter(f64); + + fn setup(mut commands: Commands) { + commands + .spawn_bundle(NodeBundle { + style: Style { + align_self: AlignSelf::FlexEnd, + flex_direction: FlexDirection::ColumnReverse, + position_type: PositionType::Absolute, + position: UiRect { + top: Val::Px(5.0), + right: Val::Px(15.0), + ..default() + }, + max_size: Size { + width: Val::Px(400.), + height: Val::Undefined, + }, + align_items: AlignItems::FlexEnd, + ..default() + }, + color: Color::hex(BACKGROUND).unwrap().into(), + ..default() + }) + .insert(DebugContainer); + } + + fn react_to_errors( + mut commands: Commands, + asset_server: Res, + time: Res