From 683fb12534da519834b650e7523e87d206fba375 Mon Sep 17 00:00:00 2001 From: andriyDev Date: Sun, 30 Jun 2024 00:06:31 -0700 Subject: [PATCH] Move the debugging code in the example to be part of `bevy_landmass::debug`. Previously, all this debug drawing code was bespoke - every user needed to write their own version. Now it's part of bevy_landmass so every user can just toss it in immediately! Note we still provide `draw_archipelago_debug` as a low-level API in case users don't like my debug visualizations. --- crates/bevy_landmass/Cargo.toml | 1 + crates/bevy_landmass/example/debug.rs | 73 ----------------- crates/bevy_landmass/example/main.rs | 23 ++++-- crates/bevy_landmass/src/debug.rs | 112 +++++++++++++++++++++++++- 4 files changed, 130 insertions(+), 79 deletions(-) delete mode 100644 crates/bevy_landmass/example/debug.rs diff --git a/crates/bevy_landmass/Cargo.toml b/crates/bevy_landmass/Cargo.toml index b0d0c4a..d6db682 100644 --- a/crates/bevy_landmass/Cargo.toml +++ b/crates/bevy_landmass/Cargo.toml @@ -19,6 +19,7 @@ type_complexity = "allow" [dependencies] bevy = { version = "0.13.0", default-features = false, features = [ "bevy_asset", + "bevy_gizmos", ] } landmass = { path = "../landmass", version = "0.4.0" } diff --git a/crates/bevy_landmass/example/debug.rs b/crates/bevy_landmass/example/debug.rs deleted file mode 100644 index f306813..0000000 --- a/crates/bevy_landmass/example/debug.rs +++ /dev/null @@ -1,73 +0,0 @@ -use bevy::{input::common_conditions::input_toggle_active, prelude::*}; -use bevy_landmass::{debug::*, LandmassSystemSet}; - -pub struct DebugPlugin; - -impl Plugin for DebugPlugin { - fn build(&self, app: &mut bevy::prelude::App) { - app - .add_systems( - Update, - draw_archipelagos - .in_set(LandmassSystemSet::Output) - .run_if(input_toggle_active(false, KeyCode::F12)), - ) - .insert_gizmo_group( - DefaultGizmoConfigGroup, - GizmoConfig { depth_bias: -1.0, ..Default::default() }, - ); - } -} - -struct LyonDrawer<'w, 's, 'a>(&'a mut Gizmos<'w, 's>); - -impl<'w, 's, 'a> DebugDrawer for LyonDrawer<'w, 's, 'a> { - fn add_point(&mut self, point_type: PointType, point: Vec3) { - self.0.sphere( - point, - Quat::IDENTITY, - 0.2, - match point_type { - PointType::AgentPosition(_) => Color::rgba(0.0, 1.0, 0.0, 0.6), - PointType::TargetPosition(_) => Color::rgba(1.0, 1.0, 0.0, 0.6), - PointType::Waypoint(_) => Color::rgba(0.6, 0.6, 0.6, 0.6), - }, - ); - } - - fn add_line(&mut self, line_type: LineType, line: [Vec3; 2]) { - self.0.line( - line[0], - line[1], - match line_type { - LineType::BoundaryEdge => Color::rgba(0.0, 0.0, 1.0, 0.6), - LineType::ConnectivityEdge => Color::rgba(0.5, 0.5, 1.0, 0.6), - LineType::AgentCorridor(_) => Color::rgba(0.6, 0.0, 0.6, 0.6), - LineType::Target(_) => Color::rgba(1.0, 1.0, 0.0, 0.6), - LineType::Waypoint(_) => Color::rgba(0.6, 0.6, 0.6, 0.6), - }, - ); - } - - fn add_triangle( - &mut self, - _triangle_type: TriangleType, - _triangle: [Vec3; 3], - ) { - // Bevy doesn't have a way to draw triangles :'( - } -} - -fn draw_archipelagos( - time: Res