Index: binaries/data/mods/public/gui/gamesettings/GameSettings.js =================================================================== --- binaries/data/mods/public/gui/gamesettings/GameSettings.js +++ binaries/data/mods/public/gui/gamesettings/GameSettings.js @@ -89,19 +89,20 @@ { let components = Object.keys(this); let i = 0; - while (components.length && i < 100) - { - // Re-pick if any random setting was unrandomised, - // to make sure dependencies are cleared. - // TODO: there's probably a better way to handle this. - components = components.filter(comp => this[comp].pickRandomItems ? - !!this[comp].pickRandomItems() : false); - ++i; - } - if (i === 100) + + // When we have looped components.length + 1 times, we are considered stuck. + for (let i = 0;i <= components.length; ++i) { - throw new Error("Infinite loop picking random items, remains : " + uneval(components)); + // Re-pick if any random setting was unrandomised, to make sure dependencies are cleared. + let rePick = false; + for (const comp in this) + if (this[comp].pickRandomItems) + rePick = rePick || this[comp].pickRandomItems(); + if (!rePick) + return; } + + throw new Error("Infinite loop picking random items detected, components: " + uneval(components)); } /** Index: binaries/data/mods/public/gui/gamesettings/attributes/Biome.js =================================================================== --- binaries/data/mods/public/gui/gamesettings/attributes/Biome.js +++ binaries/data/mods/public/gui/gamesettings/attributes/Biome.js @@ -82,11 +82,9 @@ pickRandomItems() { // If the map is random, we need to wait until it selects to know if we need to pick a biome. - if (this.settings.map.map === "random") - return true; - - if (this.biome !== "random") + if (this.settings.map.map === "random" || this.biome !== "random") return false; + this.biome = pickRandom(Array.from(this.available)); return true; } Index: binaries/data/mods/public/gui/gamesettings/attributes/Daytime.js =================================================================== --- binaries/data/mods/public/gui/gamesettings/attributes/Daytime.js +++ binaries/data/mods/public/gui/gamesettings/attributes/Daytime.js @@ -44,11 +44,9 @@ pickRandomItems() { // If the map is random, we need to wait until it is selected. - if (this.settings.map.map === "random") - return true; - - if (this.value !== "random") + if (this.settings.map.map === "random" || this.value !== "random") return false; + this.value = pickRandom(this.data).Id; return true; } Index: binaries/data/mods/public/gui/gamesettings/attributes/Landscape.js =================================================================== --- binaries/data/mods/public/gui/gamesettings/attributes/Landscape.js +++ binaries/data/mods/public/gui/gamesettings/attributes/Landscape.js @@ -57,10 +57,7 @@ pickRandomItems() { // If the map is random, we need to wait until it is selected. - if (this.settings.map.map === "random") - return true; - - if (!this.value || !this.value.startsWith("random")) + if (this.settings.map.map === "random" || !this.value || !this.value.startsWith("random")) return false; let items = []; Index: binaries/data/mods/public/gui/gamesettings/attributes/MatchID.js =================================================================== --- binaries/data/mods/public/gui/gamesettings/attributes/MatchID.js +++ binaries/data/mods/public/gui/gamesettings/attributes/MatchID.js @@ -2,6 +2,7 @@ { init() { + // TODO remove this assignment, this shouldn't be in persistmatchsettings. this.matchID = 0; } @@ -10,14 +11,12 @@ attribs.matchID = this.matchID; } - fromInitAttributes(attribs) - { - if (attribs.matchID !== undefined) - this.matchID = attribs.matchID; - } - pickRandomItems() { + if (this.matchID) + return false; + this.matchID = Engine.GetMatchID(); + return true; } }; Index: binaries/data/mods/public/gui/gamesettings/attributes/Seeds.js =================================================================== --- binaries/data/mods/public/gui/gamesettings/attributes/Seeds.js +++ binaries/data/mods/public/gui/gamesettings/attributes/Seeds.js @@ -2,6 +2,7 @@ { init() { + // TODO remove this assignment, this shouldn't be in persistmatchsettings. this.seed = 0; this.AIseed = 0; } @@ -13,18 +14,12 @@ attribs.settings.AISeed = this.AIseed; } - fromInitAttributes(attribs) - { - // Seed is used for map generation and simulation. - if (this.getLegacySetting(attribs, "Seed") !== undefined) - this.seed = this.getLegacySetting(attribs, "Seed"); - if (this.getLegacySetting(attribs, "AISeed") !== undefined) - this.AIseed = this.getLegacySetting(attribs, "AISeed"); - } - pickRandomItems() { + if (this.seed && this.AIseed) + return false; this.seed = randIntExclusive(0, Math.pow(2, 32)); this.AIseed = randIntExclusive(0, Math.pow(2, 32)); + return true; } }; Index: binaries/data/mods/public/gui/gamesettings/attributes/TeamPlacement.js =================================================================== --- binaries/data/mods/public/gui/gamesettings/attributes/TeamPlacement.js +++ binaries/data/mods/public/gui/gamesettings/attributes/TeamPlacement.js @@ -40,11 +40,9 @@ pickRandomItems() { // If the map is random, we need to wait until it is selected. - if (this.settings.map.map === "random") - return true; - - if (this.value !== "random") + if (this.settings.map.map === "random" || this.value !== "random") return false; + this.value = pickRandom(this.available).Id; return true; }