chiark / gitweb /
clear log, including piece moves, on game reset
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 3 Apr 2021 16:46:42 +0000 (17:46 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 4 Apr 2021 02:45:09 +0000 (03:45 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/cmdlistener.rs
src/bin/otter.rs
src/movehist.rs
src/updates.rs
templates/script.ts

index 2112e4a6d9bb92ddc8dfd41b9fbd5f5d0e6f211d..1b59a26b837863b76ab1411a2ee62062ee2a85e7 100644 (file)
@@ -748,6 +748,9 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
 
     MGI::ClearLog => {
       let (ig, _) = cs.check_acl(&ag, ig, PCH::Instance, &[TP::Super])?;
+      for gpl in ig.gs.players.values_mut() {
+        gpl.movehist.clear();
+      }
       ig.gs.log.clear();
       for ipr in ig.iplayers.values_mut() {
         // todo: do this only if there are no hidden pieces?
@@ -759,12 +762,12 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
           tr.retain(|_k, v| v.latest >= latest);
         }
       }
-      // xxx clear the movehist
+      let raw = Some(vec![ PUE::MoveHistClear ]);
       (U{ pcs: vec![ ],
           log: vec![ LogEntry {
-            html: hformat!("{} cleared the log", who),
+            html: hformat!("{} cleared the log history", who),
           } ],
-          raw: None },
+          raw },
        Fine, None, ig)
     },
 
index 5ebb3689d3f39ab21fa60ef062d9a887350db96f..3a0ed2efb2a53fb1f46e0e858f10447bec078c43 100644 (file)
@@ -531,7 +531,6 @@ fn setup_table(_ma: &MainOpts, spec: &TableSpec) -> Vec<MGI> {
   let acl = acl.try_into()?;
 
   let mut insns = vec![];
-  insns.push(MGI::ClearLog);
   insns.push(MGI::SetACL { acl });
   insns.push(MGI::SetLinks(links.clone()));
   insns
@@ -700,6 +699,7 @@ mod reset_game {
       insns.push(MGI::DefinePieceAlias{ alias, target });
     }
 
+    insns.push(MGI::ClearLog);
     insns.push(MGI::SetTableSize(table_size));
     insns.push(MGI::SetTableColour(table_colour));
 
index a8a5edeb820338af737e358aded1d819556d35cd..7397a71252d4d088bd0b0c5cb2fde67a28f7f282 100644 (file)
@@ -83,6 +83,10 @@ impl Posx {
   }
 }
 
+impl PlHist {
+  pub fn clear(&mut self) { self.hist.clear() }
+}
+
 // We're track this on behalf of the client, based on the updates
 // we are sending.  That means we don't ahve to worry about
 // occultation, etc. etc.
index 41cb4d2709fbc204ec9a1681a792b52e072a9c1a..ac7abedd83bab99d01535104001f08ead3b7bd80 100644 (file)
@@ -57,6 +57,7 @@ pub enum PreparedUpdateEntry {
   Piece(PreparedUpdateEntry_Piece),
   Image(PreparedUpdateEntry_Image),
   MoveHistEnt(SecondarySlotMap<PlayerId, movehist::Ent>),
+  MoveHistClear,
   SetTableSize(Pos),
   SetTableColour(Colour),
   SetLinks(Arc<LinksTable>),
@@ -223,6 +224,7 @@ enum TransmitUpdateEntry<'u> {
   Piece(TransmitUpdateEntry_Piece<'u>),
   Image(TransmitUpdateEntry_Image<'u>),
   MoveHistEnt(&'u movehist::Ent),
+  MoveHistClear{},
   RecordedUnpredictable {
     piece: VisiblePieceId,
     cseq: ClientSequence,
@@ -414,6 +416,7 @@ impl PreparedUpdateEntry {
       Log(logent) => {
         logent.logent.html.json_len() * 28
       }
+      MoveHistClear => 50,
       AddPlayer {
         player:_,
         data: DataLoadPlayer { dasharray, nick, },
@@ -913,6 +916,9 @@ impl PreparedUpdate {
             _ => continue,
           }
         }
+        PUE::MoveHistClear => {
+          TUE::MoveHistClear{}
+        }
         PUE::Log(logent) => {
           TUE::Log((&tz, &logent))
         }
index 7d40d71212be9fc7b38fe03009f6b20760c7443d..3dd0cb5455f99a8c646f0635b3dcafe9b10d1ea0 100644 (file)
@@ -1009,6 +1009,9 @@ type MoveHistPosx = {
 }
 
 messages.MoveHistEnt = <MessageHandler>movehist_record;
+messages.MoveHistClear = <MessageHandler>function() {
+  movehist_revisible_custmax(0);
+}
 
 function movehist_record(ent: MoveHistEnt) {
   let old_pos = ent.posx[0].pos;
@@ -1054,11 +1057,15 @@ function movehist_record(ent: MoveHistEnt) {
   }
 }
 
-function movehist_revisible() {
+function movehist_revisible() { 
+  movehist_revisible_custmax(movehist_len_max);
+}
+
+function movehist_revisible_custmax(len_max: number) {
   let n = movehist_lens[movehist_len_i];
   let i = 0;
   let node = movehist_end;
-  while (i < movehist_len_max) {
+  while (i < len_max) {
     i++; // i now eg 1..10
     node = node.previousElementSibling! as SVGGraphicsElement;
     if (node == movehist_start)