mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-20 23:51:29 -07:00
Move per-puzzle ad-hoc getenv preferences into game_ui.
Environment variables that set specific settings of particular puzzles, such as SLANT_SWAP_BUTTONS, LIGHTUP_LIT_BLOBS and LOOPY_AUTOFOLLOW, now all affect the game behaviour via fields in game_ui instead of being looked up by getenv in the individual functions that need to know them. The purpose of this refactoring is to put those config fields in a place where other more user-friendly configuration systems will also be able to access them, once I introduce one. However, for the moment, there's no functional change: I haven't _yet_ changed how the user sets those options. They're still set by environment variables alone. All I'm changing here is where the settings are stored inside the code, and exactly when they're read out of the environment to put into the game_ui. Specifically, the getenvs now happen during new_ui(). Or rather, in all the puzzles I've changed here, they happen in a subroutine legacy_prefs_override() called from within new_ui(), after it's set up the default values for the settings, and then gives the environment a chance to override them. Or rather, legacy_prefs_override() only actually calls getenv the first time, and after that, it's cached the answers it got. In order to make the override functions less wordy, I've altered the prototype of getenv_bool so that it returns an int rather than a bool, and takes its default return value in the same form. That way you can set the default to something other than 0 or 1, and find out whether a value was present at all. This commit only touches environment configuration specific to an individual puzzle. The midend also has some standard environment-based config options that apply to all puzzles, such as colour scheme and default presets and preset-menu extension. I haven't handled those yet.
This commit is contained in:
48
signpost.c
48
signpost.c
@ -1387,8 +1387,32 @@ struct game_ui {
|
||||
bool dragging, drag_is_from;
|
||||
int sx, sy; /* grid coords of start cell */
|
||||
int dx, dy; /* pixel coords of drag posn */
|
||||
|
||||
/*
|
||||
* Trivial and foolish configurable option done on purest whim.
|
||||
* With this option enabled, the victory flash is done by rotating
|
||||
* each square in the opposite direction from its immediate
|
||||
* neighbours, so that they behave like a field of interlocking
|
||||
* gears. With it disabled, they all rotate in the same direction.
|
||||
* Choose for yourself which is more brain-twisting :-)
|
||||
*/
|
||||
bool gear_mode;
|
||||
};
|
||||
|
||||
static void legacy_prefs_override(struct game_ui *ui_out)
|
||||
{
|
||||
static bool initialised = false;
|
||||
static int gear_mode = -1;
|
||||
|
||||
if (!initialised) {
|
||||
initialised = true;
|
||||
gear_mode = getenv_bool("SIGNPOST_GEARS", -1);
|
||||
}
|
||||
|
||||
if (gear_mode != -1)
|
||||
ui_out->gear_mode = gear_mode;
|
||||
}
|
||||
|
||||
static game_ui *new_ui(const game_state *state)
|
||||
{
|
||||
game_ui *ui = snew(game_ui);
|
||||
@ -1402,6 +1426,9 @@ static game_ui *new_ui(const game_state *state)
|
||||
ui->dragging = false;
|
||||
ui->sx = ui->sy = ui->dx = ui->dy = 0;
|
||||
|
||||
ui->gear_mode = false;
|
||||
legacy_prefs_override(ui);
|
||||
|
||||
return ui;
|
||||
}
|
||||
|
||||
@ -2143,26 +2170,7 @@ static void game_redraw(drawing *dr, game_drawstate *ds,
|
||||
if (state->nums[i] != ds->nums[i] ||
|
||||
f != ds->f[i] || dirp != ds->dirp[i] ||
|
||||
force || !ds->started) {
|
||||
int sign;
|
||||
{
|
||||
/*
|
||||
* Trivial and foolish configurable option done on
|
||||
* purest whim. With this option enabled, the
|
||||
* victory flash is done by rotating each square
|
||||
* in the opposite direction from its immediate
|
||||
* neighbours, so that they behave like a field of
|
||||
* interlocking gears. With it disabled, they all
|
||||
* rotate in the same direction. Choose for
|
||||
* yourself which is more brain-twisting :-)
|
||||
*/
|
||||
static int gear_mode = -1;
|
||||
if (gear_mode < 0)
|
||||
gear_mode = getenv_bool("SIGNPOST_GEARS", false);
|
||||
if (gear_mode)
|
||||
sign = 1 - 2 * ((x ^ y) & 1);
|
||||
else
|
||||
sign = 1;
|
||||
}
|
||||
int sign = (ui->gear_mode ? 1 - 2 * ((x ^ y) & 1) : 1);
|
||||
tile_redraw(dr, ds,
|
||||
BORDER + x * TILE_SIZE,
|
||||
BORDER + y * TILE_SIZE,
|
||||
|
Reference in New Issue
Block a user