Changeset 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) | |||||
{ | // When we have looped components.length + 1 times, we are considered stuck. | ||||
// Re-pick if any random setting was unrandomised, | for (let i = 0;i <= components.length; ++i) | ||||
Lint: no-shadow: 'i' is already declared in the upper scope on line 91 column 7. | |||||
Lint: semi-spacing Missing whitespace after semicolon. Lint: semi-spacing: Missing whitespace after semicolon. | |||||
// 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 = rePick || this[comp].pickRandomItems(); | |||||
if (!rePick) | |||||
return; | |||||
} | } | ||||
throw new Error("Infinite loop picking random items detected, components: " + uneval(components)); | |||||
Not Done Inline ActionsFeels 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. 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 |
'i' is already declared in the upper scope on line 91 column 7.