diff --git a/src/js/consistencyCheck.js b/src/js/consistencyCheck.js new file mode 100644 index 0000000000000000000000000000000000000000..cd7272a00161f024b71427f148d254d1d52dadfa --- /dev/null +++ b/src/js/consistencyCheck.js @@ -0,0 +1,31 @@ +/* checks V.slaves for consistency */ +$(document).on(":passagestart", event => { + if (event.passage.title !== "AS Dump" // Don't put in the work on passages we leave immediately anyway. + && V.slaves !== undefined) { // no V.slaves at game start + if (V.slaves.includes(null)) { + const p = document.createElement("p"); + p.append(App.UI.DOM.makeElement("span", "ERROR: Main slaves array contains a null entry! Please report this. ", "error"), + // we can't reload the passage as we could be on a passage that changes the game state. + App.UI.DOM.link("Fix for next passage.", () => { V.slaves.delete(null); })); + event.content.append(p); + } else { + // This part would break with a null entry. + _(V.slaves).countBy(s => s.ID) + .pickBy(count => count > 1) + .keys() + .map(id => Number(id)) + .value() + .forEach(id => { + event.content.append(App.UI.DOM.makeElement("p", `Duplicate slave ID ${id} at indices ${ + _(V.slaves) + .map((s, idx) => ({ + ID: s.ID, idx: idx, name: s.slaveName, assignment: s.assignment + })) + .filter(s => s.ID === id) + .map(s => s.idx + ': ' + s.name + ' (' + s.assignment + ')') + .join(', ') + }`, "error")); + }); + } + } +}); diff --git a/src/uncategorized/main.tw b/src/uncategorized/main.tw index 236a9236733d5aa8efc8100fa12877e2b547fee5..a004be2826f22b053e74255408152f3fcde1e98e 100644 --- a/src/uncategorized/main.tw +++ b/src/uncategorized/main.tw @@ -16,9 +16,6 @@ <</if>> /* extra sanity checks and repair */ -<<if $slaves.includes(null)>> - <br><br>@@.red;ERROR: Main slaves array contains a null entry! Please report this.@@ <<link "Repair">><<set $slaves.delete(null)>><</link>><<goto "Main">><br><br> -<</if>> <span id="NaNArray"> <<if $NaNArray.length > 0>> <br><br>@@.red; ERROR: The following variables are NaN! Please report this.@@<br> @@ -36,13 +33,6 @@ <br><br>@@.red;ERROR: Your husk slave order has taken on a mutated life of its own and has been summarily shot. Refile your husk slave order, if necessary, and notify the appropriate authorities if you see this message again.@@<br><br> <<set $huskSlave = new App.Entity.CustomSlaveOrder()>> <</if>> - -<<set _duplicateSlaves = _($slaves).countBy(s => s.ID).pickBy(v => v > 1).keys().map(v => Number(v)).value()>> -<<for _i range _duplicateSlaves>> - <br><br>@@.red;Duplicate slave ID _i at indices - <<= _($slaves).map((s, idx) => ({ID: s.ID, idx: idx, name: s.slaveName, assignment: s.assignment})).filter(s => s.ID === _i).map(s => s.idx + ' - ' + s.name + ' (' + s.assignment + ')').join(', ')>>@@ -<</for>> - /* end extra sanity checks and repair */