From d9b7e0e1598c431b89c6e1be1478c8cbaaf0243c Mon Sep 17 00:00:00 2001 From: ac-stef Date: Mon, 23 Feb 2015 20:17:43 +0100 Subject: [PATCH] clean up saved.cfg * combine all weapon attributes in a table * sort variables and aliases * group variables * implement curname as SVAR * implement cmdbuf as temporary alias --- source/src/clientgame.cpp | 3 +- source/src/command.cpp | 74 ++++++++++++++++++++++++--------------- source/src/console.cpp | 3 +- 3 files changed, 49 insertions(+), 31 deletions(-) diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index 0d0e5b8e..40453df9 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -169,9 +169,10 @@ void newname(const char *name) addmsg(SV_SWITCHNAME, "rs", player1->name); } else conoutf(_("your name is: %s"), player1->name); - alias("curname", player1->name); } +SVARFF(curname, { curname = exchangestr(curname, player1->name); }, {} ); + int teamatoi(const char *name) { return getlistindex(name, teamnames, true, -1); diff --git a/source/src/command.cpp b/source/src/command.cpp index b1188ca8..38e94a39 100644 --- a/source/src/command.cpp +++ b/source/src/command.cpp @@ -1452,6 +1452,8 @@ const char *escapestring(const char *s, bool force, bool noquotes) } COMMANDF(escape, "s", (const char *s) { result(escapestring(s));}); +int sortident(ident **a, ident **b) { return strcasecmp((*a)->name, (*b)->name); } + void writecfg() { filerotate("config/saved", "cfg", CONFIGROTATEMAX); // keep five old config sets @@ -1460,7 +1462,7 @@ void writecfg() f->printf("// automatically written on exit, DO NOT MODIFY\n// delete this file to have defaults.cfg overwrite these settings\n// modify settings in game, or put settings in autoexec.cfg to override anything\n\n"); f->printf("// basic settings\n\n"); f->printf("name %s\n", escapestring(player1->name, false)); - loopi(CROSSHAIR_NUM) if(crosshairs[i] && crosshairs[i] != notexture) + for(int i = CROSSHAIR_DEFAULT; i < CROSSHAIR_NUM; i++) if(crosshairs[i] && crosshairs[i] != notexture) { f->printf("loadcrosshair %s %s\n", crosshairnames[i], behindpath(crosshairs[i]->name)); } @@ -1471,53 +1473,67 @@ void writecfg() f->printf("\n"); audiomgr.writesoundconfig(f); f->printf("\n"); - f->printf("// kill messages for each weapon\n"); - loopi(NUMGUNS) - { - const char *fragmsg = killmessage(i, false); - const char *gibmsg = killmessage(i, true); - f->printf("\nfragmessage %d [%s]", i, fragmsg); - f->printf("\ngibmessage %d [%s]", i, gibmsg); - } - f->printf("\n\n// client variables\n\n"); + 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"); + vector sids; enumerate(*idents, ident, id, - if(!id.persist) continue; - switch(id.type) + if(id.persist) switch(id.type) { case ID_VAR: - { - if(*id.storage.i != id.defaultval) f->printf("%s %d\n", id.name, *id.storage.i); - break; - } + if(*id.storage.i == id.defaultval) break; case ID_FVAR: - { - if(*id.storage.f != id.defaultvalf) f->printf("%s %s\n", id.name, floatstr(*id.storage.f)); + if(id.type == ID_FVAR && *id.storage.f == id.defaultvalf) break; + case ID_SVAR: + sids.add(&id); break; - } - case ID_SVAR: f->printf("%s %s\n", id.name, escapestring(*id.storage.s, false)); break; } ); - f->printf("\n// weapon settings\n\n"); + sids.sort(sortident); + const char *rep = ""; + int repn = 0; + loopv(sids) + { + ident &id = *sids[i]; + f->printf("%s", !strncmp(rep, id.name, 3) && ++repn < 4 ? " ; " : (repn = 0, "\n")); + rep = id.name; + 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; + } + } + f->printf("\n\n// weapon settings\n\n"); loopi(NUMGUNS) if(guns[i].isauto) { - f->printf("burstshots %d %d\n", i, burstshotssettings[i]); + f->printf("burstshots %s %d\n", gunnames[i], burstshotssettings[i]); } f->printf("\n// key binds\n\n"); writebinds(f); f->printf("\n// aliases\n\n"); - enumerate(*idents, ident, id, - if(id.type==ID_ALIAS && id.persist && id.action[0] && strncmp(id.name, "demodesc_", 9)) + sids.setsize(0); + enumerate(*idents, ident, id, if(id.type==ID_ALIAS && id.persist && id.action[0]) sids.add(&id); ); + sids.sort(sortident); + loopv(sids) + { + ident &id = *sids[i]; + if(strncmp(id.name, "demodesc_", 9)) { f->printf("alias %s %s\n", escapestring(id.name, false), escapestring(id.action, false)); + sids.remove(i--); } - ); - f->printf("\n// demo descriptions\n\n"); - enumerate(*idents, ident, id, - if(id.type==ID_ALIAS && id.persist && id.action[0] && !strncmp(id.name, "demodesc_", 9) && id.action) + } + if(sids.length()) + { + f->printf("\n// demo descriptions\n\n"); + loopv(sids) { + ident &id = *sids[i]; f->printf("alias %s %s\n", escapestring(id.name, false), escapestring(id.action, false)); } - ); + } f->printf("\n"); delete f; } diff --git a/source/src/console.cpp b/source/src/console.cpp index 472aa6be..351c049d 100644 --- a/source/src/console.cpp +++ b/source/src/console.cpp @@ -410,8 +410,9 @@ struct hline pushscontext(IEXC_PROMPT); if(action) { - alias("cmdbuf", buf); + push("cmdbuf", buf); execute(action); + pop("cmdbuf"); } else if(buf[0]=='/') execute(buf+1); else toserver(buf);