From 9b16c22cb096064bf59834484fbdebcf9e854a93 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 19 Jun 2022 20:13:51 +0100 Subject: [PATCH] script: Break out treat_as_pinned We're going to reuse this. Signed-off-by: Ian Jackson --- templates/script.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/templates/script.ts b/templates/script.ts index dc279f2e..8760224d 100644 --- a/templates/script.ts +++ b/templates/script.ts @@ -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; -- 2.30.2