From dc2407ed0ce90a15d8b494850964de74fe5ea7df Mon Sep 17 00:00:00 2001 From: Hauke Rehr Date: Tue, 11 Feb 2025 07:36:33 +0100 Subject: [PATCH] Use semantic enum entry names for pref indices [Commit message added by SGT: this makes it easier to allocate indices in the config_item array, and keep them in sync between get_prefs and set_prefs for each game.] --- bridges.c | 21 +++++++++++++-------- fifteen.c | 26 ++++++++++++++++---------- guess.c | 21 +++++++++++++-------- keen.c | 22 ++++++++++++++-------- lightup.c | 21 +++++++++++++-------- loopy.c | 36 +++++++++++++++++++++--------------- map.c | 52 ++++++++++++++++++++++++++++++---------------------- net.c | 22 ++++++++++++++-------- palisade.c | 25 +++++++++++++++---------- pearl.c | 25 +++++++++++++++---------- range.c | 25 +++++++++++++++---------- signpost.c | 26 ++++++++++++++++---------- singles.c | 21 +++++++++++++-------- slant.c | 26 ++++++++++++++++---------- solo.c | 22 ++++++++++++++-------- towers.c | 37 ++++++++++++++++++++++--------------- undead.c | 37 ++++++++++++++++++++++--------------- unequal.c | 22 ++++++++++++++-------- untangle.c | 47 +++++++++++++++++++++++++++-------------------- 19 files changed, 323 insertions(+), 211 deletions(-) diff --git a/bridges.c b/bridges.c index 700fd3e..4244447 100644 --- a/bridges.c +++ b/bridges.c @@ -107,6 +107,11 @@ enum { NCOLOURS }; +enum { + PREF_SHOW_HINTS, + N_PREF_ITEMS +}; + struct game_params { int w, h, maxb; int islands, expansion; /* %age of island squares, %age chance of expansion */ @@ -2145,22 +2150,22 @@ static config_item *get_prefs(game_ui *ui) { config_item *ret; - ret = snewn(2, config_item); + ret = snewn(N_PREF_ITEMS+1, config_item); - ret[0].name = "Show possible bridge locations"; - ret[0].kw = "show-hints"; - ret[0].type = C_BOOLEAN; - ret[0].u.boolean.bval = ui->show_hints; + ret[PREF_SHOW_HINTS].name = "Show possible bridge locations"; + ret[PREF_SHOW_HINTS].kw = "show-hints"; + ret[PREF_SHOW_HINTS].type = C_BOOLEAN; + ret[PREF_SHOW_HINTS].u.boolean.bval = ui->show_hints; - ret[1].name = NULL; - ret[1].type = C_END; + ret[N_PREF_ITEMS].name = NULL; + ret[N_PREF_ITEMS].type = C_END; return ret; } static void set_prefs(game_ui *ui, const config_item *cfg) { - ui->show_hints = cfg[0].u.boolean.bval; + ui->show_hints = cfg[PREF_SHOW_HINTS].u.boolean.bval; } static void free_ui(game_ui *ui) diff --git a/fifteen.c b/fifteen.c index a2a9554..2682c68 100644 --- a/fifteen.c +++ b/fifteen.c @@ -43,6 +43,11 @@ enum { NCOLOURS }; +enum { + PREF_ARROW_SEMANTICS, + N_PREF_ITEMS +}; + struct game_params { int w, h; }; @@ -488,24 +493,25 @@ static config_item *get_prefs(game_ui *ui) { config_item *ret; - ret = snewn(2, config_item); + ret = snewn(N_PREF_ITEMS+1, config_item); - ret[0].name = "Sense of arrow keys"; - ret[0].kw = "arrow-semantics"; - ret[0].type = C_CHOICES; - ret[0].u.choices.choicenames = ":Move the tile:Move the gap"; - ret[0].u.choices.choicekws = ":tile:gap"; - ret[0].u.choices.selected = ui->invert_cursor; + ret[PREF_ARROW_SEMANTICS].name = "Sense of arrow keys"; + ret[PREF_ARROW_SEMANTICS].kw = "arrow-semantics"; + ret[PREF_ARROW_SEMANTICS].type = C_CHOICES; + ret[PREF_ARROW_SEMANTICS].u.choices.choicenames = + ":Move the tile:Move the gap"; + ret[PREF_ARROW_SEMANTICS].u.choices.choicekws = ":tile:gap"; + ret[PREF_ARROW_SEMANTICS].u.choices.selected = ui->invert_cursor; - ret[1].name = NULL; - ret[1].type = C_END; + ret[N_PREF_ITEMS].name = NULL; + ret[N_PREF_ITEMS].type = C_END; return ret; } static void set_prefs(game_ui *ui, const config_item *cfg) { - ui->invert_cursor = cfg[0].u.choices.selected; + ui->invert_cursor = cfg[PREF_ARROW_SEMANTICS].u.choices.selected; } static void free_ui(game_ui *ui) diff --git a/guess.c b/guess.c index 4a2a718..13d6276 100644 --- a/guess.c +++ b/guess.c @@ -26,6 +26,11 @@ enum { NCOLOURS }; +enum { + PREF_SHOW_LABELS, + N_PREF_ITEMS +}; + struct game_params { int ncolours, npegs, nguesses; bool allow_blank, allow_multiple; @@ -431,22 +436,22 @@ static config_item *get_prefs(game_ui *ui) { config_item *ret; - ret = snewn(2, config_item); + ret = snewn(N_PREF_ITEMS+1, config_item); - ret[0].name = "Label colours with numbers"; - ret[0].kw = "show-labels"; - ret[0].type = C_BOOLEAN; - ret[0].u.boolean.bval = ui->show_labels; + ret[PREF_SHOW_LABELS].name = "Label colours with numbers"; + ret[PREF_SHOW_LABELS].kw = "show-labels"; + ret[PREF_SHOW_LABELS].type = C_BOOLEAN; + ret[PREF_SHOW_LABELS].u.boolean.bval = ui->show_labels; - ret[1].name = NULL; - ret[1].type = C_END; + ret[N_PREF_ITEMS].name = NULL; + ret[N_PREF_ITEMS].type = C_END; return ret; } static void set_prefs(game_ui *ui, const config_item *cfg) { - ui->show_labels = cfg[0].u.boolean.bval; + ui->show_labels = cfg[PREF_SHOW_LABELS].u.boolean.bval; } static void free_ui(game_ui *ui) diff --git a/keen.c b/keen.c index 7e2f71c..ce3846f 100644 --- a/keen.c +++ b/keen.c @@ -65,6 +65,11 @@ enum { NCOLOURS }; +enum { + PREF_PENCIL_KEEP_HIGHLIGHT, + N_PREF_ITEMS +}; + struct game_params { int w, diff; bool multiplication_only; @@ -1560,22 +1565,23 @@ static config_item *get_prefs(game_ui *ui) { config_item *ret; - ret = snewn(2, config_item); + ret = snewn(N_PREF_ITEMS+1, config_item); - ret[0].name = "Keep mouse highlight after changing a pencil mark"; - ret[0].kw = "pencil-keep-highlight"; - ret[0].type = C_BOOLEAN; - ret[0].u.boolean.bval = ui->pencil_keep_highlight; + ret[PREF_PENCIL_KEEP_HIGHLIGHT].name = + "Keep mouse highlight after changing a pencil mark"; + ret[PREF_PENCIL_KEEP_HIGHLIGHT].kw = "pencil-keep-highlight"; + ret[PREF_PENCIL_KEEP_HIGHLIGHT].type = C_BOOLEAN; + ret[PREF_PENCIL_KEEP_HIGHLIGHT].u.boolean.bval = ui->pencil_keep_highlight; - ret[1].name = NULL; - ret[1].type = C_END; + ret[N_PREF_ITEMS].name = NULL; + ret[N_PREF_ITEMS].type = C_END; return ret; } static void set_prefs(game_ui *ui, const config_item *cfg) { - ui->pencil_keep_highlight = cfg[0].u.boolean.bval; + ui->pencil_keep_highlight = cfg[PREF_PENCIL_KEEP_HIGHLIGHT].u.boolean.bval; } static void game_changed_state(game_ui *ui, const game_state *oldstate, diff --git a/lightup.c b/lightup.c index e779663..fc04e4f 100644 --- a/lightup.c +++ b/lightup.c @@ -95,6 +95,11 @@ enum { enum { SYMM_NONE, SYMM_REF2, SYMM_ROT2, SYMM_REF4, SYMM_ROT4, SYMM_MAX }; +enum { + PREF_SHOW_LIT_BLOBS, + N_PREF_ITEMS +}; + #define DIFFCOUNT 2 struct game_params { @@ -1871,22 +1876,22 @@ static config_item *get_prefs(game_ui *ui) { config_item *ret; - ret = snewn(2, config_item); + ret = snewn(N_PREF_ITEMS+1, config_item); - ret[0].name = "Draw non-light marks even when lit"; - ret[0].kw = "show-lit-blobs"; - ret[0].type = C_BOOLEAN; - ret[0].u.boolean.bval = ui->draw_blobs_when_lit; + ret[PREF_SHOW_LIT_BLOBS].name = "Draw non-light marks even when lit"; + ret[PREF_SHOW_LIT_BLOBS].kw = "show-lit-blobs"; + ret[PREF_SHOW_LIT_BLOBS].type = C_BOOLEAN; + ret[PREF_SHOW_LIT_BLOBS].u.boolean.bval = ui->draw_blobs_when_lit; - ret[1].name = NULL; - ret[1].type = C_END; + ret[N_PREF_ITEMS].name = NULL; + ret[N_PREF_ITEMS].type = C_END; return ret; } static void set_prefs(game_ui *ui, const config_item *cfg) { - ui->draw_blobs_when_lit = cfg[0].u.boolean.bval; + ui->draw_blobs_when_lit = cfg[PREF_SHOW_LIT_BLOBS].u.boolean.bval; } static void free_ui(game_ui *ui) diff --git a/loopy.c b/loopy.c index b30dd68..a103fa5 100644 --- a/loopy.c +++ b/loopy.c @@ -111,6 +111,12 @@ enum { NCOLOURS }; +enum { + PREF_DRAW_FAINT_LINES, + PREF_AUTO_FOLLOW, + N_PREF_ITEMS +}; + struct game_state { grid *game_grid; /* ref-counted (internally) */ @@ -939,31 +945,31 @@ static config_item *get_prefs(game_ui *ui) { config_item *ret; - ret = snewn(3, config_item); + ret = snewn(N_PREF_ITEMS+1, config_item); - ret[0].name = "Draw excluded grid lines faintly"; - ret[0].kw = "draw-faint-lines"; - ret[0].type = C_BOOLEAN; - ret[0].u.boolean.bval = ui->draw_faint_lines; + ret[PREF_DRAW_FAINT_LINES].name = "Draw excluded grid lines faintly"; + ret[PREF_DRAW_FAINT_LINES].kw = "draw-faint-lines"; + ret[PREF_DRAW_FAINT_LINES].type = C_BOOLEAN; + ret[PREF_DRAW_FAINT_LINES].u.boolean.bval = ui->draw_faint_lines; - ret[1].name = "Auto-follow unique paths of edges"; - ret[1].kw = "auto-follow"; - ret[1].type = C_CHOICES; - ret[1].u.choices.choicenames = + ret[PREF_AUTO_FOLLOW].name = "Auto-follow unique paths of edges"; + ret[PREF_AUTO_FOLLOW].kw = "auto-follow"; + ret[PREF_AUTO_FOLLOW].type = C_CHOICES; + ret[PREF_AUTO_FOLLOW].u.choices.choicenames = ":No:Based on grid only:Based on grid and game state"; - ret[1].u.choices.choicekws = ":off:fixed:adaptive"; - ret[1].u.choices.selected = ui->autofollow; + ret[PREF_AUTO_FOLLOW].u.choices.choicekws = ":off:fixed:adaptive"; + ret[PREF_AUTO_FOLLOW].u.choices.selected = ui->autofollow; - ret[2].name = NULL; - ret[2].type = C_END; + ret[N_PREF_ITEMS].name = NULL; + ret[N_PREF_ITEMS].type = C_END; return ret; } static void set_prefs(game_ui *ui, const config_item *cfg) { - ui->draw_faint_lines = cfg[0].u.boolean.bval; - ui->autofollow = cfg[1].u.choices.selected; + ui->draw_faint_lines = cfg[PREF_DRAW_FAINT_LINES].u.boolean.bval; + ui->autofollow = cfg[PREF_AUTO_FOLLOW].u.choices.selected; } static void game_changed_state(game_ui *ui, const game_state *oldstate, diff --git a/map.c b/map.c index 2ef156e..002a3f9 100644 --- a/map.c +++ b/map.c @@ -73,6 +73,13 @@ enum { NCOLOURS }; +enum { + PREF_FLASH_TYPE, + PREF_SHOW_NUMBERS, + PREF_STIPPLE_STYLE, + N_PREF_ITEMS +}; + struct game_params { int w, h, n, diff; }; @@ -2339,38 +2346,39 @@ static config_item *get_prefs(game_ui *ui) { config_item *ret; - ret = snewn(4, config_item); + ret = snewn(N_PREF_ITEMS+1, config_item); - ret[0].name = "Victory flash effect"; - ret[0].kw = "flash-type"; - ret[0].type = C_CHOICES; - ret[0].u.choices.choicenames = ":Cyclic:Each to white:All to white"; - ret[0].u.choices.choicekws = ":cyclic:each-white:all-white"; - ret[0].u.choices.selected = ui->flash_type; + ret[PREF_FLASH_TYPE].name = "Victory flash effect"; + ret[PREF_FLASH_TYPE].kw = "flash-type"; + ret[PREF_FLASH_TYPE].type = C_CHOICES; + ret[PREF_FLASH_TYPE].u.choices.choicenames = + ":Cyclic:Each to white:All to white"; + ret[PREF_FLASH_TYPE].u.choices.choicekws = ":cyclic:each-white:all-white"; + ret[PREF_FLASH_TYPE].u.choices.selected = ui->flash_type; - ret[1].name = "Number regions"; - ret[1].kw = "show-numbers"; - ret[1].type = C_BOOLEAN; - ret[1].u.boolean.bval = ui->show_numbers; + ret[PREF_SHOW_NUMBERS].name = "Number regions"; + ret[PREF_SHOW_NUMBERS].kw = "show-numbers"; + ret[PREF_SHOW_NUMBERS].type = C_BOOLEAN; + ret[PREF_SHOW_NUMBERS].u.boolean.bval = ui->show_numbers; - ret[2].name = "Display style for stipple marks"; - ret[2].kw = "stipple-style"; - ret[2].type = C_CHOICES; - ret[2].u.choices.choicenames = ":Small:Large"; - ret[2].u.choices.choicekws = ":small:large"; - ret[2].u.choices.selected = ui->large_stipples; + ret[PREF_STIPPLE_STYLE].name = "Display style for stipple marks"; + ret[PREF_STIPPLE_STYLE].kw = "stipple-style"; + ret[PREF_STIPPLE_STYLE].type = C_CHOICES; + ret[PREF_STIPPLE_STYLE].u.choices.choicenames = ":Small:Large"; + ret[PREF_STIPPLE_STYLE].u.choices.choicekws = ":small:large"; + ret[PREF_STIPPLE_STYLE].u.choices.selected = ui->large_stipples; - ret[3].name = NULL; - ret[3].type = C_END; + ret[N_PREF_ITEMS].name = NULL; + ret[N_PREF_ITEMS].type = C_END; return ret; } static void set_prefs(game_ui *ui, const config_item *cfg) { - ui->flash_type = cfg[0].u.choices.selected; - ui->show_numbers = cfg[1].u.boolean.bval; - ui->large_stipples = cfg[2].u.choices.selected; + ui->flash_type = cfg[PREF_FLASH_TYPE].u.choices.selected; + ui->show_numbers = cfg[PREF_SHOW_NUMBERS].u.boolean.bval; + ui->large_stipples = cfg[PREF_STIPPLE_STYLE].u.choices.selected; } static void free_ui(game_ui *ui) diff --git a/net.c b/net.c index 3200253..7b1ec9b 100644 --- a/net.c +++ b/net.c @@ -85,6 +85,11 @@ enum { NCOLOURS }; +enum { + PREF_UNLOCKED_LOOPS, + N_PREF_ITEMS +}; + struct game_params { int width; int height; @@ -2092,22 +2097,23 @@ static config_item *get_prefs(game_ui *ui) { config_item *ret; - ret = snewn(2, config_item); + ret = snewn(N_PREF_ITEMS+1, config_item); - ret[0].name = "Highlight loops involving unlocked squares"; - ret[0].kw = "unlocked-loops"; - ret[0].type = C_BOOLEAN; - ret[0].u.boolean.bval = ui->unlocked_loops; + ret[PREF_UNLOCKED_LOOPS].name = + "Highlight loops involving unlocked squares"; + ret[PREF_UNLOCKED_LOOPS].kw = "unlocked-loops"; + ret[PREF_UNLOCKED_LOOPS].type = C_BOOLEAN; + ret[PREF_UNLOCKED_LOOPS].u.boolean.bval = ui->unlocked_loops; - ret[1].name = NULL; - ret[1].type = C_END; + ret[N_PREF_ITEMS].name = NULL; + ret[N_PREF_ITEMS].type = C_END; return ret; } static void set_prefs(game_ui *ui, const config_item *cfg) { - ui->unlocked_loops = cfg[0].u.boolean.bval; + ui->unlocked_loops = cfg[PREF_UNLOCKED_LOOPS].u.boolean.bval; } static void game_changed_state(game_ui *ui, const game_state *oldstate, diff --git a/palisade.c b/palisade.c index ecbbbb4..34cd3cd 100644 --- a/palisade.c +++ b/palisade.c @@ -43,6 +43,11 @@ static char *string(int n, const char *fmt, ...) return ret; } +enum { + PREF_CURSOR_MODE, + N_PREF_ITEMS +}; + struct game_params { int w, h, k; }; @@ -890,24 +895,24 @@ static config_item *get_prefs(game_ui *ui) { config_item *cfg; - cfg = snewn(2, config_item); + cfg = snewn(N_PREF_ITEMS+1, config_item); - cfg[0].name = "Cursor mode"; - cfg[0].kw = "cursor-mode"; - cfg[0].type = C_CHOICES; - cfg[0].u.choices.choicenames = ":Half-grid:Full-grid"; - cfg[0].u.choices.choicekws = ":half:full"; - cfg[0].u.choices.selected = ui->legacy_cursor; + cfg[PREF_CURSOR_MODE].name = "Cursor mode"; + cfg[PREF_CURSOR_MODE].kw = "cursor-mode"; + cfg[PREF_CURSOR_MODE].type = C_CHOICES; + cfg[PREF_CURSOR_MODE].u.choices.choicenames = ":Half-grid:Full-grid"; + cfg[PREF_CURSOR_MODE].u.choices.choicekws = ":half:full"; + cfg[PREF_CURSOR_MODE].u.choices.selected = ui->legacy_cursor; - cfg[1].name = NULL; - cfg[1].type = C_END; + cfg[N_PREF_ITEMS].name = NULL; + cfg[N_PREF_ITEMS].type = C_END; return cfg; } static void set_prefs(game_ui *ui, const config_item *cfg) { - ui->legacy_cursor = cfg[0].u.choices.selected; + ui->legacy_cursor = cfg[PREF_CURSOR_MODE].u.choices.selected; } static void free_ui(game_ui *ui) diff --git a/pearl.c b/pearl.c index 9599317..a3337d3 100644 --- a/pearl.c +++ b/pearl.c @@ -102,6 +102,11 @@ enum { NCOLOURS }; +enum { + PREF_APPEARANCE, + N_PREF_ITEMS +}; + /* Macro ickery copied from slant.c */ #define DIFFLIST(A) \ A(EASY,Easy,e) \ @@ -1918,24 +1923,24 @@ static config_item *get_prefs(game_ui *ui) { config_item *ret; - ret = snewn(2, config_item); + ret = snewn(N_PREF_ITEMS+1, config_item); - ret[0].name = "Puzzle appearance"; - ret[0].kw = "appearance"; - ret[0].type = C_CHOICES; - ret[0].u.choices.choicenames = ":Traditional:Loopy-style"; - ret[0].u.choices.choicekws = ":traditional:loopy"; - ret[0].u.choices.selected = ui->gui_style; + ret[PREF_APPEARANCE].name = "Puzzle appearance"; + ret[PREF_APPEARANCE].kw = "appearance"; + ret[PREF_APPEARANCE].type = C_CHOICES; + ret[PREF_APPEARANCE].u.choices.choicenames = ":Traditional:Loopy-style"; + ret[PREF_APPEARANCE].u.choices.choicekws = ":traditional:loopy"; + ret[PREF_APPEARANCE].u.choices.selected = ui->gui_style; - ret[1].name = NULL; - ret[1].type = C_END; + ret[N_PREF_ITEMS].name = NULL; + ret[N_PREF_ITEMS].type = C_END; return ret; } static void set_prefs(game_ui *ui, const config_item *cfg) { - ui->gui_style = cfg[0].u.choices.selected; + ui->gui_style = cfg[PREF_APPEARANCE].u.choices.selected; } static void game_changed_state(game_ui *ui, const game_state *oldstate, diff --git a/range.c b/range.c index bc29f76..bc16f59 100644 --- a/range.c +++ b/range.c @@ -96,6 +96,11 @@ struct game_params { puzzle_size h; }; +enum { + PREF_MOUSE_BUTTON_ORDER, + N_PREF_ITEMS +}; + struct game_state { struct game_params params; bool has_cheated, was_solved; @@ -1275,25 +1280,25 @@ static config_item *get_prefs(game_ui *ui) { config_item *ret; - ret = snewn(2, config_item); + ret = snewn(N_PREF_ITEMS+1, config_item); - ret[0].name = "Mouse button order"; - ret[0].kw = "left-mouse-button"; - ret[0].type = C_CHOICES; - ret[0].u.choices.choicenames = + ret[PREF_MOUSE_BUTTON_ORDER].name = "Mouse button order"; + ret[PREF_MOUSE_BUTTON_ORDER].kw = "left-mouse-button"; + ret[PREF_MOUSE_BUTTON_ORDER].type = C_CHOICES; + ret[PREF_MOUSE_BUTTON_ORDER].u.choices.choicenames = ":Left to fill, right to dot:Left to dot, right to fill"; - ret[0].u.choices.choicekws = ":fill:dot"; - ret[0].u.choices.selected = ui->swap_buttons; + ret[PREF_MOUSE_BUTTON_ORDER].u.choices.choicekws = ":fill:dot"; + ret[PREF_MOUSE_BUTTON_ORDER].u.choices.selected = ui->swap_buttons; - ret[1].name = NULL; - ret[1].type = C_END; + ret[N_PREF_ITEMS].name = NULL; + ret[N_PREF_ITEMS].type = C_END; return ret; } static void set_prefs(game_ui *ui, const config_item *cfg) { - ui->swap_buttons = cfg[0].u.choices.selected; + ui->swap_buttons = cfg[PREF_MOUSE_BUTTON_ORDER].u.choices.selected; } static void free_ui(game_ui *ui) diff --git a/signpost.c b/signpost.c index 755599b..1605bda 100644 --- a/signpost.c +++ b/signpost.c @@ -42,6 +42,11 @@ enum { NCOLOURS = COL_B0 + 4*NBACKGROUNDS }; +enum { + PREF_FLASH_TYPE, + N_PREF_ITEMS +}; + struct game_params { int w, h; bool force_corner_start; @@ -1441,24 +1446,25 @@ static config_item *get_prefs(game_ui *ui) { config_item *ret; - ret = snewn(2, config_item); + ret = snewn(N_PREF_ITEMS+1, config_item); - ret[0].name = "Victory rotation effect"; - ret[0].kw = "flash-type"; - ret[0].type = C_CHOICES; - ret[0].u.choices.choicenames = ":Unidirectional:Meshing gears"; - ret[0].u.choices.choicekws = ":unidirectional:gears"; - ret[0].u.choices.selected = ui->gear_mode; + ret[PREF_FLASH_TYPE].name = "Victory rotation effect"; + ret[PREF_FLASH_TYPE].kw = "flash-type"; + ret[PREF_FLASH_TYPE].type = C_CHOICES; + ret[PREF_FLASH_TYPE].u.choices.choicenames = + ":Unidirectional:Meshing gears"; + ret[PREF_FLASH_TYPE].u.choices.choicekws = ":unidirectional:gears"; + ret[PREF_FLASH_TYPE].u.choices.selected = ui->gear_mode; - ret[1].name = NULL; - ret[1].type = C_END; + ret[N_PREF_ITEMS].name = NULL; + ret[N_PREF_ITEMS].type = C_END; return ret; } static void set_prefs(game_ui *ui, const config_item *cfg) { - ui->gear_mode = cfg[0].u.choices.selected; + ui->gear_mode = cfg[PREF_FLASH_TYPE].u.choices.selected; } static void game_changed_state(game_ui *ui, const game_state *oldstate, diff --git a/singles.c b/singles.c index 07db836..be8c0d6 100644 --- a/singles.c +++ b/singles.c @@ -92,6 +92,11 @@ enum { NCOLOURS }; +enum { + PREF_SHOW_BLACK_NUMS, + N_PREF_ITEMS +}; + struct game_params { int w, h, diff; }; @@ -1468,22 +1473,22 @@ static config_item *get_prefs(game_ui *ui) { config_item *ret; - ret = snewn(2, config_item); + ret = snewn(N_PREF_ITEMS+1, config_item); - ret[0].name = "Show numbers on black squares"; - ret[0].kw = "show-black-nums"; - ret[0].type = C_BOOLEAN; - ret[0].u.boolean.bval = ui->show_black_nums; + ret[PREF_SHOW_BLACK_NUMS].name = "Show numbers on black squares"; + ret[PREF_SHOW_BLACK_NUMS].kw = "show-black-nums"; + ret[PREF_SHOW_BLACK_NUMS].type = C_BOOLEAN; + ret[PREF_SHOW_BLACK_NUMS].u.boolean.bval = ui->show_black_nums; - ret[1].name = NULL; - ret[1].type = C_END; + ret[N_PREF_ITEMS].name = NULL; + ret[N_PREF_ITEMS].type = C_END; return ret; } static void set_prefs(game_ui *ui, const config_item *cfg) { - ui->show_black_nums = cfg[0].u.boolean.bval; + ui->show_black_nums = cfg[PREF_SHOW_BLACK_NUMS].u.boolean.bval; } static void free_ui(game_ui *ui) diff --git a/slant.c b/slant.c index bd04b78..54aa419 100644 --- a/slant.c +++ b/slant.c @@ -48,6 +48,11 @@ enum { NCOLOURS }; +enum { + PREF_MOUSE_BUTTON_ORDER, + N_PREF_ITEMS +}; + /* * In standalone solver mode, `verbose' is a variable which can be * set by command-line option; in debugging mode it's simply always @@ -1621,24 +1626,25 @@ static config_item *get_prefs(game_ui *ui) { config_item *ret; - ret = snewn(2, config_item); + ret = snewn(N_PREF_ITEMS+1, config_item); - ret[0].name = "Mouse button order"; - ret[0].kw = "left-button"; - ret[0].type = C_CHOICES; - ret[0].u.choices.choicenames = ":Left \\, right /:Left /, right \\"; - ret[0].u.choices.choicekws = ":\\:/"; - ret[0].u.choices.selected = ui->swap_buttons; + ret[PREF_MOUSE_BUTTON_ORDER].name = "Mouse button order"; + ret[PREF_MOUSE_BUTTON_ORDER].kw = "left-button"; + ret[PREF_MOUSE_BUTTON_ORDER].type = C_CHOICES; + ret[PREF_MOUSE_BUTTON_ORDER].u.choices.choicenames = + ":Left \\, right /:Left /, right \\"; + ret[PREF_MOUSE_BUTTON_ORDER].u.choices.choicekws = ":\\:/"; + ret[PREF_MOUSE_BUTTON_ORDER].u.choices.selected = ui->swap_buttons; - ret[1].name = NULL; - ret[1].type = C_END; + ret[N_PREF_ITEMS].name = NULL; + ret[N_PREF_ITEMS].type = C_END; return ret; } static void set_prefs(game_ui *ui, const config_item *cfg) { - ui->swap_buttons = cfg[0].u.choices.selected; + ui->swap_buttons = cfg[PREF_MOUSE_BUTTON_ORDER].u.choices.selected; } static void free_ui(game_ui *ui) diff --git a/solo.c b/solo.c index 2445501..c93558d 100644 --- a/solo.c +++ b/solo.c @@ -140,6 +140,11 @@ enum { NCOLOURS }; +enum { + PREF_PENCIL_KEEP_HIGHLIGHT, + N_PREF_ITEMS +}; + /* * To determine all possible ways to reach a given sum by adding two or * three numbers from 1..9, each of which occurs exactly once in the sum, @@ -4592,22 +4597,23 @@ static config_item *get_prefs(game_ui *ui) { config_item *ret; - ret = snewn(2, config_item); + ret = snewn(N_PREF_ITEMS+1, config_item); - ret[0].name = "Keep mouse highlight after changing a pencil mark"; - ret[0].kw = "pencil-keep-highlight"; - ret[0].type = C_BOOLEAN; - ret[0].u.boolean.bval = ui->pencil_keep_highlight; + ret[PREF_PENCIL_KEEP_HIGHLIGHT].name = + "Keep mouse highlight after changing a pencil mark"; + ret[PREF_PENCIL_KEEP_HIGHLIGHT].kw = "pencil-keep-highlight"; + ret[PREF_PENCIL_KEEP_HIGHLIGHT].type = C_BOOLEAN; + ret[PREF_PENCIL_KEEP_HIGHLIGHT].u.boolean.bval = ui->pencil_keep_highlight; - ret[1].name = NULL; - ret[1].type = C_END; + ret[N_PREF_ITEMS].name = NULL; + ret[N_PREF_ITEMS].type = C_END; return ret; } static void set_prefs(game_ui *ui, const config_item *cfg) { - ui->pencil_keep_highlight = cfg[0].u.boolean.bval; + ui->pencil_keep_highlight = cfg[PREF_PENCIL_KEEP_HIGHLIGHT].u.boolean.bval; } static void game_changed_state(game_ui *ui, const game_state *oldstate, diff --git a/towers.c b/towers.c index 4dd9484..276cdb3 100644 --- a/towers.c +++ b/towers.c @@ -61,6 +61,12 @@ enum { NCOLOURS }; +enum { + PREF_PENCIL_KEEP_HIGHLIGHT, + PREF_APPEARANCE, + N_PREF_ITEMS +}; + struct game_params { int w, diff; }; @@ -1225,30 +1231,31 @@ static config_item *get_prefs(game_ui *ui) { config_item *ret; - ret = snewn(3, config_item); + ret = snewn(N_PREF_ITEMS+1, config_item); - ret[0].name = "Keep mouse highlight after changing a pencil mark"; - ret[0].kw = "pencil-keep-highlight"; - ret[0].type = C_BOOLEAN; - ret[0].u.boolean.bval = ui->pencil_keep_highlight; + ret[PREF_PENCIL_KEEP_HIGHLIGHT].name = + "Keep mouse highlight after changing a pencil mark"; + ret[PREF_PENCIL_KEEP_HIGHLIGHT].kw = "pencil-keep-highlight"; + ret[PREF_PENCIL_KEEP_HIGHLIGHT].type = C_BOOLEAN; + ret[PREF_PENCIL_KEEP_HIGHLIGHT].u.boolean.bval = ui->pencil_keep_highlight; - ret[1].name = "Puzzle appearance"; - ret[1].kw = "appearance"; - ret[1].type = C_CHOICES; - ret[1].u.choices.choicenames = ":2D:3D"; - ret[1].u.choices.choicekws = ":2d:3d"; - ret[1].u.choices.selected = ui->three_d; + ret[PREF_APPEARANCE].name = "Puzzle appearance"; + ret[PREF_APPEARANCE].kw = "appearance"; + ret[PREF_APPEARANCE].type = C_CHOICES; + ret[PREF_APPEARANCE].u.choices.choicenames = ":2D:3D"; + ret[PREF_APPEARANCE].u.choices.choicekws = ":2d:3d"; + ret[PREF_APPEARANCE].u.choices.selected = ui->three_d; - ret[2].name = NULL; - ret[2].type = C_END; + ret[N_PREF_ITEMS].name = NULL; + ret[N_PREF_ITEMS].type = C_END; return ret; } static void set_prefs(game_ui *ui, const config_item *cfg) { - ui->pencil_keep_highlight = cfg[0].u.boolean.bval; - ui->three_d = cfg[1].u.choices.selected; + ui->pencil_keep_highlight = cfg[PREF_PENCIL_KEEP_HIGHLIGHT].u.boolean.bval; + ui->three_d = cfg[PREF_APPEARANCE].u.choices.selected; } static void game_changed_state(game_ui *ui, const game_state *oldstate, diff --git a/undead.c b/undead.c index 0213d0e..19b0125 100644 --- a/undead.c +++ b/undead.c @@ -57,6 +57,12 @@ enum { NCOLOURS }; +enum { + PREF_PENCIL_KEEP_HIGHLIGHT, + PREF_MONSTERS, + N_PREF_ITEMS +}; + #define DIFFLIST(A) \ A(EASY,Easy,e) \ A(NORMAL,Normal,n) \ @@ -1674,30 +1680,31 @@ static config_item *get_prefs(game_ui *ui) { config_item *ret; - ret = snewn(3, config_item); + ret = snewn(N_PREF_ITEMS+1, config_item); - ret[0].name = "Keep mouse highlight after changing a pencil mark"; - ret[0].kw = "pencil-keep-highlight"; - ret[0].type = C_BOOLEAN; - ret[0].u.boolean.bval = ui->pencil_keep_highlight; + ret[PREF_PENCIL_KEEP_HIGHLIGHT].name = + "Keep mouse highlight after changing a pencil mark"; + ret[PREF_PENCIL_KEEP_HIGHLIGHT].kw = "pencil-keep-highlight"; + ret[PREF_PENCIL_KEEP_HIGHLIGHT].type = C_BOOLEAN; + ret[PREF_PENCIL_KEEP_HIGHLIGHT].u.boolean.bval = ui->pencil_keep_highlight; - ret[1].name = "Monster representation"; - ret[1].kw = "monsters"; - ret[1].type = C_CHOICES; - ret[1].u.choices.choicenames = ":Pictures:Letters"; - ret[1].u.choices.choicekws = ":pictures:letters"; - ret[1].u.choices.selected = ui->ascii; + ret[PREF_MONSTERS].name = "Monster representation"; + ret[PREF_MONSTERS].kw = "monsters"; + ret[PREF_MONSTERS].type = C_CHOICES; + ret[PREF_MONSTERS].u.choices.choicenames = ":Pictures:Letters"; + ret[PREF_MONSTERS].u.choices.choicekws = ":pictures:letters"; + ret[PREF_MONSTERS].u.choices.selected = ui->ascii; - ret[2].name = NULL; - ret[2].type = C_END; + ret[N_PREF_ITEMS].name = NULL; + ret[N_PREF_ITEMS].type = C_END; return ret; } static void set_prefs(game_ui *ui, const config_item *cfg) { - ui->pencil_keep_highlight = cfg[0].u.boolean.bval; - ui->ascii = cfg[1].u.choices.selected; + ui->pencil_keep_highlight = cfg[PREF_PENCIL_KEEP_HIGHLIGHT].u.boolean.bval; + ui->ascii = cfg[PREF_MONSTERS].u.choices.selected; } static void free_ui(game_ui *ui) { diff --git a/unequal.c b/unequal.c index ab32e4a..e8997ec 100644 --- a/unequal.c +++ b/unequal.c @@ -64,6 +64,11 @@ typedef enum { MODE_ADJACENT /* Puzzle indicators are 'adjacent number'. */ } Mode; +enum { + PREF_PENCIL_KEEP_HIGHLIGHT, + N_PREF_ITEMS +}; + struct game_params { int order; /* Size of latin square */ int diff; /* Difficulty */ @@ -1471,22 +1476,23 @@ static config_item *get_prefs(game_ui *ui) { config_item *ret; - ret = snewn(2, config_item); + ret = snewn(N_PREF_ITEMS+1, config_item); - ret[0].name = "Keep mouse highlight after changing a pencil mark"; - ret[0].kw = "pencil-keep-highlight"; - ret[0].type = C_BOOLEAN; - ret[0].u.boolean.bval = ui->pencil_keep_highlight; + ret[PREF_PENCIL_KEEP_HIGHLIGHT].name = + "Keep mouse highlight after changing a pencil mark"; + ret[PREF_PENCIL_KEEP_HIGHLIGHT].kw = "pencil-keep-highlight"; + ret[PREF_PENCIL_KEEP_HIGHLIGHT].type = C_BOOLEAN; + ret[PREF_PENCIL_KEEP_HIGHLIGHT].u.boolean.bval = ui->pencil_keep_highlight; - ret[1].name = NULL; - ret[1].type = C_END; + ret[N_PREF_ITEMS].name = NULL; + ret[N_PREF_ITEMS].type = C_END; return ret; } static void set_prefs(game_ui *ui, const config_item *cfg) { - ui->pencil_keep_highlight = cfg[0].u.boolean.bval; + ui->pencil_keep_highlight = cfg[PREF_PENCIL_KEEP_HIGHLIGHT].u.boolean.bval; } static void game_changed_state(game_ui *ui, const game_state *oldstate, diff --git a/untangle.c b/untangle.c index 8044936..b8763a9 100644 --- a/untangle.c +++ b/untangle.c @@ -69,6 +69,13 @@ enum { NCOLOURS }; +enum { + PREF_SNAP_TO_GRID, + PREF_SHOW_CROSSED_EDGES, + PREF_VERTEX_STYLE, + N_PREF_ITEMS +}; + typedef struct point { /* * Points are stored using rational coordinates, with the same @@ -1193,36 +1200,36 @@ static config_item *get_prefs(game_ui *ui) { config_item *cfg; - cfg = snewn(4, config_item); + cfg = snewn(N_PREF_ITEMS+1, config_item); - cfg[0].name = "Snap points to a grid"; - cfg[0].kw = "snap-to-grid"; - cfg[0].type = C_BOOLEAN; - cfg[0].u.boolean.bval = ui->snap_to_grid; + cfg[PREF_SNAP_TO_GRID].name = "Snap points to a grid"; + cfg[PREF_SNAP_TO_GRID].kw = "snap-to-grid"; + cfg[PREF_SNAP_TO_GRID].type = C_BOOLEAN; + cfg[PREF_SNAP_TO_GRID].u.boolean.bval = ui->snap_to_grid; - cfg[1].name = "Show edges that cross another edge"; - cfg[1].kw = "show-crossed-edges"; - cfg[1].type = C_BOOLEAN; - cfg[1].u.boolean.bval = ui->show_crossed_edges; + cfg[PREF_SHOW_CROSSED_EDGES].name = "Show edges that cross another edge"; + cfg[PREF_SHOW_CROSSED_EDGES].kw = "show-crossed-edges"; + cfg[PREF_SHOW_CROSSED_EDGES].type = C_BOOLEAN; + cfg[PREF_SHOW_CROSSED_EDGES].u.boolean.bval = ui->show_crossed_edges; - cfg[2].name = "Display style for vertices"; - cfg[2].kw = "vertex-style"; - cfg[2].type = C_CHOICES; - cfg[2].u.choices.choicenames = ":Circles:Numbers"; - cfg[2].u.choices.choicekws = ":circle:number"; - cfg[2].u.choices.selected = ui->vertex_numbers; + cfg[PREF_VERTEX_STYLE].name = "Display style for vertices"; + cfg[PREF_VERTEX_STYLE].kw = "vertex-style"; + cfg[PREF_VERTEX_STYLE].type = C_CHOICES; + cfg[PREF_VERTEX_STYLE].u.choices.choicenames = ":Circles:Numbers"; + cfg[PREF_VERTEX_STYLE].u.choices.choicekws = ":circle:number"; + cfg[PREF_VERTEX_STYLE].u.choices.selected = ui->vertex_numbers; - cfg[3].name = NULL; - cfg[3].type = C_END; + cfg[N_PREF_ITEMS].name = NULL; + cfg[N_PREF_ITEMS].type = C_END; return cfg; } static void set_prefs(game_ui *ui, const config_item *cfg) { - ui->snap_to_grid = cfg[0].u.boolean.bval; - ui->show_crossed_edges = cfg[1].u.boolean.bval; - ui->vertex_numbers = cfg[2].u.choices.selected; + ui->snap_to_grid = cfg[PREF_SNAP_TO_GRID].u.boolean.bval; + ui->show_crossed_edges = cfg[PREF_SHOW_CROSSED_EDGES].u.boolean.bval; + ui->vertex_numbers = cfg[PREF_VERTEX_STYLE].u.choices.selected; } static void free_ui(game_ui *ui)