From 22165bdf50ce3caaaa26219877ef00bd5a779165 Mon Sep 17 00:00:00 2001
From: Arkerthan <arkerthan@gmail.com>
Date: Sat, 26 Dec 2020 00:43:36 +0100
Subject: [PATCH] call slaves array consistency check from
 setupEventHandlers.js

---
 src/js/consistencyCheck.js         | 12 ++++++++----
 src/zz1-last/setupEventHandlers.js | 17 +++++++++++------
 2 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/src/js/consistencyCheck.js b/src/js/consistencyCheck.js
index bdb26b021b6..d15dd310ff3 100644
--- a/src/js/consistencyCheck.js
+++ b/src/js/consistencyCheck.js
@@ -1,7 +1,11 @@
-/* checks V.slaves for consistency */
-$(document).on(":passagestart", event => {
+/**
+ * checks V.slaves for consistency
+ * @param {PassageRenderingEvent} event
+ */
+App.Debug.slavesConsistency = function(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"),
@@ -23,9 +27,9 @@ $(document).on(":passagestart", event => {
 							}))
 							.filter(s => s.ID === id)
 							.map(s => `${s.idx}: ${s.name} (${s.assignment})`)
-							.join(', ')
+							.join(", ")
 					}`, "error"));
 				});
 		}
 	}
-});
+};
diff --git a/src/zz1-last/setupEventHandlers.js b/src/zz1-last/setupEventHandlers.js
index 50c38e67457..bbe69053495 100644
--- a/src/zz1-last/setupEventHandlers.js
+++ b/src/zz1-last/setupEventHandlers.js
@@ -2,15 +2,14 @@
 Config.saves.onLoad = App.EventHandlers.onLoad;
 Config.saves.onSave = App.EventHandlers.onSave;
 
-$(document).on(':storyready', function() {
-	App.EventHandlers.storyReady();
-});
+/* ### Every-time listeners #### */
 
-$(document).one(':passagestart', function() {
-	App.EventHandlers.optionsChanged();
+$(document).on(":storyready", () => {
+	App.EventHandlers.storyReady();
 });
 
-$(document).on(':passagestart', function() {
+$(document).on(":passagestart", event => {
+	App.Debug.slavesConsistency(event);
 	Object.defineProperty(State.temporary, "S", {
 		get: () => S,
 		enumerable: true
@@ -23,3 +22,9 @@ $(document).on(":passageinit", () => {
 		delete V.passageSwitchHandler;
 	}
 });
+
+/* ### One-time listeners ### */
+
+$(document).one(":passagestart", () => {
+	App.EventHandlers.optionsChanged();
+});
-- 
GitLab