aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2022-12-07 18:43:34 +0000
committerBen Harris <bjh21@bjh21.me.uk>2022-12-07 20:41:49 +0000
commit0b036c9e79578cec5425aaca1b1af13a4ae0d937 (patch)
tree467da38cfba0922ea94a0e3407a565c8348471b2
parent09f2052fbfbc8a2136b09cf3a868c8cf9c239de0 (diff)
downloadpuzzles-0b036c9e79578cec5425aaca1b1af13a4ae0d937.zip
puzzles-0b036c9e79578cec5425aaca1b1af13a4ae0d937.tar.gz
puzzles-0b036c9e79578cec5425aaca1b1af13a4ae0d937.tar.bz2
puzzles-0b036c9e79578cec5425aaca1b1af13a4ae0d937.tar.xz
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.
-rw-r--r--galaxies.c20
1 files 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);