From f843a270957cd1ffd005bebb4c00555820452395 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 2 Apr 2021 21:34:21 +0100 Subject: [PATCH] movehist: Rework a bit and provide more to JS Signed-off-by: Ian Jackson --- daemon/main.rs | 8 ++++++-- src/movehist.rs | 20 +++++++++++++++----- src/prelude.rs | 1 + templates/loading.tera | 4 +++- templates/script.ts | 5 +++++ 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/daemon/main.rs b/daemon/main.rs index cdc9a83f..e5b831aa 100644 --- a/daemon/main.rs +++ b/daemon/main.rs @@ -95,7 +95,9 @@ struct LoadingRenderContext<'r> { layout: PresentationLayout, ptoken: &'r RawTokenVal, debug_js_inject: Arc, - movehistlens: JsonString<&'r [usize]>, + movehist_lens: JsonString<&'r [usize]>, + movehist_len_i: usize, + movehist_len_max: usize, } #[get("/")] #[throws(OER)] @@ -122,7 +124,9 @@ fn loading(layout: Option, ia: PlayerQueryString) game: g.name.to_string(), ptoken: &ia.raw_token, debug_js_inject: config().debug_js_inject.clone(), - movehistlens: JsonString(MOVEHIST_LENS), + movehist_lens: JsonString(MOVEHIST_LENS), + movehist_len_i: MOVEHIST_LEN_DEF_I, + movehist_len_max: MOVEHIST_LEN_MAX, layout, }; Template::render("loading", &c) diff --git a/src/movehist.rs b/src/movehist.rs index aa436e3e..6d995fd7 100644 --- a/src/movehist.rs +++ b/src/movehist.rs @@ -4,14 +4,24 @@ use super::*; // we are otter::updates::movehist -pub const MOVEHIST_LENS: &[usize] = &[ 1, 3, 10, 0]; +pub const MOVEHIST_LENS: &[usize] = &[ 0, 1, 3, 10 ]; pub const MOVEHIST_LEN_MAX: usize = 10; +pub const MOVEHIST_LEN_DEF_I: usize = 1; #[test] -fn movehist_len_max() { assert_eq!( - MOVEHIST_LENS.iter().max(), - Some(&MOVEHIST_LEN_MAX), -) } +fn movehist_lens() { + assert_eq!( + MOVEHIST_LENS.iter().max(), + Some(&MOVEHIST_LEN_MAX), + ); + assert!( MOVEHIST_LENS.get(MOVEHIST_LEN_DEF_I).is_some() ); + assert_eq!( MOVEHIST_LENS.iter().cloned().fold(None, |b, i| { + let i = Some(i); + assert!(i > b); + i + }), + Some(MOVEHIST_LEN_MAX) ); +} #[derive(Debug,Copy,Clone,Serialize,Deserialize)] pub struct MoveHistPosx { // usual variable: posx diff --git a/src/prelude.rs b/src/prelude.rs index 6b051ed3..784fba5c 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -147,6 +147,7 @@ pub use crate::tz::*; pub use crate::updates::*; pub use crate::updates::movehist::{self, GMoveHeld, GMoveHist, MoveHistEnt}; pub use crate::updates::movehist::{MOVEHIST_LENS, MOVEHIST_LEN_MAX}; +pub use crate::updates::movehist::{MOVEHIST_LEN_DEF_I}; pub use crate::utils::*; pub use crate::ui::*; diff --git a/templates/loading.tera b/templates/loading.tera index 36c2fab8..9a5a0844 100644 --- a/templates/loading.tera +++ b/templates/loading.tera @@ -10,7 +10,9 @@ diff --git a/templates/script.ts b/templates/script.ts index 2dc67a5b..2a646ff5 100644 --- a/templates/script.ts +++ b/templates/script.ts @@ -92,6 +92,11 @@ type PieceErrorHandler = (piece: PieceId, p: PieceInfo, m: PieceOpError) => boolean; interface DispatchTable { [key: string]: H }; +// from header +var movehist_len_i: number; +var movehist_len_max: number; +var movehist_lens: number[]; + // todo turn all var into let // todo any exceptions should have otter in them or something var globalinfo_elem : HTMLElement; -- 2.30.2