X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/puzzles/blobdiff_plain/fa3abef5abe95dd9668a87b1cc57a724dcbf6354..d68762325555dfb025d58f77f95557098fadf0c8:/midend.c diff --git a/midend.c b/midend.c index 215482d..df395e0 100644 --- a/midend.c +++ b/midend.c @@ -278,6 +278,8 @@ void midend_size(midend *me, int *x, int *y, int user_size) *y = me->winheight; } +int midend_tilesize(midend *me) { return me->tilesize; } + void midend_set_params(midend *me, game_params *params) { me->ourgame->free_params(me->params); @@ -335,9 +337,9 @@ void midend_new_game(midend *me) char newseed[16]; int i; newseed[15] = '\0'; - newseed[0] = '1' + random_upto(me->random, 9); + newseed[0] = '1' + (char)random_upto(me->random, 9); for (i = 1; i < 15; i++) - newseed[i] = '0' + random_upto(me->random, 10); + newseed[i] = '0' + (char)random_upto(me->random, 10); sfree(me->seedstr); me->seedstr = dupstr(newseed); @@ -383,6 +385,25 @@ void midend_new_game(midend *me) me->states[me->nstates].state = me->ourgame->new_game(me, me->params, me->desc); + /* + * As part of our commitment to self-testing, test the aux + * string to make sure nothing ghastly went wrong. + */ + if (me->ourgame->can_solve && me->aux_info) { + game_state *s; + char *msg, *movestr; + + msg = NULL; + movestr = me->ourgame->solve(me->states[0].state, + me->states[0].state, + me->aux_info, &msg); + assert(movestr && !msg); + s = me->ourgame->execute_move(me->states[0].state, movestr); + assert(s); + me->ourgame->free_game(s); + sfree(movestr); + } + me->states[me->nstates].movestr = NULL; me->states[me->nstates].movetype = NEWGAME; me->nstates++; @@ -538,6 +559,9 @@ static int midend_really_process_key(midend *me, int x, int y, int button) midend_stop_anim(me); if (!midend_redo(me)) goto done; + } else if (button == '\x13' && me->ourgame->can_solve) { + if (midend_solve(me)) + goto done; } else if (button == 'q' || button == 'Q' || button == '\x11') { ret = 0; goto done; @@ -683,6 +707,14 @@ int midend_process_key(midend *me, int x, int y, int button) * like a left click for the benefit of users of other * implementations. So the last of the above points is modified * in the presence of an (optional) button priority order. + * + * A further addition: we translate certain keyboard presses to + * cursor key 'select' buttons, so that a) frontends don't have + * to translate these themselves (like they do for CURSOR_UP etc), + * and b) individual games don't have to hard-code button presses + * of '\n' etc for keyboard-based cursors. The choice of buttons + * here could eventually be controlled by a runtime configuration + * option. */ if (IS_MOUSE_DRAG(button) || IS_MOUSE_RELEASE(button)) { if (me->pressed_mouse_button) { @@ -713,6 +745,14 @@ int midend_process_key(midend *me, int x, int y, int button) } /* + * Translate keyboard presses to cursor selection. + */ + if (button == '\n' || button == '\r') + button = CURSOR_SELECT; + if (button == ' ') + button = CURSOR_SELECT2; + + /* * Now send on the event we originally received. */ ret = ret && midend_really_process_key(me, x, y, button); @@ -816,9 +856,9 @@ float *midend_colours(midend *me, int *ncolours) buf[k] = '\0'; if ((e = getenv(buf)) != NULL && sscanf(e, "%2x%2x%2x", &r, &g, &b) == 3) { - ret[i*3 + 0] = r / 255.0; - ret[i*3 + 1] = g / 255.0; - ret[i*3 + 2] = b / 255.0; + ret[i*3 + 0] = r / 255.0F; + ret[i*3 + 1] = g / 255.0F; + ret[i*3 + 2] = b / 255.0F; } } } @@ -1288,7 +1328,7 @@ char *midend_rewrite_statusbar(midend *me, char *text) char timebuf[100], *ret; int min, sec; - sec = me->elapsed; + sec = (int)me->elapsed; min = sec / 60; sec %= 60; sprintf(timebuf, "[%d:%02d] ", min, sec); @@ -1592,7 +1632,7 @@ char *midend_deserialise(midend *me, uistr = val; val = NULL; } else if (!strcmp(key, "TIME")) { - elapsed = atof(val); + elapsed = (float)atof(val); } else if (!strcmp(key, "NSTATES")) { nstates = atoi(val); if (nstates <= 0) {