From ef1306764e6443d67612542654f252b376c5993e Mon Sep 17 00:00:00 2001 From: Franklin Wei Date: Mon, 23 Oct 2017 17:19:29 -0400 Subject: puzzles: resync with upstream There have been some improvements with regard to small screen sizes, which will be nice to have. Change-Id: I30c740514156258d2818fde325c1a751500f7611 --- apps/plugins/puzzles/src/unfinished/group.c | 49 ++++++++++++-------------- apps/plugins/puzzles/src/unfinished/path.c | 2 +- apps/plugins/puzzles/src/unfinished/separate.c | 6 ++-- apps/plugins/puzzles/src/unfinished/slide.c | 27 ++++++-------- apps/plugins/puzzles/src/unfinished/sokoban.c | 18 ++++------ 5 files changed, 45 insertions(+), 57 deletions(-) (limited to 'apps/plugins/puzzles/src/unfinished') diff --git a/apps/plugins/puzzles/src/unfinished/group.c b/apps/plugins/puzzles/src/unfinished/group.c index 4a4ad6ce53..b812b041eb 100644 --- a/apps/plugins/puzzles/src/unfinished/group.c +++ b/apps/plugins/puzzles/src/unfinished/group.c @@ -212,23 +212,19 @@ static config_item *game_configure(const game_params *params) ret[0].name = "Grid size"; ret[0].type = C_STRING; sprintf(buf, "%d", params->w); - ret[0].sval = dupstr(buf); - ret[0].ival = 0; + ret[0].u.string.sval = dupstr(buf); ret[1].name = "Difficulty"; ret[1].type = C_CHOICES; - ret[1].sval = DIFFCONFIG; - ret[1].ival = params->diff; + ret[1].u.choices.choicenames = DIFFCONFIG; + ret[1].u.choices.selected = params->diff; ret[2].name = "Show identity"; ret[2].type = C_BOOLEAN; - ret[2].sval = NULL; - ret[2].ival = params->id; + ret[2].u.boolean.bval = params->id; ret[3].name = NULL; ret[3].type = C_END; - ret[3].sval = NULL; - ret[3].ival = 0; return ret; } @@ -237,14 +233,14 @@ static game_params *custom_params(const config_item *cfg) { game_params *ret = snew(game_params); - ret->w = atoi(cfg[0].sval); - ret->diff = cfg[1].ival; - ret->id = cfg[2].ival; + ret->w = atoi(cfg[0].u.string.sval); + ret->diff = cfg[1].u.choices.selected; + ret->id = cfg[2].u.boolean.bval; return ret; } -static char *validate_params(const game_params *params, int full) +static const char *validate_params(const game_params *params, int full) { if (params->w < 3 || params->w > 26) return "Grid size must be between 3 and 26"; @@ -781,7 +777,7 @@ done * Gameplay. */ -static char *validate_grid_desc(const char **pdesc, int range, int area) +static const char *validate_grid_desc(const char **pdesc, int range, int area) { const char *desc = *pdesc; int squares = 0; @@ -811,7 +807,7 @@ static char *validate_grid_desc(const char **pdesc, int range, int area) return NULL; } -static char *validate_desc(const game_params *params, const char *desc) +static const char *validate_desc(const game_params *params, const char *desc) { int w = params->w, a = w*w; const char *p = desc; @@ -911,7 +907,7 @@ static void free_game(game_state *state) } static char *solve_game(const game_state *state, const game_state *currstate, - const char *aux, char **error) + const char *aux, const char **error) { int w = state->par.w, a = w*w; int i, ret; @@ -1281,13 +1277,13 @@ static char *interpret_move(const game_state *state, game_ui *ui, ui->drag |= 4; /* some movement has happened */ if (tcoord >= 0 && tcoord < w) { ui->dragpos = tcoord; - return ""; + return UI_UPDATE; } } else if (IS_MOUSE_RELEASE(button)) { if (ui->drag & 4) { ui->drag = 0; /* end drag */ if (state->sequence[ui->dragpos] == ui->dragnum) - return ""; /* drag was a no-op overall */ + return UI_UPDATE; /* drag was a no-op overall */ sprintf(buf, "D%d,%d", ui->dragnum, ui->dragpos); return dupstr(buf); } else { @@ -1298,7 +1294,7 @@ static char *interpret_move(const game_state *state, game_ui *ui, state->sequence[ui->edgepos]); return dupstr(buf); } else - return ""; /* no-op */ + return UI_UPDATE; /* no-op */ } } } else if (IS_MOUSE_DOWN(button)) { @@ -1321,7 +1317,7 @@ static char *interpret_move(const game_state *state, game_ui *ui, ui->hpencil = 0; } ui->hcursor = 0; - return ""; /* UI activity occurred */ + return UI_UPDATE; } if (button == RIGHT_BUTTON) { /* @@ -1345,20 +1341,20 @@ static char *interpret_move(const game_state *state, game_ui *ui, ui->hshow = 0; } ui->hcursor = 0; - return ""; /* UI activity occurred */ + return UI_UPDATE; } } else if (tx >= 0 && tx < w && ty == -1) { ui->drag = 2; ui->dragnum = state->sequence[tx]; ui->dragpos = tx; ui->edgepos = FROMCOORD(x + TILESIZE/2); - return ""; + return UI_UPDATE; } else if (ty >= 0 && ty < w && tx == -1) { ui->drag = 1; ui->dragnum = state->sequence[ty]; ui->dragpos = ty; ui->edgepos = FROMCOORD(y + TILESIZE/2); - return ""; + return UI_UPDATE; } } else if (IS_MOUSE_DRAG(button)) { if (!ui->hpencil && @@ -1371,7 +1367,7 @@ static char *interpret_move(const game_state *state, game_ui *ui, ui->odx = ui->ody = 0; ui->odn = 1; } - return ""; + return UI_UPDATE; } if (IS_CURSOR_MOVE(button)) { @@ -1381,13 +1377,13 @@ static char *interpret_move(const game_state *state, game_ui *ui, ui->hx = state->sequence[cx]; ui->hy = state->sequence[cy]; ui->hshow = ui->hcursor = 1; - return ""; + return UI_UPDATE; } if (ui->hshow && (button == CURSOR_SELECT)) { ui->hpencil = 1 - ui->hpencil; ui->hcursor = 1; - return ""; + return UI_UPDATE; } if (ui->hshow && @@ -2110,7 +2106,8 @@ int main(int argc, char **argv) { game_params *p; game_state *s; - char *id = NULL, *desc, *err; + char *id = NULL, *desc; + const char *err; digit *grid; int grade = FALSE; int ret, diff, really_show_working = FALSE; diff --git a/apps/plugins/puzzles/src/unfinished/path.c b/apps/plugins/puzzles/src/unfinished/path.c index 61d6c61c6a..d4ec5d87cc 100644 --- a/apps/plugins/puzzles/src/unfinished/path.c +++ b/apps/plugins/puzzles/src/unfinished/path.c @@ -770,7 +770,7 @@ int main(void) #ifdef TEST_GENERAL #include -void fatal(char *fmt, ...) +void fatal(const char *fmt, ...) { va_list ap; diff --git a/apps/plugins/puzzles/src/unfinished/separate.c b/apps/plugins/puzzles/src/unfinished/separate.c index a7b4fc96e1..7fd8da8202 100644 --- a/apps/plugins/puzzles/src/unfinished/separate.c +++ b/apps/plugins/puzzles/src/unfinished/separate.c @@ -170,7 +170,7 @@ static game_params *custom_params(const config_item *cfg) return NULL; } -static char *validate_params(const game_params *params, int full) +static const char *validate_params(const game_params *params, int full) { return NULL; } @@ -646,7 +646,7 @@ static char *new_game_desc(const game_params *params, random_state *rs, return desc; } -static char *validate_desc(const game_params *params, const char *desc) +static const char *validate_desc(const game_params *params, const char *desc) { return NULL; } @@ -676,7 +676,7 @@ static void free_game(game_state *state) } static char *solve_game(const game_state *state, const game_state *currstate, - const char *aux, char **error) + const char *aux, const char **error) { return NULL; } diff --git a/apps/plugins/puzzles/src/unfinished/slide.c b/apps/plugins/puzzles/src/unfinished/slide.c index 9d4fce1461..9770013235 100644 --- a/apps/plugins/puzzles/src/unfinished/slide.c +++ b/apps/plugins/puzzles/src/unfinished/slide.c @@ -244,25 +244,20 @@ static config_item *game_configure(const game_params *params) ret[0].name = "Width"; ret[0].type = C_STRING; sprintf(buf, "%d", params->w); - ret[0].sval = dupstr(buf); - ret[0].ival = 0; + ret[0].u.string.sval = dupstr(buf); ret[1].name = "Height"; ret[1].type = C_STRING; sprintf(buf, "%d", params->h); - ret[1].sval = dupstr(buf); - ret[1].ival = 0; + ret[1].u.string.sval = dupstr(buf); ret[2].name = "Solution length limit"; ret[2].type = C_STRING; sprintf(buf, "%d", params->maxmoves); - ret[2].sval = dupstr(buf); - ret[2].ival = 0; + ret[2].u.string.sval = dupstr(buf); ret[3].name = NULL; ret[3].type = C_END; - ret[3].sval = NULL; - ret[3].ival = 0; return ret; } @@ -271,14 +266,14 @@ static game_params *custom_params(const config_item *cfg) { game_params *ret = snew(game_params); - ret->w = atoi(cfg[0].sval); - ret->h = atoi(cfg[1].sval); - ret->maxmoves = atoi(cfg[2].sval); + ret->w = atoi(cfg[0].u.string.sval); + ret->h = atoi(cfg[1].u.string.sval); + ret->maxmoves = atoi(cfg[2].u.string.sval); return ret; } -static char *validate_params(const game_params *params, int full) +static const char *validate_params(const game_params *params, int full) { if (params->w > MAXWID) return "Width must be at most " STR(MAXWID); @@ -891,7 +886,7 @@ static char *new_game_desc(const game_params *params, random_state *rs, return ret; } -static char *validate_desc(const game_params *params, const char *desc) +static const char *validate_desc(const game_params *params, const char *desc) { int w = params->w, h = params->h, wh = w*h; int *active, *link; @@ -1126,7 +1121,7 @@ static void free_game(game_state *state) } static char *solve_game(const game_state *state, const game_state *currstate, - const char *aux, char **error) + const char *aux, const char **error) { int *moves; int nmoves; @@ -1349,7 +1344,7 @@ static char *interpret_move(const game_state *state, game_ui *ui, * And that's it. Update the display to reflect the start * of a drag. */ - return ""; + return UI_UPDATE; } else if (button == LEFT_DRAG && ui->dragging) { int dist, distlimit, dx, dy, s, px, py; @@ -1376,7 +1371,7 @@ static char *interpret_move(const game_state *state, game_ui *ui, if (px >= 0 && px < w && py >= 0 && py < h && ui->reachable[py*w+px]) { ui->drag_currpos = py*w+px; - return ""; + return UI_UPDATE; } } } diff --git a/apps/plugins/puzzles/src/unfinished/sokoban.c b/apps/plugins/puzzles/src/unfinished/sokoban.c index 2f0af35bc2..1264690416 100644 --- a/apps/plugins/puzzles/src/unfinished/sokoban.c +++ b/apps/plugins/puzzles/src/unfinished/sokoban.c @@ -210,19 +210,15 @@ static config_item *game_configure(const game_params *params) ret[0].name = "Width"; ret[0].type = C_STRING; sprintf(buf, "%d", params->w); - ret[0].sval = dupstr(buf); - ret[0].ival = 0; + ret[0].u.string.sval = dupstr(buf); ret[1].name = "Height"; ret[1].type = C_STRING; sprintf(buf, "%d", params->h); - ret[1].sval = dupstr(buf); - ret[1].ival = 0; + ret[1].u.string.sval = dupstr(buf); ret[2].name = NULL; ret[2].type = C_END; - ret[2].sval = NULL; - ret[2].ival = 0; return ret; } @@ -231,13 +227,13 @@ static game_params *custom_params(const config_item *cfg) { game_params *ret = snew(game_params); - ret->w = atoi(cfg[0].sval); - ret->h = atoi(cfg[1].sval); + ret->w = atoi(cfg[0].u.string.sval); + ret->h = atoi(cfg[1].u.string.sval); return ret; } -static char *validate_params(const game_params *params, int full) +static const char *validate_params(const game_params *params, int full) { if (params->w < 4 || params->h < 4) return "Width and height must both be at least 4"; @@ -806,7 +802,7 @@ static char *new_game_desc(const game_params *params, random_state *rs, return desc; } -static char *validate_desc(const game_params *params, const char *desc) +static const char *validate_desc(const game_params *params, const char *desc) { int w = params->w, h = params->h; int area = 0; @@ -903,7 +899,7 @@ static void free_game(game_state *state) } static char *solve_game(const game_state *state, const game_state *currstate, - const char *aux, char **error) + const char *aux, const char **error) { return NULL; } -- cgit v1.2.3