diff --git a/src/platform/maplibrary.h b/src/platform/maplibrary.h index 120d17e8..72cad596 100644 --- a/src/platform/maplibrary.h +++ b/src/platform/maplibrary.h @@ -34,7 +34,8 @@ typedef enum MAPINFO_NAME, /**< (string) Name of the map. E.g. e1m1 */ MAPINFO_TITLE, /**< (string) Title of the map. E.g. "Abyss of Cake" */ MAPINFO_AUTHOR, /**< (string) Author of the map. E.g. "John Doe" */ - MAPINFO_TYPE /**< (string) Type of map.*/ + MAPINFO_TYPE, /**< (string) Type of map.*/ + MAPINFO_PREVIEW /**< (string) URL to a preview of the map. __NULL__ if not available. Will look for level previews inside levelshots/ and maps/ with any file extensions supported by the engine and whitelisted within the cvar 'r_imageextensions'.*/ } mapType_t; /** Initialize the map library, MapLibrary_GetMapCount() will return the amount of maps available. */ diff --git a/src/platform/maplibrary.qc b/src/platform/maplibrary.qc index a788db2e..dd201fd0 100644 --- a/src/platform/maplibrary.qc +++ b/src/platform/maplibrary.qc @@ -20,6 +20,7 @@ typedef struct string title; string author; string type; + string preview; } mapLibrary_t; mapLibrary_t *g_mapLibrary; @@ -65,6 +66,31 @@ MapLibrary_MapInGameDir(string fileName, string gameDir) return list; } +static string +MapLibrary_FindPreview(string mapFile) +{ + string imageExtensions = strcat(cvar_string("r_imageextensions"), " mat"); + int imageFormats = (int)tokenize(imageExtensions); + string previewFile = ""; + string mapName = substring(mapFile, 0, strlen(mapFile) - 4); + + /* cycle through all possible extensions */ + for (int i = 0; i < imageFormats; i++) { + previewFile = strcat("levelshots/", mapName, ".", argv(i)); + + if (whichpack(previewFile)) { + return previewFile; + } + + previewFile = strcat("maps/", mapName, ".", argv(i)); + if (whichpack(previewFile)) { + return previewFile; + } + } + + return __NULL__; +} + void MapLibrary_Init(void) { @@ -137,6 +163,8 @@ MapLibrary_Init(void) g_mapLibrary[c].title = mapFile; g_mapLibrary[c].author = "Unknown"; g_mapLibrary[c].type = "Unknown"; + g_mapLibrary[c].preview = MapLibrary_FindPreview(mapFile); + c++; } } @@ -172,6 +200,9 @@ MapLibrary_GetInfo(int mapID, mapType_t infoType) case MAPINFO_TYPE: return g_mapLibrary[mapID].type; break; + case MAPINFO_PREVIEW: + return g_mapLibrary[mapID].preview; + break; default: return __NULL__; }