From: Ian Jackson Date: Thu, 3 Jun 2021 00:06:34 +0000 (+0100) Subject: script: Provide piece_z_cmp and pieceid_z_cmp X-Git-Tag: otter-0.7.0~77 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=ed091d7f5e31c69f05e8a597062265087776e5f0;p=otter.git script: Provide piece_z_cmp and pieceid_z_cmp Signed-off-by: Ian Jackson --- diff --git a/templates/script.ts b/templates/script.ts index 0d310d5c..029cbc8f 100644 --- a/templates/script.ts +++ b/templates/script.ts @@ -1803,12 +1803,22 @@ function piece_note_moved(piece: PieceId, p: PieceInfo) { movements.push({ piece: piece, p: p, this_motion: now }); } +function piece_z_cmp(a: PieceInfo, b: PieceInfo) { + if (a.z < b.z ) return -1; + if (a.z > b.z ) return +1; + if (a.zg < b.zg) return -1; + if (a.zg > b.zg) return +1; + return 0; +} + function piece_z_before(a: PieceInfo, b: PieceInfo) { - if (a.z < b.z ) return true; - if (a.z > b.z ) return false; - if (a.zg < b.zg) return true; - if (a.zg > b.zg) return false; - return false; + return piece_z_cmp(a, + b) < 0; +} + +function pieceid_z_cmp(a: PieceId, b: PieceId) { + return piece_z_cmp(pieces[a]!, + pieces[b]!); } pieceops.Move = function