Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/gamesettings/GameSettings.js
Show First 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | class GameSettings | ||||
/** | /** | ||||
* Change "random" settings into their proper settings. | * Change "random" settings into their proper settings. | ||||
*/ | */ | ||||
pickRandomItems() | pickRandomItems() | ||||
{ | { | ||||
let components = Object.keys(this); | let components = Object.keys(this); | ||||
let i = 0; | let i = 0; | ||||
while (components.length && i < 100) | // Re-pick if any random setting was unrandomised, to make sure dependencies are cleared. | ||||
{ | let pickedThisLoop = true; | ||||
// Re-pick if any random setting was unrandomised, | while (pickedThisLoop && i <= components.length) | ||||
// to make sure dependencies are cleared. | { | ||||
// TODO: there's probably a better way to handle this. | pickedThisLoop = false; | ||||
components = components.filter(comp => this[comp].pickRandomItems ? | let allHaveValue = true; | ||||
!!this[comp].pickRandomItems() : false); | for (const comp in this) | ||||
++i; | if (this[comp].pickRandomItems) | ||||
{ | |||||
const result = this[comp].pickRandomItems(); | |||||
pickedThisLoop = pickedThisLoop || result.picked; | |||||
allHaveValue = allHaveValue && result.hasValue; | |||||
} | } | ||||
if (i === 100) | if (allHaveValue) | ||||
{ | return; | ||||
throw new Error("Infinite loop picking random items, remains : " + uneval(components)); | ++i; | ||||
} | } | ||||
throw new Error("Possible infinite loop picking random items, remains : " + uneval(components.filter(comp => this[comp].pickRandomItems && !this[comp].pickRandomItems().hasValue))); | |||||
wraitii: Feels like the message is incorrect now, because you can only end up here if you haven't picked… | |||||
Done Inline ActionsThere is another way to get here: Maybe we shouldn't filter only the hasValue components, print all of them. bb: There is another way to get here:
Since we don't know the dependencies, anything can happen. | |||||
} | } | ||||
/** | /** | ||||
* Start the game & switch to the loading page. | * Start the game & switch to the loading page. | ||||
* This is here because there's limited value in having a separate folder/file for it, | * This is here because there's limited value in having a separate folder/file for it, | ||||
* since you'll need a GameSettings object anyways. | * since you'll need a GameSettings object anyways. | ||||
* @param playerAssignments - A dict of 'local'/GUID per player and their name/slot. | * @param playerAssignments - A dict of 'local'/GUID per player and their name/slot. | ||||
*/ | */ | ||||
Show All 24 Lines |
Wildfire Games · Phabricator
Feels like the message is incorrect now, because you can only end up here if you haven't picked this loop but there remains components if I'm reading this correctly. So the error is actually that some "random" value was incorrectly not unrandomised and/or returned incorrect values.