chiark / gitweb /
script: Break out treat_as_pinned
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 19 Jun 2022 19:13:51 +0000 (20:13 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 19 Jun 2022 19:59:49 +0000 (20:59 +0100)
We're going to reuse this.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
templates/script.ts

index dc279f2ea8280a4980a23b37efbc29a164a062f9..8760224d15f5912c446996f34f1fc315ef958864 100644 (file)
@@ -300,6 +300,9 @@ function piece_element(base: string, piece: PieceId): SVGGraphicsElement | null
 function piece_moveable(p: PieceInfo) {
   return p.moveable == 'Yes' || p.moveable == 'IfWresting' && wresting;
 }
+function treat_as_pinned(p: { pinned: boolean }): boolean {
+  return p.pinned && !wresting;
+}
 
 // ----- key handling -----
 
@@ -1095,7 +1098,7 @@ function mouse_find_predicate(
     }
 
     let p = pieces[piece];
-    if (p.pinned && !wresting) continue;
+    if (treat_as_pinned(p)) continue;
     if (p.held && p.held != us && !wresting) continue;
     if (i > 0 && !piece_moveable(p))
       continue;
@@ -1194,7 +1197,6 @@ function drag_mousedown(e : MouseEvent, shifted: boolean) {
   if (c == null) return;
   let clicked = c.clicked;
   let held = c.held;
-  let pinned = c.pinned;
   let multigrab = c.multigrab;
 
   special_count = null;
@@ -1212,7 +1214,7 @@ function drag_mousedown(e : MouseEvent, shifted: boolean) {
     if (!shifted) {
       ungrab_all_except(note_already);
     }
-    if (pinned && !wresting) {
+    if (treat_as_pinned(c)) {
       let p = pieces[c.clicked[0]!]!;
       add_log_message('That piece ('+p.desc+') is pinned to the table.');
       return;