X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/puzzles/blobdiff_plain/3ff276f2cd88e6f3a6fe08f95f6147abbe3fcfd4..7f34e0edcaf2134e534b8a5527da828234bda714:/midend.c diff --git a/midend.c b/midend.c index 7ef05cb..ceef686 100644 --- a/midend.c +++ b/midend.c @@ -237,7 +237,8 @@ void midend_set_params(midend_data *me, game_params *params) static void midend_set_timer(midend_data *me) { me->timing = (me->ourgame->is_timed && - me->ourgame->timing_state(me->states[me->statepos-1].state)); + me->ourgame->timing_state(me->states[me->statepos-1].state, + me->ui)); if (me->timing || me->flash_time || me->anim_time) activate_timer(me->frontend); else @@ -311,10 +312,10 @@ void midend_new_game(midend_data *me) me->drawstate = me->ourgame->new_drawstate(me->states[0].state); midend_size_new_drawstate(me); me->elapsed = 0.0F; - midend_set_timer(me); if (me->ui) me->ourgame->free_ui(me->ui); me->ui = me->ourgame->new_ui(me->states[0].state); + midend_set_timer(me); me->pressed_mouse_button = 0; } @@ -431,7 +432,7 @@ static int midend_really_process_key(midend_data *me, int x, int y, int button) { game_state *oldstate = me->ourgame->dup_game(me->states[me->statepos - 1].state); - int special = FALSE, gotspecial = FALSE, ret = 1; + int type = MOVE, gottype = FALSE, ret = 1; float anim_time; game_state *s; char *movestr; @@ -449,8 +450,8 @@ static int midend_really_process_key(midend_data *me, int x, int y, int button) } else if (button == 'u' || button == 'u' || button == '\x1A' || button == '\x1F') { midend_stop_anim(me); - special = special(me->states[me->statepos-1].movetype); - gotspecial = TRUE; + type = me->states[me->statepos-1].movetype; + gottype = TRUE; if (!midend_undo(me)) goto done; } else if (button == 'r' || button == 'R' || @@ -491,18 +492,23 @@ static int midend_really_process_key(midend_data *me, int x, int y, int button) me->states[me->nstates].movetype = MOVE; me->statepos = ++me->nstates; me->dir = +1; + if (me->ui) + me->ourgame->changed_state(me->ui, + me->states[me->statepos-2].state, + me->states[me->statepos-1].state); } else { goto done; } } - if (!gotspecial) - special = special(me->states[me->statepos-1].movetype); + if (!gottype) + type = me->states[me->statepos-1].movetype; /* * See if this move requires an animation. */ - if (special) { + if (special(type) && !(type == SOLVE && + (me->ourgame->mouse_priorities & SOLVE_ANIMATES))) { anim_time = 0; } else { anim_time = me->ourgame->anim_length(oldstate, @@ -716,11 +722,13 @@ float *midend_colours(midend_data *me, int *ncolours) for (i = 0; i < *ncolours; i++) { char buf[80], *e; unsigned int r, g, b; - int j; + int j, k; sprintf(buf, "%s_COLOUR_%d", me->ourgame->name, i); - for (j = 0; buf[j]; j++) - buf[j] = toupper((unsigned char)buf[j]); + for (j = k = 0; buf[j]; j++) + if (!isspace((unsigned char)buf[j])) + buf[k++] = toupper((unsigned char)buf[j]); + buf[k] = '\0'; if ((e = getenv(buf)) != NULL && sscanf(e, "%2x%2x%2x", &r, &g, &b) == 3) { ret[i*3 + 0] = r / 255.0; @@ -766,11 +774,13 @@ int midend_num_presets(midend_data *me) * encoded parameter strings. */ char buf[80], *e, *p; - int j; + int j, k; sprintf(buf, "%s_PRESETS", me->ourgame->name); - for (j = 0; buf[j]; j++) - buf[j] = toupper((unsigned char)buf[j]); + for (j = k = 0; buf[j]; j++) + if (!isspace((unsigned char)buf[j])) + buf[k++] = toupper((unsigned char)buf[j]); + buf[k] = '\0'; if ((e = getenv(buf)) != NULL) { p = e = dupstr(e); @@ -1112,8 +1122,18 @@ char *midend_solve(midend_data *me) me->ourgame->changed_state(me->ui, me->states[me->statepos-2].state, me->states[me->statepos-1].state); - me->anim_time = 0.0; - midend_finish_move(me); + me->dir = +1; + if (me->ourgame->mouse_priorities & SOLVE_ANIMATES) { + me->oldstate = me->ourgame->dup_game(me->states[me->statepos-2].state); + me->anim_time = + me->ourgame->anim_length(me->states[me->statepos-2].state, + me->states[me->statepos-1].state, + +1, me->ui); + me->anim_pos = 0.0; + } else { + me->anim_time = 0.0; + midend_finish_move(me); + } midend_redraw(me); midend_set_timer(me); return NULL; @@ -1350,6 +1370,7 @@ char *midend_deserialise(midend_data *me, if (key[8] != ':') { if (started) ret = "Data was incorrectly formatted for a saved game file"; + goto cleanup; } len = strcspn(key, ": "); assert(len <= 8);