From ed091d7f5e31c69f05e8a597062265087776e5f0 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 3 Jun 2021 01:06:34 +0100 Subject: [PATCH] script: Provide piece_z_cmp and pieceid_z_cmp Signed-off-by: Ian Jackson --- templates/script.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) 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 -- 2.30.2