chiark / gitweb /
Patch from James H to centralise some generally useful cursor-
[sgt-puzzles.git] / inertia.c
index 4e84f56f3a1f7ed4664995c2d191db7974fe07c5..aebd3145553a9576a0598ccc5be2ce5fe3acc1cf 100644 (file)
--- a/inertia.c
+++ b/inertia.c
@@ -1445,6 +1445,11 @@ static char *solve_game(game_state *state, game_state *currstate,
     return soln;
 }
 
+static int game_can_format_as_text_now(game_params *params)
+{
+    return TRUE;
+}
+
 static char *game_text_format(game_state *state)
 {
     return NULL;
@@ -1575,7 +1580,8 @@ static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
         dir = 1;
     else if (button == (MOD_NUM_KEYPAD | '3'))
         dir = 3;
-    else if (button == ' ' && state->soln && state->solnpos < state->soln->len)
+    else if (IS_CURSOR_SELECT(button) &&
+             state->soln && state->solnpos < state->soln->len)
        dir = state->soln->list[state->solnpos];
 
     if (dir < 0)
@@ -1626,6 +1632,10 @@ static game_state *execute_move(game_state *state, char *move)
            sol->list[i] = move[i] - '0';
        ret = dup_game(state);
        ret->cheated = TRUE;
+       if (ret->soln && --ret->soln->refcount == 0) {
+           sfree(ret->soln->list);
+           sfree(ret->soln);
+       }
        ret->soln = sol;
        ret->solnpos = 0;
        sol->refcount = 1;
@@ -2180,7 +2190,7 @@ const struct game thegame = {
     dup_game,
     free_game,
     TRUE, solve_game,
-    FALSE, game_text_format,
+    FALSE, game_can_format_as_text_now, game_text_format,
     new_ui,
     free_ui,
     encode_ui,