paiagram/vehicles/
services.rs1use crate::colors::DisplayColor;
2use bevy::prelude::*;
3use egui::{Pos2, Shape, Stroke};
4use moonshine_core::prelude::*;
5
6#[derive(Reflect, Debug, Component, MapEntities)]
7#[reflect(Component, MapEntities)]
8#[require(Name)]
9pub struct VehicleService {
10 pub class: Option<Entity>,
11}
12
13#[derive(Debug, Clone, Copy)]
14pub enum StrokeStyle {
15 Filled {
16 color: DisplayColor,
17 width: f32,
18 },
19 Dotted {
20 color: DisplayColor,
21 radius: f32,
22 spacing: f32,
23 },
24 Dashed {
25 color: DisplayColor,
26 length: f32,
27 spacing: f32,
28 width: f32,
29 },
30}
31
32impl StrokeStyle {
33 pub fn to_shape(self, light: bool, points: &[Pos2]) -> Vec<Shape> {
34 match self {
35 Self::Filled { color, width } => {
36 vec![Shape::line(
37 points.to_vec(),
38 Stroke::new(width, color.get(light)),
39 )]
40 }
41 Self::Dashed {
42 color,
43 length,
44 spacing,
45 width,
46 } => Shape::dashed_line(
47 points,
48 Stroke::new(width, color.get(light)),
49 length,
50 spacing,
51 ),
52 Self::Dotted {
53 color,
54 radius,
55 spacing,
56 } => Shape::dotted_line(points, color.get(light), radius, spacing),
57 }
58 }
59}
60
61impl Default for StrokeStyle {
62 fn default() -> Self {
63 Self::Filled {
64 color: DisplayColor::default(),
65 width: 1.0,
66 }
67 }
68}
69
70#[derive(Debug, Component)]
71#[require(Name)]
72pub struct VehicleClass {
73 pub stroke: StrokeStyle,
74}
75
76impl Default for VehicleClass {
77 fn default() -> Self {
78 Self {
79 stroke: StrokeStyle::default(),
80 }
81 }
82}