shithub: puzzles

Download patch

ref: 0b036c9e79578cec5425aaca1b1af13a4ae0d937
parent: 09f2052fbfbc8a2136b09cf3a868c8cf9c239de0
author: Ben Harris <bjh21@bjh21.me.uk>
date: Wed Dec 7 13:43:34 EST 2022

galaxies: Use the same code for handling all dropped arrows

The keyboard code was prone to adding null items to the undo history,
and was also unreadable.  Rather than fix it, I've replaced it with a
jump to the mouse drop handling, lightly enhanced to reject drops on
things that aren't tiles.

--- a/galaxies.c
+++ b/galaxies.c
@@ -353,6 +353,8 @@
     int *colors;
     bool toret;
 
+    if (tile->type != s_tile)
+        return false;
     if (tile->flags & F_DOT)
         return false;
     if (opposite == NULL)
@@ -2645,8 +2647,6 @@
         ui->dy = y;
         return UI_UPDATE;
     } else if (button == RIGHT_RELEASE && ui->dragging) {
-        ui->dragging = false;
-
         /*
          * Drags are always targeted at a single square.
          */
@@ -2653,6 +2653,8 @@
         px = 2*FROMCOORD(x+TILE_SIZE) - 1;
         py = 2*FROMCOORD(y+TILE_SIZE) - 1;
 
+        dropped: /* We arrive here from the end of a keyboard drag. */
+        ui->dragging = false;
 	/*
 	 * Dragging an arrow on to the same square it started from
 	 * is a null move; just update the ui and finish.
@@ -2710,18 +2712,8 @@
         }
         sp = &SPACE(state, ui->cur_x, ui->cur_y);
         if (ui->dragging) {
-            ui->dragging = false;
-
-            if ((ui->srcx != ui->dotx || ui->srcy != ui->doty) &&
-                SPACE(state, ui->srcx, ui->srcy).flags & F_TILE_ASSOC) {
-                sprintf(buf, "%sU%d,%d", sep, ui->srcx, ui->srcy);
-                sep = ";";
-            }
-            if (sp->type == s_tile && !(sp->flags & F_DOT) && !(sp->flags & F_TILE_ASSOC)) {
-                sprintf(buf + strlen(buf), "%sA%d,%d,%d,%d",
-                        sep, ui->cur_x, ui->cur_y, ui->dotx, ui->doty);
-            }
-            return dupstr(buf);
+            px = ui->cur_x; py = ui->cur_y;
+            goto dropped;
         } else if (sp->flags & F_DOT) {
             ui->dragging = true;
             ui->dx = SCOORD(ui->cur_x);