From a4151968232576ae4a88d1df8d16e4b2074161e6 Mon Sep 17 00:00:00 2001 From: ac_stef Date: Fri, 26 Dec 2008 12:59:58 +0000 Subject: [PATCH] fix mapname autocompletion git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@4067 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- config/scripts.cfg | 2 +- source/src/command.cpp | 16 ++++++++++++++-- source/src/worldio.cpp | 15 +++++++-------- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/config/scripts.cfg b/config/scripts.cfg index d76448b1..87c1a57c 100644 --- a/config/scripts.cfg +++ b/config/scripts.cfg @@ -9,7 +9,7 @@ alias editent [ ] // Auto-completions -alias mapcomplete [complete $arg1 "packages/maps" cgz] +alias mapcomplete [complete $arg1 "packages/maps/official packages/maps" cgz] mapcommands = "map tdm coop dm lms ts ctf pf lss osok tosok htf vip tktf ktf" loop i (listlen $mapcommands) [ mapcomplete (at $mapcommands $i) diff --git a/source/src/command.cpp b/source/src/command.cpp index c4bda502..09051c78 100644 --- a/source/src/command.cpp +++ b/source/src/command.cpp @@ -518,10 +518,11 @@ struct completeval { int type; char *dir, *ext; + vector dirlist; vector list; completeval(int type, const char *dir, const char *ext) : type(type), dir(dir && dir[0] ? newstring(dir) : NULL), ext(ext && ext[0] ? newstring(ext) : NULL) {} - ~completeval() { DELETEA(dir); DELETEA(ext); list.deletecontentsa(); } + ~completeval() { DELETEA(dir); DELETEA(ext); dirlist.deletecontentsa(); list.deletecontentsa(); } }; static inline bool htcmp(const completekey &x, const completekey &y) @@ -556,6 +557,17 @@ void addcomplete(char *command, int type, char *dir, char *ext) { completeval *f = new completeval(type, dir, ext); if(type==COMPLETE_LIST) explodelist(dir, f->list); + if(type==COMPLETE_FILE) + { + explodelist(dir, f->dirlist); + loopv(f->dirlist) + { + char *dir = f->dirlist[i]; + int dirlen = (int)strlen(dir); + while(dirlen > 0 && (dir[dirlen-1] == '/' || dir[dirlen-1] == '\\')) + dir[--dirlen] = '\0'; + } + } val = &completedata[completekey(type, f->dir, f->ext)]; *val = f; } @@ -616,7 +628,7 @@ void commandcomplete(char *s) if(init && cdata && cdata->type==COMPLETE_FILE) { cdata->list.deletecontentsa(); - listfiles(cdata->dir, cdata->ext, cdata->list); + loopv(cdata->dirlist) listfiles(cdata->dirlist[i], cdata->ext, cdata->list); } if(*cp == '/' || *cp == ';') diff --git a/source/src/worldio.cpp b/source/src/worldio.cpp index 1c736491..34da1eae 100644 --- a/source/src/worldio.cpp +++ b/source/src/worldio.cpp @@ -268,16 +268,15 @@ int numspawn[3], maploaded = 0, numflagspawn[2]; bool load_world(char *mname) // still supports all map formats that have existed since the earliest cube betas! { int loadmillis = SDL_GetTicks(); - bool isofficial = true; setnames(mname); maploaded = getfilesize(ocgzname); - gzFile f = opengzfile(ocgzname, "rb9"); - if(!f) + if(maploaded > 0) { - maploaded = getfilesize(cgzname); - f = opengzfile(cgzname, "rb9"); - isofficial = false; + s_strcpy(cgzname, ocgzname); + s_strcpy(mcfname, omcfname); } + else maploaded = getfilesize(cgzname); + gzFile f = opengzfile(cgzname, "rb9"); if(!f) { conoutf("\f3could not read map %s", cgzname); return false; } header tmp; memset(&tmp, 0, sizeof(header)); @@ -411,14 +410,14 @@ bool load_world(char *mname) // still supports all map formats that have if(f) gzclose(f); c2skeepalive(); calclight(); - conoutf("read map %s (%d milliseconds)", isofficial ? ocgzname : cgzname, SDL_GetTicks()-loadmillis); + conoutf("read map %s (%d milliseconds)", cgzname, SDL_GetTicks()-loadmillis); conoutf("%s", hdr.maptitle); pushscontext(IEXC_MAPCFG); // untrusted altogether persistidents = false; execfile("config/default_map_settings.cfg"); execfile(pcfname); - execfile(isofficial ? omcfname : mcfname); + execfile(mcfname); persistidents = true; popscontext();