Platform: add MAPINFO_PREVIEW query type to MapLibrary_GetInfo() so interfaces can get a proper preview for levels.
This commit is contained in:
parent
e67d1b0da4
commit
801742dd4c
2 changed files with 33 additions and 1 deletions
|
@ -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. */
|
||||
|
|
|
@ -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__;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue