From 521df79f61e30655f950df18fa86d3048fc8ef6a Mon Sep 17 00:00:00 2001
From: MouseOfLight <4144-MouseOfLight@users.noreply.gitgud.io>
Date: Sat, 7 Dec 2019 21:59:17 -0800
Subject: [PATCH] Warning rules assistant

---
 src/js/DefaultRules.js            |  4 ++++
 src/js/rulesAssistantOptions.js   |  8 +++++++-
 src/uncategorized/main.tw         | 15 ++-------------
 src/uncategorized/storyCaption.tw |  2 +-
 4 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/src/js/DefaultRules.js b/src/js/DefaultRules.js
index 2e340cab4cf..a1cc473e971 100644
--- a/src/js/DefaultRules.js
+++ b/src/js/DefaultRules.js
@@ -2937,5 +2937,9 @@ window.DefaultRules = (function() {
 		}
 	}
 
+	let rxCheckEqual = /[^!=<>]=[^=<>]/gi;
+	window.RuleHasError = (rule) => rule.condition.function === "custom"
+	                             && rule.condition.data.match(rxCheckEqual);
+	window.DefaultRulesError = () => V.defaultRules.some(r => RuleHasError(r));
 	return DefaultRules;
 })();
diff --git a/src/js/rulesAssistantOptions.js b/src/js/rulesAssistantOptions.js
index 6c726bb3d8a..0cbedb90a0c 100644
--- a/src/js/rulesAssistantOptions.js
+++ b/src/js/rulesAssistantOptions.js
@@ -1196,9 +1196,15 @@ window.rulesAssistantOptions = (function() {
 		render(data) {
 			const elem = document.createElement("div");
 			const textarea = document.createElement("textarea");
+			const errorMessage = document.createElement("div");
+			$(errorMessage).addClass("yellow");
 			textarea.innerHTML = data;
-			textarea.onblur = () => current_rule.condition.data = textarea.value;
+			let checkRules = () => errorMessage.innerText = RuleHasError(current_rule) ? "WARNING: This rule attempts to set a variable; please ensure any '=' is replaced with '=='" : "";
+			$(textarea).blur(() => current_rule.condition.data = textarea.value);
+			$(textarea).blur(checkRules);
+			checkRules();
 			elem.appendChild(textarea);
+			elem.appendChild(errorMessage);
 			const explanation = document.createElement("div");
 			explanation.innerHTML = "Insert a valid <a target='_blank' class='link-external' href='https://www.w3schools.com/js/js_comparisons.asp'>JavaScript comparison and/or logical operation</a>.";
 			elem.appendChild(explanation);
diff --git a/src/uncategorized/main.tw b/src/uncategorized/main.tw
index aab6e91ab2f..6d4b70e117d 100644
--- a/src/uncategorized/main.tw
+++ b/src/uncategorized/main.tw
@@ -96,17 +96,6 @@
 <</if>>
 <<if ($seeDesk == 1) && ($seeFCNN == 0)>><br><</if>>
 
-/* Check if custom rules have an assignation operator */
-<<set _RL = $defaultRules.length>>
-<<set _regex = /[^!=<>]=[^=<>]/gi>>
-<<set $rulesError = false>>
-<<for _itr = 0; _itr < _RL; _itr++>>
-	<<if $defaultRules[_itr].condition.function == "custom" && $defaultRules[_itr].condition.data.match(_regex)>>
-		<<set $rulesError = true>>
-		<<break>>
-	<</if>>
-<</for>>
-
 __''MAIN MENU''__&nbsp;&nbsp;&nbsp;&nbsp;//[[Summary Options]]//
 <<if $rulesAssistantMain != 0>>
 	| //<span id="RAButton"><<link "Rules Assistant Options" "Rules Assistant">><</link>></span>// @@.cyan;[R]@@
@@ -115,7 +104,7 @@ __''MAIN MENU''__&nbsp;&nbsp;&nbsp;&nbsp;//[[Summary Options]]//
 	<<else>>
 		| //<<link "Stop applying Rules Assistant at week end" "Main">><<set $rulesAssistantAuto = 0>><</link>>//
 	<</if>>
-	| //<<if $rulesError>>@@.yellow; WARNING: some custom rules will change slave variables @@<</if>><<link "Re-apply Rules Assistant now (this will only check slaves in the Penthouse)" "Main">><<for _i = 0;_i < _SL;_i++>><<if $slaves[_i].assignmentVisible == 1 && $slaves[_i].useRulesAssistant == 1>><<= DefaultRules($slaves[_i])>><</if>><</for>><</link>>//
+	| //<<if DefaultRulesError()>>@@.yellow; WARNING: some custom rules will change slave variables @@<</if>><<link "Re-apply Rules Assistant now (this will only check slaves in the Penthouse)" "Main">><<for _i = 0;_i < _SL;_i++>><<if $slaves[_i].assignmentVisible == 1 && $slaves[_i].useRulesAssistant == 1>><<= DefaultRules($slaves[_i])>><</if>><</for>><</link>>//
 <</if>>
 
 <<print App.UI.SlaveList.penthousePage()>>
@@ -203,4 +192,4 @@ __''MAIN MENU''__&nbsp;&nbsp;&nbsp;&nbsp;//[[Summary Options]]//
 <</if>>
 <<if ($debugMode == 1)>>
 	//| [[Show all walk past scenes|Walk Past List]]//
-<</if>>
\ No newline at end of file
+<</if>>
diff --git a/src/uncategorized/storyCaption.tw b/src/uncategorized/storyCaption.tw
index 1cf0d746140..518dde903ca 100644
--- a/src/uncategorized/storyCaption.tw
+++ b/src/uncategorized/storyCaption.tw
@@ -9,7 +9,7 @@
 			<strong> <span id="endWeekButton"> <br><br>
 			<<link "$nextButton">> <<goto $nextLink>> <</link>> @@.cyan;[Ent]@@
 			</span> </strong>
-			<<if $rulesError && $rulesAssistantAuto == 1>>
+			<<if $rulesAssistantAuto == 1 && DefaultRulesError()>>
 				<br>@@.yellow;WARNING: some custom rules will change slave variables@@
 			<</if>>
 		<<else>>
-- 
GitLab