From 0b036c9e79578cec5425aaca1b1af13a4ae0d937 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Wed, 7 Dec 2022 18:43:34 +0000 Subject: [PATCH] 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. --- galaxies.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/galaxies.c b/galaxies.c index 9a7b363..908b45a 100644 --- a/galaxies.c +++ b/galaxies.c @@ -353,6 +353,8 @@ static bool ok_to_add_assoc_with_opposite_internal( int *colors; bool toret; + if (tile->type != s_tile) + return false; if (tile->flags & F_DOT) return false; if (opposite == NULL) @@ -2645,14 +2647,14 @@ static char *interpret_move(const game_state *state, game_ui *ui, ui->dy = y; return UI_UPDATE; } else if (button == RIGHT_RELEASE && ui->dragging) { - ui->dragging = false; - /* * Drags are always targeted at a single square. */ 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 @@ static char *interpret_move(const game_state *state, game_ui *ui, } 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);