From 372b3a9081eb4aefc2175d637f7a1190a0016390 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 2 Apr 2021 22:41:52 +0100 Subject: [PATCH] movehist: Provide move len in update Signed-off-by: Ian Jackson --- src/movehist.rs | 13 ++++++++----- templates/script.ts | 1 + 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/movehist.rs b/src/movehist.rs index f8f077e1..75e2c7cd 100644 --- a/src/movehist.rs +++ b/src/movehist.rs @@ -38,9 +38,9 @@ pub struct MoveHistEnt { pub diff: MoveHistDiffToShow, } -#[derive(Debug,Copy,Clone,Serialize,Deserialize,Eq,PartialEq)] +#[derive(Debug,Copy,Clone,Serialize,Deserialize)] pub enum MoveHistDiffToShow { - Moved, + Moved { d: f64 }, } #[derive(Debug,Clone,Serialize,Deserialize)] @@ -72,9 +72,12 @@ impl MoveHistPosx { -> Option { use MoveHistDiffToShow as D; - match (|| Ok::<_,CoordinateOverflow> ( - (self.pos - other.pos)?.len2()? > MOVEHIST_MIN_DIST*MOVEHIST_MIN_DIST - ))() { Ok(false) => {}, _ => return Some(D::Moved), } + match (|| Ok::<_,CoordinateOverflow> ({ + (self.pos - other.pos)?.len()? + }))() { + Ok(d) if d >= MOVEHIST_MIN_DIST as f64 => return Some(D::Moved{ d }), + _ => {}, + } None } diff --git a/templates/script.ts b/templates/script.ts index 7694abf8..aa52aab1 100644 --- a/templates/script.ts +++ b/templates/script.ts @@ -984,6 +984,7 @@ messages.SetLinks = function type MoveHistEnt = { held: PlayerId, posx: [MoveHistPosx, MoveHistPosx], + diff: { 'Moved': { d: number } }, } type MoveHistPosx = { pos: Pos, -- 2.30.2