Skip to content
Snippets Groups Projects
Verified Commit c74a4bbc authored by Louis's avatar Louis :fire:
Browse files

Add feature-gated debug rendering for colliders

parent 1b574c12
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,9 @@ name = "shoot-the-revival"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = []
debug-colliders = []
[dependencies]
log = "0.4.19"
......
use crate::entities::{BoxSize, CollisionGroup};
use bevy::prelude::{Added, BuildChildren, Commands, Entity, Query, Transform};
use bevy_prototype_lyon::prelude::{Fill, GeometryBuilder, RectangleOrigin, ShapeBundle, Stroke};
use bevy_prototype_lyon::shapes;
pub fn spawn_debug_colliders(
mut commands: Commands,
new_collider_query: Query<(Entity, &BoxSize, &CollisionGroup), Added<CollisionGroup>>,
) {
for (entity, box_size, group) in &new_collider_query {
commands.entity(entity).with_children(|commands| {
let shape = shapes::Rectangle {
origin: RectangleOrigin::Center,
extents: **box_size,
};
commands.spawn((
ShapeBundle {
transform: Transform::from_xyz(0.0, 0.0, 100.0),
path: GeometryBuilder::build_as(&shape),
..Default::default()
},
Fill::color(group.color().with_a(0.3)),
Stroke::new(group.color(), 1.5),
));
});
}
}
#[cfg(feature = "debug-colliders")]
mod colliders;
mod _plugin {
use bevy::app::App;
use bevy::prelude::Plugin;
pub struct DebugPlugin;
impl Plugin for DebugPlugin {
fn build(&self, app: &mut App) {
#[cfg(feature = "debug-colliders")]
app.add_system(super::colliders::spawn_debug_colliders);
}
}
}
pub use _plugin::DebugPlugin;
pub mod debug;
pub mod entities;
pub mod system;
pub mod utilities;
......@@ -17,6 +17,7 @@ fn main() {
}))
.add_plugin(shoot_the_revival::system::SystemPlugin)
.add_plugin(shoot_the_revival::entities::EntityPlugin)
.add_plugin(shoot_the_revival::debug::DebugPlugin)
.add_plugin(bevy_prototype_lyon::plugin::ShapePlugin)
.run();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment