Index: binaries/data/mods/public/gui/gamesetup/gamesetup.js =================================================================== --- binaries/data/mods/public/gui/gamesetup/gamesetup.js +++ binaries/data/mods/public/gui/gamesetup/gamesetup.js @@ -157,7 +157,7 @@ "clientlist": (msg, user) => getUsernameList(), }; -var g_MapFilterList = prepareForDropdown([ +var g_MapFilterList = [ { "id": "default", "name": translateWithContext("map filter", "Default"), @@ -195,7 +195,9 @@ "tooltip": translateWithContext("map filter", "Every map of the chosen maptype."), "filter": mapKeywords => true }, -]); +]; + +var g_MapFilterListFiltered = prepareForDropdown(g_MapFilterList); /** * Whether this is a single- or multiplayer match. @@ -426,20 +428,20 @@ "PlayerData": g_DefaultPlayerData.slice(0, 4) }; - reloadMapList(); + reloadMapFilterList(); }, "autocomplete": true, }, "mapFilter": { "title": () => translate("Map Filter"), - "tooltip": (hoverIdx) => g_MapFilterList.tooltip[hoverIdx] || translate("Select a map filter."), - "labels": () => g_MapFilterList.name, - "ids": () => g_MapFilterList.id, - "default": () => g_MapFilterList.Default, + "tooltip": (hoverIdx) => g_MapFilterListFiltered.tooltip[hoverIdx] || translate("Select a map filter."), + "labels": () => g_MapFilterListFiltered.name, + "ids": () => g_MapFilterListFiltered.id, + "default": () => g_MapFilterListFiltered.Default, "defined": () => g_GameAttributes.mapFilter !== undefined, "get": () => g_GameAttributes.mapFilter, "select": (idx) => { - g_GameAttributes.mapFilter = g_MapFilterList.id[idx]; + g_GameAttributes.mapFilter = g_MapFilterListFiltered.id[idx]; delete g_GameAttributes.map; reloadMapList(); }, @@ -1361,41 +1363,62 @@ } /** - * Initialize the dropdown containing all maps for the selected maptype and mapfilter. + * Returns all maps that match to filter and the set map type. */ -function reloadMapList() +function getFilteredMaps(filter) { if (!g_MapPath[g_GameAttributes.mapType]) { error("Unexpected map type: " + g_GameAttributes.mapType); - return; + return []; } let mapFiles = g_GameAttributes.mapType == "random" ? getJSONFileList(g_GameAttributes.mapPath) : getXMLFileList(g_GameAttributes.mapPath); - // Apply map filter, if any defined - let mapList = []; - + let maps = []; // TODO: Should verify these are valid maps before adding to list for (let mapFile of mapFiles) { let file = g_GameAttributes.mapPath + mapFile; let mapData = loadMapData(file); - let filterID = g_MapFilterList.id.findIndex(id => id == g_GameAttributes.mapFilter); - let mapFilter = g_MapFilterList.filter[filterID] || undefined; - if (!mapData.settings || mapFilter && !mapFilter(mapData.settings.Keywords || [])) + if (!mapData.settings || filter && !filter(mapData.settings.Keywords || [])) continue; - mapList.push({ + maps.push({ "file": file, "name": translate(getMapDisplayName(file)), "color": g_ColorRegular, "description": translate(mapData.settings.Description) }); } + return maps; +} + +/** + * Initialize the dropdown containing all map filters for the selected maptype. + */ +function reloadMapFilterList() +{ + g_MapFilterListFiltered = prepareForDropdown(g_MapFilterList.filter(entry => + getFilteredMaps(entry.filter).length > 0 + )); + + initDropdown("mapFilter"); + reloadMapList(); +} + +/** + * Initialize the dropdown containing all maps for the selected maptype and mapfilter. + */ +function reloadMapList() +{ + // Apply map filter, if any defined + let filterID = g_MapFilterListFiltered.id.findIndex(id => id == g_GameAttributes.mapFilter); + let mapFilter = g_MapFilterListFiltered.filter[filterID]; + let mapList = getFilteredMaps(mapFilter); mapList = mapList.sort(sortNameIgnoreCase); @@ -1475,7 +1498,7 @@ sanitizePlayerData(mapSettings.PlayerData); // Reload, as the maptype or mapfilter might have changed - reloadMapList(); + reloadMapFilterList(); g_GameAttributes.settings.RatingEnabled = Engine.HasXmppClient(); Engine.SetRankedGame(g_GameAttributes.settings.RatingEnabled);