chiark / gitweb /
wrest and unwrest
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 3 Oct 2020 00:44:02 +0000 (01:44 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 3 Oct 2020 00:44:02 +0000 (01:44 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
templates/script.ts

index e1986b154d31c47e589def132ff14ac8e57c1554..970bf2cf1aa5a7fd73fc0dc1d15515a313a608cf 100644 (file)
@@ -355,7 +355,8 @@ function some_keydown(e: KeyboardEvent) {
 keyops_local['wrest'] = function (uo: UoRecord) {
   wresting = !wresting;
   document.getElementById('wresting-warning')!.innerHTML = !wresting ? "" :
-      " <strong>(wresting mode!)</strong>";
+    " <strong>(wresting mode!)</strong>";
+  ungrab_all();
   recompute_keybindings();
 }
 
@@ -438,13 +439,7 @@ function drag_mousedown(e : MouseEvent, shifted: boolean) {
     }
   } else if (held == null || wresting) {
     if (!shifted) {
-      for (let tpiece of Object.keys(pieces)) {
-       let tp = pieces[tpiece]!;
-       if (tp.held == us) {
-         set_ungrab(tpiece,tp);
-         api_piece(api, 'ungrab', tpiece,tp, { });
-       }
-      }
+      ungrab_all();
     }
     dragging = DRAGGING.MAYBE_GRAB;
     drag_add_piece(piece,p);
@@ -461,6 +456,16 @@ function drag_mousedown(e : MouseEvent, shifted: boolean) {
   window.addEventListener('mouseup',   drag_mouseup,   true);
 }
 
+function ungrab_all() {
+  for (let tpiece of Object.keys(pieces)) {
+    let tp = pieces[tpiece]!;
+    if (tp.held == us) {
+         set_ungrab(tpiece,tp);
+      api_piece(api, 'ungrab', tpiece,tp, { });
+    }
+  }
+}
+
 function set_grab(piece: PieceId, p: PieceInfo, owner: PlayerId) {
   p.held = owner;
   redisplay_ancillaries(piece,p);