11use bevy:: { platform:: collections:: HashSet , prelude:: * } ;
2+ use bevy_prototype_lyon:: prelude:: * ;
3+ use petgraph:: {
4+ dot:: { Config , Dot } ,
5+ stable_graph:: NodeIndex ,
6+ } ;
27
38use crate :: {
49 collision:: { point_segment_collision, segment_collision, PointCollision , SegmentCollision } ,
10+ layer,
511 lines:: { possible_lines, Axis } ,
612 sim:: SimulationState ,
7- spawn_road_segment, Collider , ColliderLayer , DrawingInteraction , DrawingMouseMovement ,
8- MousePos , MouseSnappedPos , PointGraphNode , RoadGraph , RoadSegment , SegmentGraphNodes ,
9- SelectedTool , Tool , BOTTOM_BAR_HEIGHT ,
10- } ;
11-
12- use petgraph:: {
13- dot:: { Config , Dot } ,
14- stable_graph:: NodeIndex ,
13+ spawn_road_segment, theme, Collider , ColliderLayer , DrawingInteraction , DrawingMouseMovement ,
14+ GameState , MousePos , MouseSnappedPos , PointGraphNode , RoadGraph , RoadSegment ,
15+ SegmentGraphNodes , SelectedTool , Tool , BOTTOM_BAR_HEIGHT ,
1516} ;
1617
1718pub struct RoadDrawingPlugin ;
@@ -28,7 +29,9 @@ impl Plugin for RoadDrawingPlugin {
2829 ) ;
2930 app. add_systems (
3031 Update ,
31- ( drawing_mouse_click_system) . in_set ( DrawingInteraction ) ,
32+ ( drawing_mouse_click_system, draw_drawing_system)
33+ . chain ( )
34+ . in_set ( DrawingInteraction ) ,
3235 ) ;
3336 }
3437}
@@ -62,6 +65,8 @@ impl Default for RoadDrawingState {
6265 }
6366 }
6467}
68+ #[ derive( Component ) ]
69+ struct DrawingLine ;
6570
6671#[ derive( Clone , Debug ) ]
6772struct AddSegment {
@@ -622,3 +627,36 @@ fn drawing_mouse_movement_system(
622627 road_state. valid = false ;
623628 }
624629}
630+
631+ fn draw_drawing_system (
632+ mut commands : Commands ,
633+ road_drawing : Res < RoadDrawingState > ,
634+ lines : Query < Entity , With < DrawingLine > > ,
635+ ) {
636+ if !road_drawing. is_changed ( ) {
637+ return ;
638+ }
639+
640+ for entity in lines. iter ( ) {
641+ commands. entity ( entity) . despawn ( ) ;
642+ }
643+
644+ if road_drawing. drawing {
645+ let color = if road_drawing. valid {
646+ theme:: DRAWING_ROAD [ road_drawing. layer as usize - 1 ]
647+ } else {
648+ bevy:: color:: palettes:: css:: RED
649+ } ;
650+
651+ for ( a, b) in road_drawing. segments . iter ( ) {
652+ commands. spawn ( (
653+ ShapeBuilder :: with ( & shapes:: Line ( * a, * b) )
654+ . stroke ( ( color, 2.0 ) )
655+ . build ( ) ,
656+ Transform :: from_xyz ( 0.0 , 0.0 , layer:: ROAD_OVERLAY ) ,
657+ DrawingLine ,
658+ StateScoped ( GameState :: Playing ) ,
659+ ) ) ;
660+ }
661+ }
662+ }
0 commit comments