chiark / gitweb /
script: Sort drag piece list
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 3 Jun 2021 00:10:32 +0000 (01:10 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 3 Jun 2021 00:10:32 +0000 (01:10 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
templates/script.ts

index e70f785bf37c0e3c69cd118a4da25e0d4353929f..150c28f6f22bd2eb3a7320ba85211424d22c3dea 100644 (file)
@@ -1196,6 +1196,7 @@ function drag_mousemove(e: MouseEvent) {
       if (need_redisplay_ancillaries) redisplay_ancillaries(tpiece, tp);
     }
     if (!(dragging & DRAGGING.RAISED)) {
+      sort_drag_pieces();
       for (let dp of drag_pieces) {
        let piece = dp.piece;
        let p = pieces[piece]!;
@@ -1216,6 +1217,13 @@ function drag_mousemove(e: MouseEvent) {
   }
   return ddr2;
 }
+function sort_drag_pieces() {
+  function sort_with(a: DragInfo, b: DragInfo): number {
+    return pieceid_z_cmp(a.piece,
+                        b.piece);
+  }
+  drag_pieces.sort(sort_with);
+}
 
 function drag_mouseup(e: MouseEvent) {
   console.log('mouseup', dragging);
@@ -1226,6 +1234,7 @@ function drag_mouseup(e: MouseEvent) {
 function drag_end() {
   if (dragging == DRAGGING.MAYBE_UNGRAB ||
       (dragging & ~DRAGGING.RAISED) == (DRAGGING.MAYBE_GRAB | DRAGGING.YES)) {
+    sort_drag_pieces();
     for (let dp of drag_pieces) {
       let piece = dp.piece;
       let p = pieces[piece]!;