omit unchanged default binds from saved.cfg

omitunchangeddefaultbinds n

  0 print
  1 print, but commented out
  2 omit

The new var _defaultbinds is used to mark default binds in resetbinds.cfg.

DOCREF omitunchangeddefaultbinds
This commit is contained in:
ac-stef
2016-08-26 14:31:33 +02:00
parent daae49273d
commit dbfdb5927b
3 changed files with 19 additions and 7 deletions
+4
View File
@@ -31,6 +31,8 @@ alias key_commandline [ saycommand / ]
alias key_prevweapon [ weapon (prevweapon) ]
alias key_editmeta2 [ editmeta2down = 1 ; onrelease [ editmeta2down = 0 ] ]
_defaultbinds 1 // do not save the following binds to saved.cfg
bind MOUSE1 attack
bind MOUSE2 altaction
editbind MOUSE2 [ showmenu editing ]
@@ -226,6 +228,8 @@ bind SYSREQ []
bind BREAK []
bind MENU []
_defaultbinds 0
omitunchangeddefaults 1 // switch to a clean saved.cfg when keybinds are reset
persistidents 1
+13 -5
View File
@@ -211,12 +211,17 @@ COMMAND(findkeycode, "s");
keym *keypressed = NULL;
char *keyaction = NULL;
VAR(_defaultbinds, 0, 0, 1);
bool bindkey(keym *km, const char *action, int type)
{
if(!km) return false;
if(type < keym::ACTION_DEFAULT || type >= keym::NUMACTIONS) { conoutf("invalid bind type \"%i\"", type); return false; }
if(!keypressed || keyaction!=km->actions[type]) delete[] km->actions[type];
km->actions[type] = newstring(action);
if(!km || type < keym::ACTION_DEFAULT || type >= keym::NUMACTIONS) return false;
if(strcmp(action, km->actions[type]))
{
if(!keypressed || keyaction!=km->actions[type]) delete[] km->actions[type];
km->actions[type] = newstring(action);
km->unchangeddefault[type] = _defaultbinds != 0;
}
return true;
}
@@ -601,12 +606,15 @@ char *getcurcommand()
return saycommandon ? cmdline.buf : NULL;
}
VARP(omitunchangeddefaultbinds, 0, 1, 2);
void writebinds(stream *f)
{
loopv(keyms)
{
keym *km = &keyms[i];
loopj(3) if(*km->actions[j]) f->printf("%s \"%s\" %s\n", keycmd(j), km->name, escapestring(km->actions[j]));
loopj(3) if(*km->actions[j] && (!km->unchangeddefault[j] || omitunchangeddefaultbinds < 2))
f->printf("%s%s \"%s\" %s\n", km->unchangeddefault[j] && omitunchangeddefaultbinds ? "//" : "", keycmd(j), km->name, escapestring(km->actions[j]));
}
}
+2 -2
View File
@@ -148,9 +148,9 @@ struct keym
};
char *name, *actions[NUMACTIONS];
bool pressed;
bool pressed, unchangeddefault[NUMACTIONS];
keym() : code(-1), name(NULL), pressed(false) { loopi(NUMACTIONS) actions[i] = newstring(""); }
keym() : code(-1), name(NULL), pressed(false) { loopi(NUMACTIONS) { actions[i] = newstring(""); unchangeddefault[i] = false; } }
~keym() { DELETEA(name); loopi(NUMACTIONS) DELETEA(actions[i]); }
};