From f88bb49db60a9f94e49d247dac869de70b3752a1 Mon Sep 17 00:00:00 2001
From: ezsh <ezsh.junk@gmail.com>
Date: Wed, 29 May 2019 15:27:39 +0200
Subject: [PATCH] Add RA rule validation function

---
 src/js/datatypeCleanupJS.js | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/src/js/datatypeCleanupJS.js b/src/js/datatypeCleanupJS.js
index a55b7e5c684..4dd22853b89 100644
--- a/src/js/datatypeCleanupJS.js
+++ b/src/js/datatypeCleanupJS.js
@@ -2146,3 +2146,29 @@ App.Entity.Utils.RARuleDatatypeCleanup = function() {
 		set.growth.intensity = Math.clamp(+set.growth.intensity, 0, 1) || 0;
 	}
 }();
+
+App.Entity.Utils.validateRules = function() {
+	/** @type {App.RA.Rule[]} */
+	const rules = State.variables.defaultRules;
+
+	function testObject(o, path) {
+		for (const p in o) {
+			const v = o[p];
+			if (v === undefined) {
+				throw `Property ${path}.${p} is undefined`;
+			}
+			if (v !== null && typeof v === 'object') {
+				testObject(v, path + '.' + p);
+			}
+		}
+	}
+
+	/** @type {App.RA.Rule} */
+	for (const rule of rules) {
+		try {
+			testObject(rule.set, "set");
+		} catch (e) {
+			console.error(`Error in rule ${rule.name}: ${e}`);
+		}
+	}
+};
-- 
GitLab