chiark / gitweb /
movehist: Rework a bit and provide more to JS
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 2 Apr 2021 20:34:21 +0000 (21:34 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 2 Apr 2021 22:38:25 +0000 (23:38 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/main.rs
src/movehist.rs
src/prelude.rs
templates/loading.tera
templates/script.ts

index cdc9a83fc6e8420edc42e2ff7f3134a0bc4d92d4..e5b831aa8c8113cb8fe1e0618ba0bc20b8609111 100644 (file)
@@ -95,7 +95,9 @@ struct LoadingRenderContext<'r> {
   layout: PresentationLayout,
   ptoken: &'r RawTokenVal,
   debug_js_inject: Arc<String>,
-  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<PresentationLayout>, 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)
index aa436e3ec6836543b74c9969b5b5a567d06896d9..6d995fd78da3adac70c0b108f6a753bcd34cf883 100644 (file)
@@ -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
index 6b051ed32be3f08b468bcde0d067c906265ed8d8..784fba5c8f51c02f513e0848272fd680d3bab06e 100644 (file)
@@ -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::*;
 
index 36c2fab8419e25d0dbad7c71b64ff076b2e50a60..9a5a0844fe3acfbb69ed18cba48d0295a6bac1f2 100644 (file)
@@ -10,7 +10,9 @@
 <script src="/_/wasm.js" defer></script>
 <script id="global-info" data-layout="{{ layout }}"></script>
 <script>
-  movehistlens={{ movehistlens }};
+  movehist_lens   ={{ movehist_lens    }};
+  movehist_len_i  ={{ movehist_len_i   }};
+  movehist_len_max={{ movehist_len_max }};
 </script>
 <script src="/_/script.js" defer></script>
 </head>
index 2dc67a5b46d1bfa1fd37478f0bef3fa0d99aabbf..2a646ff5a0429dc56fb6860a9e51a556374110b7 100644 (file)
@@ -92,6 +92,11 @@ type PieceErrorHandler = (piece: PieceId, p: PieceInfo, m: PieceOpError)
   => boolean;
 interface DispatchTable<H> { [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;