From 978301eab13f6a63b94f116532f94b6adf0a0b67 Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Sat, 16 Sep 2023 10:54:40 +0200 Subject: [PATCH 1/2] feat: allow using `String.prototype.includes` in item effect filters --- src/documents/actor/actor.js | 13 ++++++++++--- src/expression-evaluation/evaluator.ts | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/documents/actor/actor.js b/src/documents/actor/actor.js index ae4c1112..3277c491 100644 --- a/src/documents/actor/actor.js +++ b/src/documents/actor/actor.js @@ -5,7 +5,8 @@ import { DS4 } from "../../config"; import { createCheckRoll } from "../../dice/check-factory"; -import { mathEvaluator } from "../../expression-evaluation/evaluator"; +import { Evaluator } from "../../expression-evaluation/evaluator"; +import { Validator } from "../../expression-evaluation/validator"; import { logger } from "../../utils/logger"; import { getGame } from "../../utils/utils"; import { DS4ActiveEffect } from "../active-effect"; @@ -59,7 +60,7 @@ export class DS4Actor extends Actor { } /** - * The effects that should be applioed to this actor. + * The effects that should be applied to this actor. * @type {import("../active-effect").DS4ActiveEffect[]} * @protected */ @@ -90,7 +91,7 @@ export class DS4Actor extends Actor { if (condition !== undefined && condition !== "") { try { const replacedCondition = DS4Actor.replaceFormulaData(condition, { item, actor: this, effect }); - return replacedCondition !== undefined ? Boolean(mathEvaluator.evaluate(replacedCondition)) : false; + return replacedCondition !== undefined ? Boolean(DS4Actor.evaluator.evaluate(replacedCondition)) : false; } catch (error) { logger.warn(error); return false; @@ -520,6 +521,12 @@ export class DS4Actor extends Actor { rejectClose: false, }); } + + static evaluator = new Evaluator({ + context: Math, + predicate: (identifier) => + Validator.defaultPredicate(identifier) || ["includes", "toLowerCase", "toUpperCase"].includes(identifier), + }); } /** diff --git a/src/expression-evaluation/evaluator.ts b/src/expression-evaluation/evaluator.ts index ffc971ac..2cc9409a 100644 --- a/src/expression-evaluation/evaluator.ts +++ b/src/expression-evaluation/evaluator.ts @@ -19,7 +19,7 @@ export class Evaluator { get: (t, k) => (k === Symbol.unscopables ? undefined : t[k as keyof typeof t]), }); actualPredicate = (identifier: string) => - predicate(identifier) || Object.getOwnPropertyNames(Math).includes(identifier); + predicate(identifier) || Object.getOwnPropertyNames(context).includes(identifier); } this.validator = new Validator(actualPredicate); } -- 2.45.2 From 6f9b98ffc29e3cb2125ffd70503300604aea01f8 Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Sat, 16 Sep 2023 10:54:51 +0200 Subject: [PATCH 2/2] chore: update vscode launch config --- .vscode/launch.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 9371697e..370f6fec 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,12 +5,14 @@ "version": "0.2.0", "configurations": [ { - "type": "pwa-chrome", + "type": "chrome", "request": "launch", "runtimeExecutable": "/usr/bin/chromium", "name": "Launch Chrome against localhost", "url": "http://localhost:30000/game", - "webRoot": "${workspaceFolder}/dist" + "pathMapping": { + "/systems/ds4": "${workspaceFolder}/dist" + } } ] } -- 2.45.2