From 1b2e944754fdee20a27ef4859565d2a69ca19e7e Mon Sep 17 00:00:00 2001 From: ac-stef Date: Sat, 30 May 2015 22:44:52 +0200 Subject: [PATCH] add script commands to support texture and sound config menus textureslotusagelist Return a list of 256 numbers representing the number of uses for every texture slot. If is "onlygeometry", uses as map model skin do not count. If is "onlymodels", the uses in map geometry do not count. gettextureorigin Returns the location where the texture actually can be found. The possibilities are: "official": texture was found in the working directory, which indicates an official texture. "custom": texture was found in the profile directory, which means, the texture is either manually installed or downloaded. "package dir #x": texture was found in a mod directory. "": that. textureslotbyname Returns the list of numbers of all texture slots which use that texture file. edittexturestack Puts a texture slot in a "last used" list up front. The first parameter picks the list, the second parameter is the texture slot number to be used for the next edit getautomapconfig Returns "1" if automapconfig is already enabled, "0" otherwise. getmapsoundorigin Returns the location where the map sound file actually can be found. The possibilities are: "official": the sound file was found in the working directory, which indicates an official mapsound. "custom": the file was found in the profile directory, which means, the mapsound is either manually installed or downloaded. "package dir #x": mapsound was found in a mod directory. "": that. mapsoundslotbyname Returns the list of numbers of all mapsound slots which use that texture file. getmapsoundlist Returns a list of all *.wav and *.ogg files below packages/audio/ambient. DOCREF textureslotusagelist gettextureorigin textureslotbyname DOCREF edittexturestack getautomapconfig DOCREF getmapsoundorigin mapsoundslotbyname getmapsoundlist --- config/scripts.cfg | 1 + source/src/audiomanager.cpp | 50 ++++++++++++++++++++++++++++++++++ source/src/command.cpp | 6 ++--- source/src/editing.cpp | 14 ++++++++++ source/src/texture.cpp | 54 +++++++++++++++++++++++++++++++++++++ source/src/worldio.cpp | 2 ++ 6 files changed, 124 insertions(+), 3 deletions(-) diff --git a/config/scripts.cfg b/config/scripts.cfg index 419623ef..fa196b67 100644 --- a/config/scripts.cfg +++ b/config/scripts.cfg @@ -101,6 +101,7 @@ looplist [ team teamnames addpunct punctuations // the command addpunct actually wants the punctuation name as second argument, but we can't do that. sry. loadcrosshair crosshairnames + edittexturestack texturestacktypes ] [ cmd options ] [ listcomplete $cmd (listoptions $options) ] diff --git a/source/src/audiomanager.cpp b/source/src/audiomanager.cpp index f4bbbd28..fda90f64 100644 --- a/source/src/audiomanager.cpp +++ b/source/src/audiomanager.cpp @@ -905,3 +905,53 @@ void editmapsoundslot(int *n, char *name, char *maxuses) // edit slot parameters } COMMAND(editmapsoundslot, "isssss"); +void getmapsoundorigin(char *fname) +{ + defformatstring(s)("packages/audio/ambience/%s", fname); + findfile(path(s), "r"); + const char *res = s; + switch(findfilelocation) + { + case FFL_WORKDIR: res = fileexists(s, "r") ? "official" : ""; break; + case FFL_HOME: res = "custom"; break; + default: formatstring(s)("package dir #%d", findfilelocation); break; + } + result(res); +} +COMMAND(getmapsoundorigin, "s"); + +void mapsoundslotbyname(char *name) // returns the slot(s) that a certain mapsound file is used in +{ + string res = ""; + loopv(mapconfigdata.mapsoundlines) if(!strcmp(name, mapconfigdata.mapsoundlines[i].name)) concatformatstring(res, "%s%d", *res ? " " : "", i); + result(res); +} +COMMAND(mapsoundslotbyname, "s"); + +void getmapsoundlist() // create a list of mapsound filenames +{ + vector files; + listfilesrecursive("packages/audio/ambience", files); + files.sort(stringsort); + loopvrev(files) if(files.inrange(i + 1) && !strcmp(files[i], files[i + 1])) delstring(files.remove(i + 1)); // remove doubles + int pn = strlen("packages/audio/ambience/"); + vector res; + loopv(files) + { + if(!strncmp(files[i], "packages/audio/ambience/", pn)) + { + const char *s = files[i] + pn; + int sn = strlen(s); + if(sn > 4) + { + const char *e = s + sn - 4; + if(!strcmp(e, ".ogg") || !strcmp(e, ".wav")) cvecprintf(res, "\"%s\"\n", s); + } + } + } + if(res.length()) res.last() = '\0'; + else res.add('\0'); + files.deletearrays(); + result(res.getbuf()); +} +COMMAND(getmapsoundlist, ""); diff --git a/source/src/command.cpp b/source/src/command.cpp index f3857170..fe8fe9db 100644 --- a/source/src/command.cpp +++ b/source/src/command.cpp @@ -1754,9 +1754,9 @@ COMMAND(getscrext, ""); void listoptions(char *s) { - extern const char *menufilesortorders[]; - const char *optionnames[] = { "entities", "ents", "weapons", "teamnames", "teamnames-abbrv", "punctuations", "crosshairnames", "menufilesortorders", "" }; - const char **optionlists[] = { optionnames, entnames + 1, entnames + 1, gunnames, teamnames, teamnames_s, punctnames, crosshairnames, menufilesortorders }; + extern const char *menufilesortorders[], *texturestacktypes[]; + const char *optionnames[] = { "entities", "ents", "weapons", "teamnames", "teamnames-abbrv", "punctuations", "crosshairnames", "menufilesortorders", "texturestacktypes", "" }; + const char **optionlists[] = { optionnames, entnames + 1, entnames + 1, gunnames, teamnames, teamnames_s, punctnames, crosshairnames, menufilesortorders, texturestacktypes }; const char **listp = optionlists[getlistindex(s, optionnames, true, -1) + 1]; commandret = conc(listp, -1, true); } diff --git a/source/src/editing.cpp b/source/src/editing.cpp index eed7afcf..db5ed648 100644 --- a/source/src/editing.cpp +++ b/source/src/editing.cpp @@ -622,6 +622,20 @@ void tofronttex() // maintain most recentl } } +const char *texturestacktypes[] = { "floor", "wall", "ceiling", "" }; + +void edittexturestack(char *what, int *slot) // manually manipulate the "last-used" texture lists to put certain textures up front +{ + tofronttex(); // keep laste edited texture + int n = getlistindex(what, texturestacktypes, true, -1); + if(n >= 0) + { + loopi(256) if(hdr.texlists[n][i] == *slot) curedittex[n] = i; // find stack index of wanted texture slot + } + tofronttex(); +} +COMMAND(edittexturestack, "si"); + void editdrag(bool isdown) { if((dragging = isdown)) diff --git a/source/src/texture.cpp b/source/src/texture.cpp index b15b78c6..2801bcfc 100644 --- a/source/src/texture.cpp +++ b/source/src/texture.cpp @@ -949,6 +949,36 @@ void gettexturelist(char *_filter, char *_exclude, char *_exts) // create a list } COMMAND(gettexturelist, "sss"); +void textureslotusagelist(char *what) +{ + int used[256] = { 0 }; + if(strcmp(what, "onlygeometry")) + { // if not only geometry, cound map model usage + loopv(ents) if(ents[i].type == MAPMODEL) used[ents[i].attr4]++; + used[0] = 0; + } + if(strcmp(what, "onlymodels")) + { // if not only models, count map geometry + sqr *s = world; + loopirev(cubicsize) + { + used[s->wtex]++; + if(s->type != SOLID) + { + used[s->ctex]++; + used[s->ftex]++; + used[s->utex]++; + } + s++; + } + } + vector res; + loopi(256) cvecprintf(res, "%d ", used[i]); + res.last() = '\0'; + result(res.getbuf()); +} +COMMAND(textureslotusagelist, "s"); + bool testworldtexusage(int n) { sqr *s = world; @@ -1036,6 +1066,30 @@ void edittextureslot(int *n, char *scale, char *name) // edit slot parameters != } COMMAND(edittextureslot, "iss"); +void gettextureorigin(char *fname) +{ + defformatstring(s)("packages/textures/%s", fname); + findfile(path(s), "r"); + const char *res = s; + switch(findfilelocation) + { + case FFL_WORKDIR: res = fileexists(s, "r") ? "official" : ""; break; + case FFL_HOME: res = "custom"; break; + default: formatstring(s)("package dir #%d", findfilelocation); break; + } + result(res); +} +COMMAND(gettextureorigin, "s"); + +void textureslotbyname(char *name) // returns the slot(s) that a certain texture file is configured in +{ + string res = ""; + loopv(slots) if(!strcmp(name, slots[i].name)) concatformatstring(res, "%s%d", *res ? " " : "", i); + result(res); +} +COMMAND(textureslotbyname, "s"); + + // helper functions to allow copy&paste between different maps while keeping the proper textures assigned // (pasting will add any missing texture slots) diff --git a/source/src/worldio.cpp b/source/src/worldio.cpp index 47789f53..7158ce3d 100644 --- a/source/src/worldio.cpp +++ b/source/src/worldio.cpp @@ -404,6 +404,8 @@ void automapconfig() } COMMAND(automapconfig, ""); +COMMANDF(getautomapconfig, "", () { intret((hdr.flags & MHF_AUTOMAPCONFIG) != 0); }); + void flagmapconfigchange() { // if changes are tracked, because automapcfg is enabled and the change is not read from a config file -> set unsaved edits flag if(execcontext != IEXC_MAPCFG && hdr.flags & MHF_AUTOMAPCONFIG) unsavededits++;