Skip to content

Commit f145e66

Browse files
committed
Tidying
1 parent c22fefd commit f145e66

2 files changed

Lines changed: 49 additions & 42 deletions

File tree

src/main.rs

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ fn main() {
139139
.after(DrawingMouseMovement)
140140
.run_if(in_state(GameState::Playing)),
141141
);
142-
app.add_systems(Update, draw_mouse_system.in_set(DrawingInteraction));
142+
app.add_systems(Update, draw_cursor_system.in_set(DrawingInteraction));
143143

144144
// whenever
145145
app.add_systems(
@@ -241,8 +241,6 @@ struct MainCamera;
241241
#[derive(Component)]
242242
struct Cursor;
243243
#[derive(Component)]
244-
struct DrawingLine;
245-
#[derive(Component)]
246244
struct GridPoint;
247245
#[derive(Component)]
248246
struct PixieCountText;
@@ -656,12 +654,11 @@ fn snap_to_grid(position: Vec2, grid_size: f32) -> Vec2 {
656654
(position / grid_size).round() * grid_size
657655
}
658656

659-
fn draw_mouse_system(
657+
fn draw_cursor_system(
660658
mut commands: Commands,
661659
line_drawing: Res<RoadDrawingState>,
662660
mouse_snapped: Res<MouseSnappedPos>,
663661
q_cursor: Query<Entity, With<Cursor>>,
664-
q_drawing: Query<Entity, With<DrawingLine>>,
665662
) {
666663
if mouse_snapped.is_changed() || line_drawing.is_changed() {
667664
for entity in q_cursor.iter() {
@@ -685,34 +682,6 @@ fn draw_mouse_system(
685682
StateScoped(GameState::Playing),
686683
));
687684
}
688-
689-
// TODO move this bit to a separate system in road_drawing.rs
690-
if !line_drawing.is_changed() {
691-
return;
692-
}
693-
694-
for entity in q_drawing.iter() {
695-
commands.entity(entity).despawn();
696-
}
697-
698-
if line_drawing.drawing {
699-
let color = if line_drawing.valid {
700-
theme::DRAWING_ROAD[line_drawing.layer as usize - 1]
701-
} else {
702-
bevy::color::palettes::css::RED
703-
};
704-
705-
for (a, b) in line_drawing.segments.iter() {
706-
commands.spawn((
707-
ShapeBuilder::with(&shapes::Line(*a, *b))
708-
.stroke((color, 2.0))
709-
.build(),
710-
Transform::from_xyz(0.0, 0.0, layer::ROAD_OVERLAY),
711-
DrawingLine,
712-
StateScoped(GameState::Playing),
713-
));
714-
}
715-
}
716685
}
717686

718687
fn drawing_mode_change_system(

src/road_drawing.rs

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
use bevy::{platform::collections::HashSet, prelude::*};
2+
use bevy_prototype_lyon::prelude::*;
3+
use petgraph::{
4+
dot::{Config, Dot},
5+
stable_graph::NodeIndex,
6+
};
27

38
use 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

1718
pub 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)]
6772
struct 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

Comments
 (0)