From: Ian Jackson Date: Sun, 19 Jun 2022 19:13:51 +0000 (+0100) Subject: script: Break out treat_as_pinned X-Git-Tag: otter-1.2.0~18 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=9b16c22cb096064bf59834484fbdebcf9e854a93;p=otter.git script: Break out treat_as_pinned We're going to reuse this. Signed-off-by: Ian Jackson --- 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;