chiark / gitweb /
move lower into ts
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 1 Oct 2020 00:00:05 +0000 (01:00 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 1 Oct 2020 00:00:05 +0000 (01:00 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/gamestate.rs
templates/script.ts

index 1a0566ba041baf192c86b51bd989bd175a4f19e7..1027ef5e5826da051ba953dfcb80ecfb24a21a43 100644 (file)
@@ -279,13 +279,6 @@ impl<T> PieceExt for T where T: Piece + ?Sized {
         desc: Html::lit("flip"),
       })
     }
-    out.push(UoDescription {
-      kind: UoKind::GlobalExtra,
-      wrc: WRC::Predictable,
-      def_key: 'l'.into(),
-      opname: "lower".to_string(),
-      desc: Html::lit("lower (send to bottom)"),
-    });
     self.add_ui_operations(&mut out)?;
     out
   }
index 35b9b44bc560ae7d906ff7c02203368b6144de8c..0e406355069ac5a3ce52534cfc88eec19a35dffc 100644 (file)
@@ -46,7 +46,7 @@ type PlayerId = string;
 type Pos = [number, number];
 type ClientSeq = number;
 type Generation = number;
-type UoKind = "Global"| "Piece" | "ClientExtra" | "GlobalExtra";
+type UoKind = 'Client' | "Global"| "Piece" | "ClientExtra" | "GlobalExtra";
 type WhatResponseToClientOp = "Predictable" | "Unpredictable" | "UpdateSvg";
 
 type UoDescription = {
@@ -64,6 +64,7 @@ type UoRecord = UoDescription & {
 type PieceInfo = {
   held : PlayerId | null,
   cseq : number | null,
+  cseq_updatesvg : number | null,
   z : number,
   zg : Generation,
   uos : UoDescription[],
@@ -212,9 +213,11 @@ function piece_element(base: string, piece: PieceId): SVGGraphicsElement | null
 
 function recompute_keybindings() {
   uo_map = Object.create(null);
+  let all_targets = [];
   for (let piece of Object.keys(pieces)) {
     let p = pieces[piece];
     if (p.held != us) continue;
+    all_targets.push(piece);
     for (var uo of p.uos) {
       let currently = uo_map[uo.def_key];
       if (currently === null) continue;
@@ -234,14 +237,28 @@ function recompute_keybindings() {
       currently.targets!.push(piece);
     }
   }
-  uo_map['W'] = {
-    kind: 'ClientExtra',
+  let add_uo = function(targets: PieceId[] | null, uo: UoDescription) {
+    uo_map[uo.def_key] = {
+      targets: targets,
+      ...uo
+    };
+  };
+  if (all_targets.length) {
+    add_uo(all_targets, {
+      def_key: 'l',
+      kind: 'Client',
+      wrc: 'Predictable',
+      opname: "lower",
+      desc: "lower (send to bottom)",
+    });
+  }
+  add_uo(null, {
     def_key: 'W',
+    kind: 'ClientExtra',
     opname: 'wrest',
     desc: 'Enter wresting mode',
-    targets: null,
     wrc: 'Predictable',
-  }
+  });
   var uo_keys = Object.keys(uo_map);
   uo_keys.sort(function (ak,bk) {
     let a = uo_map[ak]!;
@@ -274,8 +291,13 @@ function some_keydown(e: KeyboardEvent) {
 
   console.log('KEY UO', e, uo);
   if (uo.targets === null) {
+    // xxx 'wrest'
     return;
   }
+  // xxx 'lower'
+  if (!(uo.kind == 'Global' || uo.kind == 'GlobalExtra'))
+    throw 'bad kind '+uo.kind;
+
   if (uo.wrc! == 'UpdateSvg' || uo.wrc! == 'Predictable') {
     
   }