chiark / gitweb /
movehist: Provide move len in update
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 2 Apr 2021 21:41:52 +0000 (22:41 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 2 Apr 2021 23:04:52 +0000 (00:04 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/movehist.rs
templates/script.ts

index f8f077e13bb8585eff16a5ccf4aa4a78dcce2a0a..75e2c7cd1ff23180cdd48a8bc08f1ba735914ecc 100644 (file)
@@ -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<MoveHistDiffToShow> {
     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
   }
index 7694abf810577f3d184e37a5f4eaa67a8d8d5073..aa52aab1b24e4925449eee3817f6abfc962799de 100644 (file)
@@ -984,6 +984,7 @@ messages.SetLinks = <MessageHandler>function
 type MoveHistEnt = {
   held: PlayerId,
   posx: [MoveHistPosx, MoveHistPosx],
+  diff: { 'Moved': { d: number } },
 }
 type MoveHistPosx = {
   pos: Pos,