2022-02-20 10:10:18 +00:00
|
|
|
use crate::{resources::Time, uid::Uid};
|
2020-07-06 14:23:08 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2021-01-07 20:25:12 +00:00
|
|
|
use specs::Component;
|
2019-09-25 20:22:39 +00:00
|
|
|
use vek::*;
|
|
|
|
|
2022-08-08 04:38:20 +00:00
|
|
|
#[derive(Copy, Clone, Debug)]
|
2019-09-25 20:22:39 +00:00
|
|
|
pub struct Waypoint {
|
|
|
|
pos: Vec3<f32>,
|
2020-05-24 04:10:08 +00:00
|
|
|
last_save: Time,
|
2019-09-25 20:22:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Waypoint {
|
2020-11-16 01:40:12 +00:00
|
|
|
// TODO: add actual fix and remove this method
|
|
|
|
pub fn temp_new(pos: Vec3<f32>, last_save: Time) -> Self {
|
|
|
|
Self {
|
|
|
|
pos: pos + Vec3::from(0.25f32).map(|e| e * rand::random::<f32>() - 0.25 / 2.0),
|
|
|
|
last_save,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-24 04:10:08 +00:00
|
|
|
pub fn new(pos: Vec3<f32>, last_save: Time) -> Self { Self { pos, last_save } }
|
2019-09-25 20:22:39 +00:00
|
|
|
|
2020-02-01 20:39:39 +00:00
|
|
|
pub fn get_pos(&self) -> Vec3<f32> { self.pos }
|
2020-05-24 04:10:08 +00:00
|
|
|
|
|
|
|
/// Time in seconds since this waypoint was saved
|
|
|
|
pub fn elapsed(&self, time: Time) -> f64 { time.0 - self.last_save.0 }
|
2019-09-25 20:22:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Component for Waypoint {
|
2022-08-08 04:38:20 +00:00
|
|
|
type Storage = specs::VecStorage<Self>;
|
2019-09-25 20:22:39 +00:00
|
|
|
}
|
2020-01-25 02:15:15 +00:00
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
|
|
|
pub struct WaypointArea(f32);
|
|
|
|
|
2020-01-25 12:27:36 +00:00
|
|
|
impl WaypointArea {
|
2020-02-01 20:39:39 +00:00
|
|
|
pub fn radius(&self) -> f32 { self.0 }
|
2020-01-25 12:27:36 +00:00
|
|
|
}
|
|
|
|
|
2020-01-25 02:15:15 +00:00
|
|
|
impl Component for WaypointArea {
|
2022-08-08 04:38:20 +00:00
|
|
|
type Storage = specs::VecStorage<Self>;
|
2020-01-25 02:15:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for WaypointArea {
|
2020-02-01 20:39:39 +00:00
|
|
|
fn default() -> Self { Self(5.0) }
|
2020-01-25 02:15:15 +00:00
|
|
|
}
|
2022-02-20 10:10:18 +00:00
|
|
|
|
|
|
|
/// Marker on the map, used for sharing waypoint with group and
|
|
|
|
/// persisting it server side.
|
2022-08-08 04:38:20 +00:00
|
|
|
#[derive(Copy, Clone, Debug)]
|
2022-02-20 10:10:18 +00:00
|
|
|
pub struct MapMarker(pub Vec2<i32>);
|
|
|
|
|
|
|
|
impl Component for MapMarker {
|
2022-08-08 04:38:20 +00:00
|
|
|
type Storage = specs::VecStorage<Self>;
|
2022-02-20 10:10:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
|
|
|
pub enum MapMarkerChange {
|
|
|
|
Update(Vec2<i32>),
|
|
|
|
Remove,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
|
|
pub enum MapMarkerUpdate {
|
|
|
|
Owned(MapMarkerChange),
|
|
|
|
GroupMember(Uid, MapMarkerChange),
|
|
|
|
ClearGroup,
|
|
|
|
}
|