diff --git a/src/debug.rs b/src/debug.rs index 37bebb1..14014d6 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -20,7 +20,6 @@ impl Plugin for DebugPlugin { )); app.register_type::() - .add_systems(First, clear_shapes) .add_systems(Update, debug_toggle) // TODO: Check if this could be scheduled just before render instead .add_systems(PostUpdate, draw_shapes); @@ -43,9 +42,8 @@ impl DebugMode { } } -/// TODO: Rename to something smarter #[derive(Clone, Copy, Debug, Reflect)] -pub struct Draw { +pub struct ColoredShape { pub shape: Shape, pub color: Srgba, } @@ -71,12 +69,12 @@ pub struct DebugCanvas; #[derive(Debug, Default, Resource, Reflect)] #[reflect(Resource)] pub struct DebugDraw { - pub draw_queue: Vec, + pub draw_queue: Vec, } impl DebugDraw { - pub fn shape(&mut self, draw: Draw) { - self.draw_queue.push(draw); + pub fn colored_shape(&mut self, colored_shape: ColoredShape) { + self.draw_queue.push(colored_shape); } } @@ -90,17 +88,15 @@ fn debug_toggle(input: Res>, mut debug_mode: ResMut>) { - for parent in canvas_query.iter() { - commands.entity(parent).despawn_descendants(); - } -} - fn draw_shapes( mut commands: Commands, canvas: Option>>, mut debug_draw: ResMut, ) { + // TODO: Re-use old shapes + if let Some(canvas) = canvas.as_ref() { + commands.entity(**canvas).despawn_descendants(); + } let canvas = match canvas { Some(canvas) => *canvas, None => commands @@ -108,9 +104,9 @@ fn draw_shapes( .id(), }; commands.entity(canvas).with_children(|builder| { - for draw in debug_draw.draw_queue.drain(..) { + for ColoredShape { shape, color } in debug_draw.draw_queue.drain(..) { // TODO - let path = match draw.shape { + let path = match shape { Shape::Line { from, to } => GeometryBuilder::build_as(&shapes::Line(from, to)), Shape::Polygon { center, @@ -126,7 +122,7 @@ fn draw_shapes( builder.spawn(( ShapeBundle { path, ..default() }, Fill::color(Srgba::NONE), - Stroke::color(draw.color), + Stroke::color(color), )); } }); diff --git a/src/game/systems/worker.rs b/src/game/systems/worker.rs index c134d05..c441f2f 100644 --- a/src/game/systems/worker.rs +++ b/src/game/systems/worker.rs @@ -1,7 +1,7 @@ use bevy::{color::palettes::css, prelude::*}; use crate::{ - debug::{DebugDraw, Draw, Shape}, + debug::{ColoredShape, DebugDraw, Shape}, game::{ item::{Inventory, ItemSource, Stockpile}, work::{Task, WorkType, Worker}, @@ -82,10 +82,10 @@ pub fn draw_job_targets( ) { for (worker_entity, worker) in worker_query.iter() { let worker_global = global_query.get(worker_entity).unwrap(); - let draws = match worker.0 { + let colored_shapes = match worker.0 { Some(task) => match task.work_type { WorkType::Gather => vec![ - Draw { + ColoredShape { shape: Shape::Polygon { center: worker_global.translation().xy(), sides: 3, @@ -93,7 +93,7 @@ pub fn draw_job_targets( }, color: css::GREEN, }, - Draw { + ColoredShape { shape: Shape::Line { from: worker_global.translation().xy(), to: global_query.get(task.target).unwrap().translation().xy(), @@ -102,7 +102,7 @@ pub fn draw_job_targets( }, ], WorkType::Store(_) => vec![ - Draw { + ColoredShape { shape: Shape::Polygon { center: worker_global.translation().xy(), sides: 3, @@ -110,7 +110,7 @@ pub fn draw_job_targets( }, color: css::YELLOW, }, - Draw { + ColoredShape { shape: Shape::Line { from: worker_global.translation().xy(), to: global_query.get(task.target).unwrap().translation().xy(), @@ -119,7 +119,7 @@ pub fn draw_job_targets( }, ], }, - None => vec![Draw { + None => vec![ColoredShape { shape: Shape::Polygon { center: worker_global.translation().xy(), sides: 3, @@ -128,8 +128,8 @@ pub fn draw_job_targets( color: css::RED, }], }; - for draw in draws { - debug_draw.shape(draw); + for colored_shape in colored_shapes { + debug_draw.colored_shape(colored_shape); } } }