veloren_common/comp/
gizmos.rs1use enum_map::EnumMap;
4use serde::{Deserialize, Serialize};
5use specs::{Component, DenseVecStorage};
6use vek::{Rgba, Sphere, Vec3};
7
8use crate::{resources::Time, uid::Uid};
9
10#[derive(Serialize, Deserialize, Debug, Clone)]
11pub enum Shape {
12 Sphere(Sphere<f32, f32>),
13 LineStrip(Vec<Vec3<f32>>),
14}
15
16#[derive(Serialize, Deserialize, Debug, Clone)]
17pub struct Gizmos {
18 pub shape: Shape,
19 pub color: Rgba<u8>,
20 pub end_time: Option<Time>,
22}
23
24impl Gizmos {
25 pub fn sphere(pos: Vec3<f32>, radius: f32, color: impl Into<Rgba<u8>>) -> Self {
26 Self {
27 shape: Shape::Sphere(Sphere {
28 center: pos,
29 radius,
30 }),
31 color: color.into(),
32 end_time: None,
33 }
34 }
35
36 pub fn line(a: Vec3<f32>, b: Vec3<f32>, color: impl Into<Rgba<u8>>) -> Self {
37 Self {
38 shape: Shape::LineStrip(vec![a, b]),
39 color: color.into(),
40 end_time: None,
41 }
42 }
43
44 pub fn line_strip(points: Vec<Vec3<f32>>, color: impl Into<Rgba<u8>>) -> Self {
45 Self {
46 shape: Shape::LineStrip(points),
47 color: color.into(),
48 end_time: None,
49 }
50 }
51
52 pub fn with_end_time(mut self, time: Time) -> Self {
56 self.end_time = Some(time);
57 self
58 }
59}
60
61#[derive(
62 Serialize,
63 Deserialize,
64 strum::EnumString,
65 strum::Display,
66 strum::EnumIter,
67 PartialEq,
68 enum_map::Enum,
69 Clone,
70 Copy,
71)]
72pub enum GizmoSubscription {
73 PathFinding,
74 Rtsim,
75}
76
77#[derive(Default, Clone)]
78pub enum GizmoContext {
79 #[default]
80 Disabled,
81 Enabled,
82 EnabledWithTarget(Uid),
84}
85
86pub struct GizmoSubscriber {
88 pub gizmos: EnumMap<GizmoSubscription, GizmoContext>,
89 pub range: f32,
91}
92
93#[derive(Default)]
95pub struct RtsimGizmos {
96 pub tracked: slotmap::SecondaryMap<crate::rtsim::NpcId, Vec<Gizmos>>,
97}
98
99impl Default for GizmoSubscriber {
100 fn default() -> Self {
101 GizmoSubscriber {
102 gizmos: EnumMap::default(),
103 range: 32.0,
104 }
105 }
106}
107
108impl Component for GizmoSubscriber {
109 type Storage = DenseVecStorage<GizmoSubscriber>;
110}