From: Ian Jackson Date: Sat, 3 Apr 2021 16:46:42 +0000 (+0100) Subject: clear log, including piece moves, on game reset X-Git-Tag: otter-0.5.0~257 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=09f7e8426b417d08029e9cc44ec794ecad380ce9;p=otter.git clear log, including piece moves, on game reset Signed-off-by: Ian Jackson --- diff --git a/daemon/cmdlistener.rs b/daemon/cmdlistener.rs index 2112e4a6..1b59a26b 100644 --- a/daemon/cmdlistener.rs +++ b/daemon/cmdlistener.rs @@ -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) }, diff --git a/src/bin/otter.rs b/src/bin/otter.rs index 5ebb3689..3a0ed2ef 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -531,7 +531,6 @@ fn setup_table(_ma: &MainOpts, spec: &TableSpec) -> Vec { 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)); diff --git a/src/movehist.rs b/src/movehist.rs index a8a5edeb..7397a712 100644 --- a/src/movehist.rs +++ b/src/movehist.rs @@ -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. diff --git a/src/updates.rs b/src/updates.rs index 41cb4d27..ac7abedd 100644 --- a/src/updates.rs +++ b/src/updates.rs @@ -57,6 +57,7 @@ pub enum PreparedUpdateEntry { Piece(PreparedUpdateEntry_Piece), Image(PreparedUpdateEntry_Image), MoveHistEnt(SecondarySlotMap), + MoveHistClear, SetTableSize(Pos), SetTableColour(Colour), SetLinks(Arc), @@ -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)) } diff --git a/templates/script.ts b/templates/script.ts index 7d40d712..3dd0cb54 100644 --- a/templates/script.ts +++ b/templates/script.ts @@ -1009,6 +1009,9 @@ type MoveHistPosx = { } messages.MoveHistEnt = movehist_record; +messages.MoveHistClear = 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)