Index: binaries/data/mods/public/gui/maps/mapbrowser/grid/MapGridBrowser.js =================================================================== --- binaries/data/mods/public/gui/maps/mapbrowser/grid/MapGridBrowser.js +++ binaries/data/mods/public/gui/maps/mapbrowser/grid/MapGridBrowser.js @@ -50,21 +50,28 @@ updateMapList() { - let selectedMap = - this.mapList[this.selected] && - this.mapList[this.selected].file || undefined; + const selectedMap = this.mapList[this.selected]?.file; + const mapType = this.mapBrowserPage.controls.MapFiltering.getSelectedMapType(); + const mapFilter = this.mapBrowserPage.controls.MapFiltering.getSelectedMapFilter(); + const filterText = this.mapBrowserPage.controls.MapFiltering.getSearchText(); + const randomMap = { + "file": "random", + "name": translate("Random"), + "description": translate("Pick a map at random.") + } - let mapList = this.mapFilters.getFilteredMaps( - this.mapBrowserPage.controls.MapFiltering.getSelectedMapType(), - this.mapBrowserPage.controls.MapFiltering.getSelectedMapFilter()); + let mapList = this.mapFilters.getFilteredMaps(mapType, mapFilter); - let filterText = this.mapBrowserPage.controls.MapFiltering.getSearchText(); + if (mapType == "random") + Array.prototype.unshift.apply(mapList, randomMap) + if (filterText) { mapList = MatchSort.get(filterText, mapList, "name"); if (!mapList.length) { - let filter = "all"; + const filter = "all"; + mapList.push(randomMap) for (let type of g_MapTypes.Name) for (let map of this.mapFilters.getFilteredMaps(type, filter)) mapList.push(Object.assign({ "type": type, "filter": filter }, map)); @@ -71,14 +78,7 @@ mapList = MatchSort.get(filterText, mapList, "name"); } } - if (this.mapBrowserPage.controls.MapFiltering.getSelectedMapType() == "random") - { - mapList = [{ - "file": "random", - "name": "Random", - "description": "Pick a map at random.", - }, ...mapList]; - } + this.mapList = mapList; this.itemCount = this.mapList.length; this.resizeGrid();