mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-22 16:32:13 -07:00
Use a proper union in struct config_item.
This allows me to use different types for the mutable, dynamically allocated string value in a C_STRING control and the fixed constant list of option names in a C_CHOICES.
This commit is contained in:
@ -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,9 +233,9 @@ 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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user