new options for saved.cfg
Defaults to omitting variables from saved.cfg, that are still at default value. By setting omitunchangeddefaults to zero, those variables get written, but commented out. The variable "groupvariables" sets the number of variables with similar names, that can be grouped on one line. Setting it to zero will additionally write min, max and default values and a short description of the variable to file. In general, variables, that are still at default value, will not be restored from saved.cfg, so when the default in the game is changed, all clients will use that new default. This way, testers don't have to erase their saved.cfg as often. DOCREF omitunchangeddefaults groupvariables
This commit is contained in:
@@ -184,4 +184,6 @@ bind SYSREQ []
|
||||
bind BREAK []
|
||||
bind MENU []
|
||||
|
||||
omitunchangeddefaults 1 // switch to a clean saved.cfg when keybinds are reset
|
||||
|
||||
persistidents 1
|
||||
|
||||
+17
-4
@@ -1454,6 +1454,9 @@ COMMANDF(escape, "s", (const char *s) { result(escapestring(s));});
|
||||
|
||||
int sortident(ident **a, ident **b) { return strcasecmp((*a)->name, (*b)->name); }
|
||||
|
||||
VARP(omitunchangeddefaults, 0, 0, 1);
|
||||
VAR(groupvariables, 0, 4, 10);
|
||||
|
||||
void writecfg()
|
||||
{
|
||||
filerotate("config/saved", "cfg", CONFIGROTATEMAX); // keep five old config sets
|
||||
@@ -1476,15 +1479,13 @@ void writecfg()
|
||||
f->printf("// crosshairs and kill messages for each weapon\n\nlooplist [\n");
|
||||
loopi(NUMGUNS) f->printf(" %-7s %-11s %-12s %s\n", gunnames[i], crosshairs[i] && crosshairs[i] != notexture ? behindpath(crosshairs[i]->name) : "\"\"", escapestring(killmessage(i, false)), escapestring(killmessage(i, true)));
|
||||
f->printf("] [ w c f g ] [ loadcrosshair $w $c ; fragmessage $w $f ; gibmessage $w $g ]\n");
|
||||
f->printf("\n\n// client variables\n");
|
||||
f->printf("\n\n// client variables (unchanged default values %s)\n", omitunchangeddefaults ? "omitted" : "commented out");
|
||||
vector<ident *> sids;
|
||||
enumerate(*idents, ident, id,
|
||||
if(id.persist) switch(id.type)
|
||||
{
|
||||
case ID_VAR:
|
||||
if(*id.storage.i == id.defaultval) break;
|
||||
case ID_FVAR:
|
||||
if(id.type == ID_FVAR && *id.storage.f == id.defaultvalf) break;
|
||||
case ID_SVAR:
|
||||
sids.add(&id);
|
||||
break;
|
||||
@@ -1493,17 +1494,29 @@ void writecfg()
|
||||
sids.sort(sortident);
|
||||
const char *rep = "";
|
||||
int repn = 0;
|
||||
bool lastdef = false, curdef;
|
||||
loopv(sids)
|
||||
{
|
||||
ident &id = *sids[i];
|
||||
f->printf("%s", !strncmp(rep, id.name, 3) && ++repn < 4 ? " ; " : (repn = 0, "\n"));
|
||||
curdef = (id.type == ID_VAR && *id.storage.i == id.defaultval) || (id.type == ID_FVAR && *id.storage.f == id.defaultvalf);
|
||||
if(curdef && omitunchangeddefaults) continue;
|
||||
f->printf("%s", !strncmp(rep, id.name, curdef ? 1 : 3) && ++repn < groupvariables && lastdef == curdef ? " ; " : (repn = 0, "\n"));
|
||||
rep = id.name;
|
||||
lastdef = curdef;
|
||||
if(curdef && repn == 0) f->printf("// ");
|
||||
switch(id.type)
|
||||
{
|
||||
case ID_VAR: f->printf("%s %d", id.name, *id.storage.i); break;
|
||||
case ID_FVAR: f->printf("%s %s", id.name, floatstr(*id.storage.f)); break;
|
||||
case ID_SVAR: f->printf("%s %s", id.name, escapestring(*id.storage.s, false)); break;
|
||||
}
|
||||
if(!groupvariables)
|
||||
{
|
||||
if(id.type == ID_VAR) f->printf(" // min: %d, max: %d, def: %d", id.minval, id.maxval, id.defaultval);
|
||||
if(id.type == ID_FVAR) f->printf(" // min: %s, max: %s, def: %s", floatstr(id.minvalf), floatstr(id.maxvalf), floatstr(id.defaultvalf));
|
||||
const char *doc = docgetdesc(id.name);
|
||||
if(doc) f->printf(id.type == ID_SVAR ? " // %s" : ", %s", doc);
|
||||
}
|
||||
}
|
||||
f->printf("\n\n// weapon settings\n\n");
|
||||
loopi(NUMGUNS) if(guns[i].isauto)
|
||||
|
||||
@@ -165,6 +165,12 @@ COMMANDN(docref, adddocref, "ssss");
|
||||
COMMANDN(docexample, adddocexample, "ss");
|
||||
COMMANDN(dockey, adddockey, "sss");
|
||||
|
||||
const char *docgetdesc(const char *name)
|
||||
{
|
||||
docident *id = docidents.access(name);
|
||||
return id ? id->desc : NULL;
|
||||
}
|
||||
|
||||
char *cvecstr(vector<char *> &cvec, const char *substr, int *rline = NULL)
|
||||
{
|
||||
char *r = NULL;
|
||||
|
||||
@@ -786,6 +786,7 @@ extern void toggledoc();
|
||||
extern void scrolldoc(int i);
|
||||
extern int stringsort(const char **a, const char **b);
|
||||
extern int stringsortignorecase(const char **a, const char **b);
|
||||
extern const char *docgetdesc(const char *name);
|
||||
#endif
|
||||
|
||||
// protocol [client and server]
|
||||
|
||||
Reference in New Issue
Block a user