Index: binaries/data/mods/public/maps/random/african_plains.js =================================================================== --- binaries/data/mods/public/maps/random/african_plains.js +++ binaries/data/mods/public/maps/random/african_plains.js @@ -2,12 +2,10 @@ Engine.LoadLibrary("rmgen-common"); Engine.LoadLibrary("rmbiome"); -if (g_MapSettings.Biome) - setSelectedBiome(); -else - setBiome("generic/savanna"); +setSelectedBiome({fallback: "generic/savanna"}); + // Pick some biome defaults and overload a few settings. const tPrimary = g_Terrains.mainTerrain; const tForestFloor = g_Terrains.tier3Terrain; Index: binaries/data/mods/public/maps/random/fields_of_meroe.js =================================================================== --- binaries/data/mods/public/maps/random/fields_of_meroe.js +++ binaries/data/mods/public/maps/random/fields_of_meroe.js @@ -2,10 +2,7 @@ Engine.LoadLibrary("rmgen-common"); Engine.LoadLibrary("rmbiome"); -if (g_MapSettings.Biome) - setSelectedBiome(); -else - setBiome("fields_of_meroe/dry"); +setSelectedBiome({fallback: "fields_of_meroe/dry"}); const tMainDirt = g_Terrains.mainDirt; const tSecondaryDirt = g_Terrains.secondaryDirt; Index: binaries/data/mods/public/maps/random/gulf_of_bothnia.js =================================================================== --- binaries/data/mods/public/maps/random/gulf_of_bothnia.js +++ binaries/data/mods/public/maps/random/gulf_of_bothnia.js @@ -4,11 +4,7 @@ TILE_CENTERED_HEIGHT_MAP = true; -if (g_MapSettings.Biome) - setSelectedBiome(); -else - // TODO: Replace ugly default for atlas by a dropdown - setBiome("gulf_of_bothnia/winter"); +setSelectedBiome({fallback: "gulf_of_bothnia/winter"}); const isLakeFrozen = g_Environment.Water.Frozen; Index: binaries/data/mods/public/maps/random/neareastern_badlands.js =================================================================== --- binaries/data/mods/public/maps/random/neareastern_badlands.js +++ binaries/data/mods/public/maps/random/neareastern_badlands.js @@ -2,10 +2,7 @@ Engine.LoadLibrary("rmgen-common"); Engine.LoadLibrary("rmbiome"); -if (g_MapSettings.Biome) - setSelectedBiome(); -else - setBiome("generic/sahara"); +setSelectedBiome({fallback: "generic/sahara"}); const tPrimary = g_Terrains.mainTerrain; Index: binaries/data/mods/public/maps/random/persian_highlands.js =================================================================== --- binaries/data/mods/public/maps/random/persian_highlands.js +++ binaries/data/mods/public/maps/random/persian_highlands.js @@ -2,11 +2,7 @@ Engine.LoadLibrary("rmgen-common"); Engine.LoadLibrary("rmbiome"); -if (g_MapSettings.Biome) - setSelectedBiome(); -else - // TODO: Replace ugly default for atlas by a dropdown - setBiome("persian_highlands/summer"); +setSelectedBiome({fallback: "persian_highlands/summer"}); const tDirtMain = g_Terrains.mainTerrain; const tCity = g_Terrains.road; Index: binaries/data/mods/public/maps/random/rmbiome/randombiome.js =================================================================== --- binaries/data/mods/public/maps/random/rmbiome/randombiome.js +++ binaries/data/mods/public/maps/random/rmbiome/randombiome.js @@ -11,10 +11,36 @@ return g_BiomeID; } -function setSelectedBiome() +/** + * Get the file path for a biome. + * @param {string} biomeID - The biome ID. + * @returns {string} - The file path (tested for existance). + */ +function getBiomeFilePath(biomeID) { + const path = "maps/random/rmbiome/" + biomeID + ".json"; + if (!Engine.FileExists(path)) + { + error("Could not find biome file '" + biomeID + "'"); + return; + } + return path; +} + +/** + * Sets the selected biome. + * @param {Object} arg - optional argument. + * @param {string} arg.fallback - The ID of the fallback biome. + */ +function setSelectedBiome(arg) +{ // TODO: Replace ugly default for atlas by a dropdown - setBiome(g_MapSettings.Biome || "generic/alpine"); + + const fallback = arg?.fallback || "generic/alpine" + // We don't have an automated way to test maps in atlas, + // so we make sure that the fallback is valid here. + const unread = getBiomeFilePath(fallback); + setBiome(g_MapSettings.Biome || fallback); } function setBiome(biomeID) @@ -42,14 +68,8 @@ */ function loadBiomeFile(file) { - const path = "maps/random/rmbiome/" + file + ".json"; - if (!Engine.FileExists(path)) - { - error("Could not load biome file '" + file + "'"); - return; - } - + const path = getBiomeFilePath(file); const biome = Engine.ReadJSONFile(path); const copyProperties = (from, to) => {