Merge branch '561-info-popup-for-saved-waypoints-only-appear-for-the-second-time-you-visit-one' into 'master'

Resolve "Info popup for saved waypoints only appear for the second time you visit one"

Closes #561

See merge request veloren/veloren!1014
This commit is contained in:
Monty Marz 2020-05-29 11:39:12 +00:00
commit 6d1ec73b47
3 changed files with 18 additions and 9 deletions

View File

@ -1,16 +1,21 @@
use crate::state::Time;
use specs::{Component, FlaggedStorage};
use specs_idvs::IDVStorage;
use vek::*;
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
pub struct Waypoint {
pos: Vec3<f32>,
last_save: Time,
}
impl Waypoint {
pub fn new(pos: Vec3<f32>) -> Self { Self { pos } }
pub fn new(pos: Vec3<f32>, last_save: Time) -> Self { Self { pos, last_save } }
pub fn get_pos(&self) -> Vec3<f32> { self.pos }
/// Time in seconds since this waypoint was saved
pub fn elapsed(&self, time: Time) -> f64 { time.0 - self.last_save.0 }
}
impl Component for Waypoint {

View File

@ -840,11 +840,12 @@ fn handle_waypoint(
) {
match server.state.read_component_cloned::<comp::Pos>(target) {
Some(pos) => {
let time = server.state.ecs().read_resource();
let _ = server
.state
.ecs()
.write_storage::<comp::Waypoint>()
.insert(target, comp::Waypoint::new(pos.0));
.insert(target, comp::Waypoint::new(pos.0, *time));
server.notify_client(client, ServerMsg::private(String::from("Waypoint saved!")));
server.notify_client(client, ServerMsg::Notification(Notification::WaypointSaved));
},

View File

@ -3,10 +3,12 @@ use crate::client::Client;
use common::{
comp::{Player, Pos, Waypoint, WaypointArea},
msg::{Notification, ServerMsg},
state::Time,
};
use specs::{Entities, Join, ReadStorage, System, Write, WriteStorage};
use specs::{Entities, Join, Read, ReadStorage, System, Write, WriteStorage};
const NOTIFY_DISTANCE: f32 = 10.0;
/// Cooldown time (in seconds) for "Waypoint Saved" notifications
const NOTIFY_TIME: f64 = 10.0;
/// This system updates player waypoints
/// TODO: Make this faster by only considering local waypoints
@ -19,12 +21,13 @@ impl<'a> System<'a> for Sys {
ReadStorage<'a, WaypointArea>,
WriteStorage<'a, Waypoint>,
WriteStorage<'a, Client>,
Read<'a, Time>,
Write<'a, SysTimer<Self>>,
);
fn run(
&mut self,
(entities, positions, players, waypoint_areas, mut waypoints, mut clients, mut timer): Self::SystemData,
(entities, positions, players, waypoint_areas, mut waypoints, mut clients, time, mut timer): Self::SystemData,
) {
timer.start();
@ -33,14 +36,14 @@ impl<'a> System<'a> for Sys {
{
for (waypoint_pos, waypoint_area) in (&positions, &waypoint_areas).join() {
if player_pos.0.distance_squared(waypoint_pos.0) < waypoint_area.radius().powi(2) {
if let Some(wp) = waypoints.get(entity) {
if player_pos.0.distance_squared(wp.get_pos()) > NOTIFY_DISTANCE.powi(2) {
if let Ok(wp_old) = waypoints.insert(entity, Waypoint::new(player_pos.0, *time))
{
if wp_old.map_or(true, |w| w.elapsed(*time) > NOTIFY_TIME) {
client
.postbox
.send_message(ServerMsg::Notification(Notification::WaypointSaved));
}
}
let _ = waypoints.insert(entity, Waypoint::new(player_pos.0));
}
}
}