From 2d1102e1c9c51a67d6551ad39b096a1fbfb5f07c Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Mon, 22 Aug 2022 10:27:13 +0200 Subject: [PATCH 1/2] add error handling when sending score --- bevy-jornet/examples/whac-a-square.rs | 189 +++++++++++++++++++++----- bevy-jornet/src/leaderboards.rs | 57 +++++++- bevy-jornet/src/lib.rs | 9 +- 3 files changed, 214 insertions(+), 41 deletions(-) diff --git a/bevy-jornet/examples/whac-a-square.rs b/bevy-jornet/examples/whac-a-square.rs index 4522c36..ebb6afd 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,107 @@ 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