diff --git a/js/rulesAssistant/conditionEditor.js b/js/rulesAssistant/conditionEditor.js index 88a6ac2ba08643609311ea0a8be4656789d9a5ac..e6f4ec6be0004e6857e6223bd5ec849d95752fb4 100644 --- a/js/rulesAssistant/conditionEditor.js +++ b/js/rulesAssistant/conditionEditor.js @@ -533,9 +533,9 @@ App.RA.Activation.Editor = (function() { } /** - * @typedef {"sub" | "div" | "eq" | "neq" | "gt" | "gte" | "lt" | "lte"| "substr"} RulePairComparators + * @typedef {"sub" | "div" | "eq" | "neq" | "gt" | "gte" | "lt" | "lte"| "substr" | "match"} RulePairComparators * @typedef {object} RulePairComparatorDisplay - * @property {string} key + * @property {RulePairComparators} key * @property {string} name * @type {RulePairComparatorDisplay[]} */ @@ -549,6 +549,7 @@ App.RA.Activation.Editor = (function() { {key: "sub", name: "-"}, {key: "div", name: "/"}, {key: "substr", name: "Contains"}, + {key: "match", name: "Matches"}, ]; class RulePair extends RuleContainer { @@ -604,7 +605,7 @@ App.RA.Activation.Editor = (function() { errorList.push("Both sides need to return the same type."); return "error"; } - } else if (this.mode === "substr") { + } else if (this.mode === "substr" || this.mode === "match") { if (this._child1.validate(errorList) === "string" && this._child2.validate(errorList) === "string") { return "number"; } else { @@ -1123,7 +1124,7 @@ App.RA.Activation.Editor = (function() { } /** - * @param {"sub" | "div" | "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "substr"} mode + * @param {"sub" | "div" | "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "substr" | "match"} mode */ function makePair(mode) { const pair = new RulePair(mode); @@ -1162,6 +1163,7 @@ App.RA.Activation.Editor = (function() { ["lt", () => makePair("lt")], ["lte", () => makePair("lte")], ["substr", () => makePair("substr")], + ["match", () => makePair("match")], ["not", () => { const negate = new RuleNegate(); negate.child = stack.popRulePart(); diff --git a/js/rulesAssistant/conditionEvaluation.js b/js/rulesAssistant/conditionEvaluation.js index 66f423c03cc57aa4aaaddae87759c228cdd7688f..e3c50573c7529e77a4f7cab7d70c471bd788ca74 100644 --- a/js/rulesAssistant/conditionEvaluation.js +++ b/js/rulesAssistant/conditionEvaluation.js @@ -763,6 +763,10 @@ App.RA.Activation.evaluate = function(slave, rule) { const value = stack.popString(); stack.pushBoolean(stack.popString().includes(value)); }], + ["match", () => { + const value = stack.popString(); + stack.pushBoolean(stack.popString().match(value) !== null); + }], ["not", () => stack.pushBoolean(stack.popNumber() === 0)], ["ternarystr", () => { const ifFalse = stack.popString(); diff --git a/src/gui/Encyclopedia/encyclopediaRAActivationEditor.js b/src/gui/Encyclopedia/encyclopediaRAActivationEditor.js index 5fa62bc7cac8f4e6b6381f63d5ccd45a69fa8c02..6347e8031d5b2a1d93336bb8f52cdd6c80913738 100644 --- a/src/gui/Encyclopedia/encyclopediaRAActivationEditor.js +++ b/src/gui/Encyclopedia/encyclopediaRAActivationEditor.js @@ -68,6 +68,8 @@ App.Encyclopedia.addArticle("RA Condition Editor", function() { transformerRow(el, "/", "Divides the second value by the first value", "Number"); transformerRow(el, "Contains", "True, if the second value is somewhere in the first value", "String"); + transformerRow(el, "Matches", "True, if the first value matches the regular expression in the second value", + "String"); transformerRow(el, "Not …", "Negates the input value.", "Boolean"); transformerRow(el, "If … Then … Else …", "If the first value is true, returns the second value, otherwise the third value. The second " +