Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/gamesettings/GameSettings.js
Show First 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | for (let comp in this) | ||||
this[comp].fromInitAttributes(attribs); | this[comp].fromInitAttributes(attribs); | ||||
} | } | ||||
/** | /** | ||||
* Change "random" settings into their proper settings. | * Change "random" settings into their proper settings. | ||||
*/ | */ | ||||
pickRandomItems() | pickRandomItems() | ||||
{ | { | ||||
let components = Object.keys(this); | const components = Object.keys(this); | ||||
let i = 0; | |||||
while (components.length && i < 100) | // When we have looped components.length + 1 times, we are considered stuck. | ||||
{ | for (let i = 0; i <= components.length; ++i) | ||||
// 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) | |||||
{ | { | ||||
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 = this[comp].pickRandomItems() || rePick; | |||||
if (!rePick) | |||||
return; | |||||
} | } | ||||
throw new Error("Infinite loop picking random items detected, components: " + uneval(components)); | |||||
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.