Compare commits

..

1 commit
main ... bun

Author SHA1 Message Date
91b222a14e
chore: switch to bun as package manager and test runner
Some checks failed
ci/woodpecker/pr/checks Pipeline failed
2023-07-22 03:04:04 +02:00
33 changed files with 159 additions and 5480 deletions

2
.gitignore vendored
View file

@ -28,5 +28,3 @@ junit.xml
# foundry # foundry
/client /client
/common /common
.pnpm-store/

View file

@ -8,4 +8,3 @@
/.vscode/ /.vscode/
client client
common common
pnpm-lock.yaml

6
.vscode/launch.json vendored
View file

@ -5,14 +5,12 @@
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
"type": "chrome", "type": "pwa-chrome",
"request": "launch", "request": "launch",
"runtimeExecutable": "/usr/bin/chromium", "runtimeExecutable": "/usr/bin/chromium",
"name": "Launch Chrome against localhost", "name": "Launch Chrome against localhost",
"url": "http://localhost:30000/game", "url": "http://localhost:30000/game",
"pathMapping": { "webRoot": "${workspaceFolder}/dist"
"/systems/ds4": "${workspaceFolder}/dist"
}
} }
] ]
} }

View file

@ -5,10 +5,7 @@
$schema: https://raw.githubusercontent.com/woodpecker-ci/woodpecker/master/pipeline/schema/schema.json $schema: https://raw.githubusercontent.com/woodpecker-ci/woodpecker/master/pipeline/schema/schema.json
variables: variables:
- &node_image node:lts - &bun_image oven/bun:latest
- &enable_pnpm
- corepack enable
- corepack prepare pnpm@latest --activate
when: when:
- event: push - event: push
@ -19,34 +16,29 @@ when:
steps: steps:
install: install:
image: *node_image image: *bun_image
commands: commands:
- <<: *enable_pnpm - bun install --frozen-lockfile
- pnpm install --frozen-lockfile
lint: lint:
group: check group: check
image: *node_image image: *bun_image
commands: commands:
- <<: *enable_pnpm - bun run lint
- pnpm lint
formatcheck: formatcheck:
group: check group: check
image: *node_image image: *bun_image
commands: commands:
- <<: *enable_pnpm - bun run format:check
- pnpm format:check
typecheck: typecheck:
group: check group: check
image: *node_image image: *bun_image
commands: commands:
- <<: *enable_pnpm - bun run typecheck
- pnpm typecheck
test: test:
group: check group: check
image: *node_image image: *bun_image
commands: commands:
- <<: *enable_pnpm - bun run test
- pnpm test
reuse: reuse:
group: check group: check
image: fsfe/reuse:latest image: fsfe/reuse:latest
@ -54,17 +46,17 @@ steps:
- reuse lint - reuse lint
commitlint: commitlint:
group: check group: check
image: *node_image image: *bun_image
commands: commands:
- <<: *enable_pnpm - apt-get update
- apt-get install git -y
- git fetch origin ${CI_COMMIT_TARGET_BRANCH} - git fetch origin ${CI_COMMIT_TARGET_BRANCH}
- pnpm exec commitlint --from origin/${CI_COMMIT_TARGET_BRANCH} - bunx commitlint --from origin/${CI_COMMIT_TARGET_BRANCH}
when: when:
event: pull_request event: pull_request
build: build:
group: build group: build
image: *node_image image: *bun_image
commands: commands:
- export APPDATA=$(pwd) - export APPDATA=$(pwd)
- <<: *enable_pnpm - bun run build
- pnpm build

View file

@ -5,10 +5,7 @@
$schema: https://raw.githubusercontent.com/woodpecker-ci/woodpecker/master/pipeline/schema/schema.json $schema: https://raw.githubusercontent.com/woodpecker-ci/woodpecker/master/pipeline/schema/schema.json
variables: variables:
- &node_image node:lts - &bun_image oven/bun:latest
- &enable_pnpm
- corepack enable
- corepack prepare pnpm@latest --activate
- &is_latest_channel - &is_latest_channel
evaluate: CI_COMMIT_TAG matches "^[0-9]+\\\\.[0-9]+\\\\.[0-9]+$" evaluate: CI_COMMIT_TAG matches "^[0-9]+\\\\.[0-9]+\\\\.[0-9]+$"
- &is_beta_channel - &is_beta_channel
@ -33,18 +30,16 @@ depends_on:
steps: steps:
install: install:
image: *node_image image: *bun_image
commands: commands:
- <<: *enable_pnpm - bun install --frozen-lockfile
- pnpm install --frozen-lockfile
build: build:
image: *node_image image: *bun_image
environment: environment:
NODE_ENV: production NODE_ENV: production
commands: commands:
- export APPDATA=$(pwd) - export APPDATA=$(pwd)
- <<: *enable_pnpm - bun run build
- pnpm build
package: package:
group: prepare-release group: prepare-release
image: alpine:latest image: alpine:latest
@ -55,10 +50,9 @@ steps:
- zip -r ${CI_REPO_NAME}.zip ${CI_REPO_NAME}/* - zip -r ${CI_REPO_NAME}.zip ${CI_REPO_NAME}/*
changelog: changelog:
group: prepare-release group: prepare-release
image: *node_image image: *bun_image
commands: commands:
- <<: *enable_pnpm - bun run changelog
- pnpm changelog
choose-latest-channel: choose-latest-channel:
group: prepare-release group: prepare-release
image: alpine:latest image: alpine:latest

View file

@ -5,10 +5,7 @@
$schema: https://raw.githubusercontent.com/woodpecker-ci/woodpecker/master/pipeline/schema/schema.json $schema: https://raw.githubusercontent.com/woodpecker-ci/woodpecker/master/pipeline/schema/schema.json
variables: variables:
- &node_image node:lts - &bun_image oven/bun:latest
- &enable_pnpm
- corepack enable
- corepack prepare pnpm@latest --activate
when: when:
event: manual event: manual
@ -19,22 +16,20 @@ depends_on:
steps: steps:
install: install:
image: *node_image image: *bun_image
commands: commands:
- <<: *enable_pnpm - bun install --frozen-lockfile
- pnpm install --frozen-lockfile
release: release:
image: *node_image image: *bun_image
commands: commands:
- <<: *enable_pnpm
- apt-get update - apt-get update
- apt-get install --yes jq - apt-get install --yes jq
- export REPOSITORY_URL=$(echo "${CI_REPO_CLONE_URL}" | sed -e "s|://|://$${FORGE_TOKEN_NAME}:$${FORGE_TOKEN}@|g") - export REPOSITORY_URL=$(echo "${CI_REPO_CLONE_URL}" | sed -e "s|://|://$${FORGE_TOKEN_NAME}:$${FORGE_TOKEN}@|g")
- git remote set-url origin $${REPOSITORY_URL} - git remote set-url origin $${REPOSITORY_URL}
- git config user.name woodpecker[bot] - git config user.name woodpecker[bot]
- git config user.email woodpecker[bot]@${CI_SYSTEM_HOST} - git config user.email woodpecker[bot]@${CI_SYSTEM_HOST}
- pnpm bump-version --release=${RELEASE_TYPE} - bun run bump-version --release=${RELEASE_TYPE}
- pnpm exec prettier --write package.json system.json - bunx prettier --write package.json system.json
- export RELEASE_VERSION=$(jq -r '.version' < package.json) - export RELEASE_VERSION=$(jq -r '.version' < package.json)
- git --no-pager diff - git --no-pager diff
- git add package.json system.json - git add package.json system.json

View file

@ -32,21 +32,12 @@ https://git.f3l.de/api/packages/dungeonslayers/generic/ds4/latest/system.json
### Prerequisites ### Prerequisites
In order to build this system, recent versions of `node` and `pnpm` are In order to build this system, a recent version of `bun` isr equired.
required. Most likely using `npm` or `yarn` also works but only `pnpm` is
officially supported. We recommend using the latest lts version of `node`. If
you use `nvm` to manage your `node` versions, you can simply run
```
nvm install
```
in the project's root directory.
You also need to install the project's dependencies. To do so, run You also need to install the project's dependencies. To do so, run
``` ```
pnpm install bun install
``` ```
### Building ### Building
@ -54,13 +45,13 @@ pnpm install
You can build the project by running You can build the project by running
``` ```
pnpm build bun run build
``` ```
Alternatively, you can run Alternatively, you can run
``` ```
pnpm watch bun run watch
``` ```
to watch for changes and automatically build as necessary. to watch for changes and automatically build as necessary.
@ -83,7 +74,7 @@ On platforms other than Linux you need to adjust the path accordingly.
Then run Then run
``` ```
pnpm link-package bun run link-package
``` ```
### Running the tests ### Running the tests
@ -91,7 +82,7 @@ pnpm link-package
You can run the tests with the following command: You can run the tests with the following command:
``` ```
pnpm test bun run test
``` ```
## Contributing ## Contributing

BIN
bun.lockb Executable file

Binary file not shown.

6
bunfig.toml Normal file
View file

@ -0,0 +1,6 @@
# SPDX-FileCopyrightText: 2023 Johannes Loher
#
# SPDX-License-Identifier: MIT
[test]
preload = "./spec/setup.ts"

View file

@ -2,7 +2,7 @@
"private": true, "private": true,
"name": "dungeonslayers4", "name": "dungeonslayers4",
"description": "An implementation of the Dungeonslayers 4 game system for Foundry Virtual Tabletop.", "description": "An implementation of the Dungeonslayers 4 game system for Foundry Virtual Tabletop.",
"version": "1.21.1", "version": "1.20.0-1",
"license": "https://git.f3l.de/dungeonslayers/ds4#licensing", "license": "https://git.f3l.de/dungeonslayers/ds4#licensing",
"homepage": "https://git.f3l.de/dungeonslayers/ds4", "homepage": "https://git.f3l.de/dungeonslayers/ds4",
"repository": { "repository": {
@ -47,51 +47,50 @@
"clean": "run-p clean:files clean:link", "clean": "run-p clean:files clean:link",
"clean:files": "rimraf dist", "clean:files": "rimraf dist",
"clean:link": "node ./tools/link-package.js --clean", "clean:link": "node ./tools/link-package.js --clean",
"lint": "pnpm eslint", "lint": "bun eslint",
"lint:fix": "pnpm eslint --fix", "lint:fix": "bun eslint --fix",
"eslint": "eslint --ext .ts,.js,.cjs,.mjs .", "eslint": "eslint --ext .ts,.js,.cjs,.mjs .",
"format": "pnpm prettier --write", "format": "bun prettier --write",
"format:check": "pnpm prettier --check", "format:check": "bun prettier --check",
"prettier": "prettier './**/*.(ts|js|cjs|mjs|json|scss|yml|yaml)'", "prettier": "prettier './**/*.(ts|js|cjs|mjs|json|scss|yml|yaml)'",
"test": "run-p test:vitest test:typecheck", "test": "run-p test:bun test:typecheck",
"test:vitest": "vitest run", "test:bun": "bun test",
"test:typecheck": "tsc --noEmit --project spec/tsconfig.json", "test:typecheck": "tsc --noEmit --project spec/tsconfig.json",
"test:watch": "vitest", "test:watch": "bun test --watch",
"typecheck": "tsc --noEmit", "typecheck": "tsc --noEmit",
"typecheck:watch": "tsc --noEmit --watch", "typecheck:watch": "tsc --noEmit --watch",
"bump-version": "node ./tools/bump-version.js", "bump-version": "node ./tools/bump-version.js",
"changelog": "conventional-changelog -p conventionalcommits -o CHANGELOG.md -r 2" "changelog": "conventional-changelog -p conventionalcommits -o CHANGELOG.md -r 2"
}, },
"devDependencies": { "devDependencies": {
"@commitlint/cli": "19.5.0", "@commitlint/cli": "17.6.7",
"@commitlint/config-conventional": "19.5.0", "@commitlint/config-conventional": "17.6.7",
"@foundryvtt/foundryvtt-cli": "0.0.9", "@foundryvtt/foundryvtt-cli": "0.0.9",
"@guanghechen/rollup-plugin-copy": "6.0.2", "@guanghechen/rollup-plugin-copy": "5.0.2",
"@ironkinoko/rollup-plugin-styles": "4.0.3", "@ironkinoko/rollup-plugin-styles": "4.0.3",
"@swc/core": "1.7.28", "@swc/core": "1.3.70",
"@types/fs-extra": "11.0.4", "@types/fs-extra": "11.0.1",
"@types/jquery": "3.5.31", "@types/jquery": "3.5.16",
"@types/node": "18.19.3", "@types/node": "18.16.19",
"@typescript-eslint/eslint-plugin": "7.18.0", "@typescript-eslint/eslint-plugin": "6.1.0",
"@typescript-eslint/parser": "7.18.0", "@typescript-eslint/parser": "6.1.0",
"conventional-changelog-cli": "5.0.0", "bun-types": "0.7.0",
"conventional-changelog-conventionalcommits": "8.0.0", "conventional-changelog-cli": "3.0.0",
"eslint": "8.57.1", "conventional-changelog-conventionalcommits": "6.1.0",
"eslint-config-prettier": "9.1.0", "eslint": "8.45.0",
"fs-extra": "11.2.0", "eslint-config-prettier": "8.8.0",
"handlebars": "4.7.8", "fs-extra": "11.1.1",
"handlebars": "4.7.7",
"npm-run-all": "4.1.5", "npm-run-all": "4.1.5",
"prettier": "3.3.3", "prettier": "3.0.0",
"rimraf": "6.0.1", "rimraf": "5.0.1",
"rollup": "4.24.0", "rollup": "3.26.3",
"rollup-plugin-swc3": "0.11.2", "rollup-plugin-swc3": "0.9.1",
"sass": "1.79.4", "sass": "1.64.0",
"semver": "7.6.3", "semver": "7.5.4",
"tslib": "2.7.0", "tslib": "2.6.0",
"typescript": "5.5.4", "typescript": "5.1.6",
"vite": "4.5.5", "vite": "4.4.6",
"vitest": "0.34.6",
"yargs": "17.7.2" "yargs": "17.7.2"
}, }
"packageManager": "pnpm@9.12.0"
} }

File diff suppressed because it is too large Load diff

View file

@ -3,7 +3,7 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { describe, expect, it } from "vitest"; import { describe, expect, it } from "bun:test";
import { evaluateCheck } from "../../src/dice/check-evaluation"; import { evaluateCheck } from "../../src/dice/check-evaluation";

View file

@ -2,7 +2,7 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { describe, expect, it } from "vitest"; import { describe, expect, it } from "bun:test";
import { calculateSpellPrice } from "../../../../src/documents/item/spell/calculate-spell-price"; import { calculateSpellPrice } from "../../../../src/documents/item/spell/calculate-spell-price";
@ -205,17 +205,15 @@ describe("calculateSpellPrice", () => {
{ cooldownDuration: "d20d", factor: 3 }, { cooldownDuration: "d20d", factor: 3 },
]; ];
describe.each(cooldownDurations)( cooldownDurations.forEach(({ cooldownDuration, factor }) => {
"with cooldown duration set to $cooldownDuration", describe(`with cooldown duration set to ${cooldownDuration}`, () => {
({ cooldownDuration, factor }) => {
const dataWithCooldownDuration = { const dataWithCooldownDuration = {
...defaultData, ...defaultData,
cooldownDuration, cooldownDuration,
}; };
it.each(buildCombinedTestCases())( buildCombinedTestCases().forEach(({ minimumLevels, expected, description }) => {
`returns ${factor} × $expected if the minimum leves are $description`, it(`returns ${factor} × ${expected} if the minimum leves are ${description}`, () => {
({ minimumLevels, expected }) => {
// given // given
const data: DS4SpellDataSourceData = { const data: DS4SpellDataSourceData = {
...dataWithCooldownDuration, ...dataWithCooldownDuration,
@ -227,8 +225,8 @@ describe("calculateSpellPrice", () => {
// then // then
expect(spellPrice).toBe(expected !== null ? expected * factor : expected); expect(spellPrice).toBe(expected !== null ? expected * factor : expected);
}, });
); });
}, });
); });
}); });

View file

@ -2,7 +2,7 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { describe, expect, it } from "vitest"; import { describe, expect, it } from "bun:test";
import { defaultEvaluator, Evaluator, mathEvaluator } from "../../src/expression-evaluation/evaluator"; import { defaultEvaluator, Evaluator, mathEvaluator } from "../../src/expression-evaluation/evaluator";
@ -26,7 +26,7 @@ describe("Evaluator", () => {
const evaluate = () => defaultEvaluator.evaluate(expression); const evaluate = () => defaultEvaluator.evaluate(expression);
// then // then
expect(evaluate).toThrowError("'function' is not an allowed identifier."); expect(evaluate).toThrow("'function' is not an allowed identifier.");
}); });
it("fails to evaluate expressions that contain invalid tokens", () => { it("fails to evaluate expressions that contain invalid tokens", () => {
@ -37,7 +37,7 @@ describe("Evaluator", () => {
const evaluate = () => defaultEvaluator.evaluate(expression); const evaluate = () => defaultEvaluator.evaluate(expression);
// then // then
expect(evaluate).toThrowError("Invalid or unexpected token (1)"); expect(evaluate).toThrow("Invalid or unexpected token (1)");
}); });
it("fails to evaluate expressions that contain arrow functions", () => { it("fails to evaluate expressions that contain arrow functions", () => {
@ -48,7 +48,7 @@ describe("Evaluator", () => {
const evaluate = () => defaultEvaluator.evaluate(expression); const evaluate = () => defaultEvaluator.evaluate(expression);
// then // then
expect(evaluate).toThrowError("Invalid or unexpected token (4)"); expect(evaluate).toThrow("Invalid or unexpected token (4)");
}); });
it("makes the given context available", () => { it("makes the given context available", () => {
@ -84,7 +84,7 @@ describe("Evaluator", () => {
const evaluate = () => mathEvaluator.evaluate(expression); const evaluate = () => mathEvaluator.evaluate(expression);
// then // then
expect(evaluate).toThrowError("'constructor' is not an allowed identifier."); expect(evaluate).toThrow("'constructor' is not an allowed identifier.");
}); });
}); });
}); });

View file

@ -2,7 +2,7 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { describe, expect, it } from "vitest"; import { describe, expect, it } from "bun:test";
import { Lexer } from "../../src/expression-evaluation/lexer"; import { Lexer } from "../../src/expression-evaluation/lexer";
@ -574,7 +574,7 @@ describe("Lexer", () => {
}, },
]; ];
it.each([ [
...singleOperatorTestCases, ...singleOperatorTestCases,
...singleNumberTestCases, ...singleNumberTestCases,
...invalidNumberTestCases, ...invalidNumberTestCases,
@ -584,12 +584,14 @@ describe("Lexer", () => {
...invalidStringTestCases, ...invalidStringTestCases,
...whiteSpaceTestCases, ...whiteSpaceTestCases,
...complicatedTermTestCases, ...complicatedTermTestCases,
])("lexes $input correctly", ({ input, expected }) => { ].forEach(({ input, expected }) => {
// when it(`lexes ${input} correctly`, () => {
const result = consume(new Lexer(input)); // when
const result = consume(new Lexer(input));
// then // then
expect(result).toEqual(expected); expect(result).toEqual(expected);
});
}); });
}); });

View file

@ -2,7 +2,7 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { describe, expect, it } from "vitest"; import { describe, expect, it } from "bun:test";
import { literals, safeOperators } from "../../src/expression-evaluation/grammar"; import { literals, safeOperators } from "../../src/expression-evaluation/grammar";
import { Validator } from "../../src/expression-evaluation/validator"; import { Validator } from "../../src/expression-evaluation/validator";
@ -31,7 +31,7 @@ describe("Validator", () => {
const validate = () => validator.validate(input); const validate = () => validator.validate(input);
// then // then
expect(validate).toThrowError("'true' is not an allowed identifier"); expect(validate).toThrow("'true' is not an allowed identifier");
}); });
it("allows multiple identifiers according to the given predicate", () => { it("allows multiple identifiers according to the given predicate", () => {
@ -70,7 +70,7 @@ describe("Validator", () => {
const validate = () => validator.validate(input); const validate = () => validator.validate(input);
// then // then
expect(validate).toThrowError("'undefined' is not an allowed identifier."); expect(validate).toThrow("'undefined' is not an allowed identifier.");
}); });
it("disallows invalid invalid tokens", () => { it("disallows invalid invalid tokens", () => {
@ -82,7 +82,7 @@ describe("Validator", () => {
const validate = () => validator.validate(input); const validate = () => validator.validate(input);
// then // then
expect(validate).toThrowError("Invalid or unexpected token (0)"); expect(validate).toThrow("Invalid or unexpected token (0)");
}); });
it("allows a complicated valid expression", () => { it("allows a complicated valid expression", () => {
@ -108,7 +108,7 @@ describe("Validator", () => {
const validate = () => validator.validate(input); const validate = () => validator.validate(input);
// then // then
expect(validate).toThrowError("'constructor' is not an allowed identifier."); expect(validate).toThrow("'constructor' is not an allowed identifier.");
}); });
it("disallows arrow functions", () => { it("disallows arrow functions", () => {
@ -120,6 +120,6 @@ describe("Validator", () => {
const validate = () => validator.validate(input); const validate = () => validator.validate(input);
// then // then
expect(validate).toThrowError("Invalid or unexpected token (3)"); expect(validate).toThrow("Invalid or unexpected token (3)");
}); });
}); });

View file

@ -2,7 +2,7 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { describe, expect, it } from "vitest"; import { describe, expect, it } from "bun:test";
import de from "../../lang/de.json"; import de from "../../lang/de.json";
import en from "../../lang/en.json"; import en from "../../lang/en.json";

View file

@ -4,6 +4,8 @@
import en from "../lang/en.json"; import en from "../lang/en.json";
console.log(Bun.version);
function setupPrimitives() { function setupPrimitives() {
Object.defineProperties(Number, { Object.defineProperties(Number, {
isNumeric: { isNumeric: {

View file

@ -1,4 +1,8 @@
{ {
"extends": "../tsconfig.json", "extends": "../tsconfig.json",
"compilerOptions": {
"types": ["bun-types", "@types/jquery", "handlebars"],
"skipLibCheck": true
},
"include": ["../src", "./"] "include": ["../src", "./"]
} }

View file

@ -457,6 +457,27 @@ export class DS4ActorSheet extends ActorSheet {
this.actor.updateEmbeddedDocuments("Item", updates); this.actor.updateEmbeddedDocuments("Item", updates);
} }
/**
* @param {DragEvent} event
* @param {object} data
* @override
*/
async _onDropItem(event, data) {
const item = await Item.implementation.fromDropData(data);
if (item && !this.actor.canOwnItemType(item.type)) {
notifications.warn(
getGame().i18n.format("DS4.WarningActorCannotOwnItem", {
actorName: this.actor.name,
actorType: this.actor.type,
itemName: item.name,
itemType: item.type,
}),
);
return false;
}
return super._onDropItem(event, data);
}
} }
/** /**

View file

@ -5,8 +5,7 @@
import { DS4 } from "../../config"; import { DS4 } from "../../config";
import { createCheckRoll } from "../../dice/check-factory"; import { createCheckRoll } from "../../dice/check-factory";
import { Evaluator } from "../../expression-evaluation/evaluator"; import { mathEvaluator } from "../../expression-evaluation/evaluator";
import { Validator } from "../../expression-evaluation/validator";
import { logger } from "../../utils/logger"; import { logger } from "../../utils/logger";
import { getGame } from "../../utils/utils"; import { getGame } from "../../utils/utils";
import { DS4ActiveEffect } from "../active-effect"; import { DS4ActiveEffect } from "../active-effect";
@ -60,7 +59,7 @@ export class DS4Actor extends Actor {
} }
/** /**
* The effects that should be applied to this actor. * The effects that should be applioed to this actor.
* @type {import("../active-effect").DS4ActiveEffect[]} * @type {import("../active-effect").DS4ActiveEffect[]}
* @protected * @protected
*/ */
@ -91,7 +90,7 @@ export class DS4Actor extends Actor {
if (condition !== undefined && condition !== "") { if (condition !== undefined && condition !== "") {
try { try {
const replacedCondition = DS4Actor.replaceFormulaData(condition, { item, actor: this, effect }); const replacedCondition = DS4Actor.replaceFormulaData(condition, { item, actor: this, effect });
return replacedCondition !== undefined ? Boolean(DS4Actor.evaluator.evaluate(replacedCondition)) : false; return replacedCondition !== undefined ? Boolean(mathEvaluator.evaluate(replacedCondition)) : false;
} catch (error) { } catch (error) {
logger.warn(error); logger.warn(error);
return false; return false;
@ -521,12 +520,6 @@ export class DS4Actor extends Actor {
rejectClose: false, rejectClose: false,
}); });
} }
static evaluator = new Evaluator({
context: Math,
predicate: (identifier) =>
Validator.defaultPredicate(identifier) || ["includes", "toLowerCase", "toUpperCase"].includes(identifier),
});
} }
/** /**

View file

@ -2,6 +2,8 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
/// <reference lib="dom" />
import "../scss/ds4.scss"; import "../scss/ds4.scss";
import { registerForHooks } from "./hooks/hooks"; import { registerForHooks } from "./hooks/hooks";

View file

@ -19,7 +19,7 @@ export class Evaluator<Context extends object> {
get: (t, k) => (k === Symbol.unscopables ? undefined : t[k as keyof typeof t]), get: (t, k) => (k === Symbol.unscopables ? undefined : t[k as keyof typeof t]),
}); });
actualPredicate = (identifier: string) => actualPredicate = (identifier: string) =>
predicate(identifier) || Object.getOwnPropertyNames(context).includes(identifier); predicate(identifier) || Object.getOwnPropertyNames(Math).includes(identifier);
} }
this.validator = new Validator(actualPredicate); this.validator = new Validator(actualPredicate);
} }

View file

@ -4,14 +4,12 @@
import { registerForHotbarDropHook } from "./hotbar-drop"; import { registerForHotbarDropHook } from "./hotbar-drop";
import { registerForInitHook } from "./init"; import { registerForInitHook } from "./init";
import { registerForPreCreateItemHook } from "./pre-create-item";
import { registerForReadyHook } from "./ready"; import { registerForReadyHook } from "./ready";
import { registerForRenderHooks } from "./render"; import { registerForRenderHooks } from "./render";
import { registerForSetupHook } from "./setup"; import { registerForSetupHook } from "./setup";
export function registerForHooks(): void { export function registerForHooks(): void {
registerForHotbarDropHook(); registerForHotbarDropHook();
registerForPreCreateItemHook();
registerForInitHook(); registerForInitHook();
registerForReadyHook(); registerForReadyHook();
registerForRenderHooks(); registerForRenderHooks();

View file

@ -1,28 +0,0 @@
// SPDX-FileCopyrightText: 2023 Johannes Loher
//
// SPDX-License-Identifier: MIT
import { notifications } from "../ui/notifications.js";
import { getGame } from "../utils/utils.js";
export function registerForPreCreateItemHook() {
Hooks.on("preCreateItem", preCreateItem);
}
/**
* @param {import('../documents/item/item.js').DS4Item} item
* @returns {void | false}
*/
function preCreateItem(item) {
if (item.parent instanceof Actor && !item.parent.canOwnItemType(item.type)) {
notifications.warn(
getGame().i18n.format("DS4.WarningActorCannotOwnItem", {
actorName: item.actor.name,
actorType: item.actor.type,
itemName: item.name,
itemType: item.type,
}),
);
return false;
}
}

View file

@ -28,11 +28,12 @@
"name": "Sascha Martens" "name": "Sascha Martens"
} }
], ],
"license": "https://git.f3l.de/dungeonslayers/ds4/raw/tag/1.21.1/LICENSE.md", "url": "https://git.f3l.de/dungeonslayers/ds4",
"readme": "https://git.f3l.de/dungeonslayers/ds4/raw/tag/1.21.1/README.md", "license": "https://git.f3l.de/dungeonslayers/ds4/raw/tag/1.20.0-1/LICENSE.md",
"readme": "https://git.f3l.de/dungeonslayers/ds4/raw/tag/1.20.0-1/README.md",
"bugs": "https://git.f3l.de/dungeonslayers/ds4/issues", "bugs": "https://git.f3l.de/dungeonslayers/ds4/issues",
"changelog": "https://git.f3l.de/dungeonslayers/ds4/releases/tag/1.21.1", "changelog": "https://git.f3l.de/dungeonslayers/ds4/releases/tag/1.20.0-1",
"version": "1.21.1", "version": "1.20.0-1",
"flags": { "flags": {
"hotReload": { "hotReload": {
"extensions": ["css", "hbs", "json"], "extensions": ["css", "hbs", "json"],
@ -115,12 +116,11 @@
"type": "Item" "type": "Item"
} }
], ],
"manifest": "https://git.f3l.de/api/packages/dungeonslayers/generic/ds4/latest/system.json", "manifest": "https://git.f3l.de/api/packages/dungeonslayers/generic/ds4/beta/system.json",
"download": "https://git.f3l.de/dungeonslayers/ds4/releases/download/1.21.1/ds4.zip", "download": "https://git.f3l.de/dungeonslayers/ds4/releases/download/1.20.0-1/ds4.zip",
"initiative": "@combatValues.initiative.total", "initiative": "@combatValues.initiative.total",
"gridDistance": 1, "gridDistance": 1,
"gridUnits": "m", "gridUnits": "m",
"primaryTokenAttribute": "combatValues.hitPoints", "primaryTokenAttribute": "combatValues.hitPoints",
"manifestPlusVersion": "1.2.0", "manifestPlusVersion": "1.2.0"
"url": "https://git.f3l.de/dungeonslayers/ds4"
} }

View file

@ -9,7 +9,7 @@ SPDX-License-Identifier: MIT
!-- Render an effect list entry row. !-- Render an effect list entry row.
!-- @param effectData: The data of the item. !-- @param effectData: The data of the item.
--}} --}}
<li class="ds4-embedded-document-list__row effect" data-effect-uuid="{{effectData.uuid}}" data-effect-id="{{effectData.id}}"> <li class="ds4-embedded-document-list__row effect" data-effect-uuid="{{effectData.uuid}}">
{{!-- enabled --}} {{!-- enabled --}}
<input class="ds4-embedded-document-list__editable ds4-embedded-document-list__editable--checkbox change-effect" <input class="ds4-embedded-document-list__editable ds4-embedded-document-list__editable--checkbox change-effect"
type="checkbox" {{checked (ne effectData.disabled true)}} data-dtype="Boolean" data-property="disabled" type="checkbox" {{checked (ne effectData.disabled true)}} data-dtype="Boolean" data-property="disabled"

View file

@ -15,7 +15,7 @@ SPDX-License-Identifier: MIT
!-- @param hideDescription: A flag to disable the description column. !-- @param hideDescription: A flag to disable the description column.
!-- @param @partial-block: Custom column headers can be passed using the partial block. !-- @param @partial-block: Custom column headers can be passed using the partial block.
--}} --}}
<li class="ds4-embedded-document-list__row item" data-item-uuid="{{item.uuid}}" data-item-id="{{item.id}}"> <li class="ds4-embedded-document-list__row item" data-item-uuid="{{item.uuid}}">
{{!-- equipped --}} {{!-- equipped --}}
{{#if isEquipable}} {{#if isEquipable}}
<input class="ds4-embedded-document-list__editable ds4-embedded-document-list__editable--checkbox change-item" <input class="ds4-embedded-document-list__editable ds4-embedded-document-list__editable--checkbox change-item"

View file

@ -10,7 +10,7 @@ import { hideBin } from "yargs/helpers";
const packageType = "system"; const packageType = "system";
const repositoryOwner = process.env.CI_REPO_OWNER; const repositoryOwner = process.env.CI_REPO_OWNER;
const repositoryName = process.env.CI_REPO_NAME; const repositoryName = process.env.CI_REPO_NAME;
const repositoryURL = process.env.CI_REPO_URL; const repositoryURL = process.env.CI_REPO_LINK;
const forgeURL = process.env.CI_FORGE_URL; const forgeURL = process.env.CI_FORGE_URL;
const getManifestUrl = (channel) => const getManifestUrl = (channel) =>

View file

@ -7,7 +7,7 @@
pack() { pack() {
packs=$(ls -D ./packs) packs=$(ls -D ./packs)
for pack in $packs; do for pack in $packs; do
pnpm exec fvtt package pack --compendiumName=$pack --inputDirectory=./packs/$pack --outputDirectory=./dist/packs bunx fvtt package pack --compendiumName=$pack --inputDirectory=./packs/$pack --outputDirectory=./dist/packs
done done
} }
@ -15,7 +15,7 @@ unpack() {
packs=$(ls -D ./dist/packs) packs=$(ls -D ./dist/packs)
rm -rf ./packs/* rm -rf ./packs/*
for pack in $packs; do for pack in $packs; do
pnpm exec fvtt package unpack --compendiumName=$pack --inputDirectory=./dist/packs --outputDirectory=./packs/$pack bunx fvtt package unpack --compendiumName=$pack --inputDirectory=./dist/packs --outputDirectory=./packs/$pack
done done
} }

View file

@ -1,11 +1,12 @@
{ {
"compilerOptions": { "compilerOptions": {
"outDir": "dist", "outDir": "dist",
"target": "ES2021", "target": "ESNext",
"lib": ["ES2021", "DOM"], "lib": ["ESNext"],
"module": "ESNext",
"types": ["@types/jquery", "handlebars"], "types": ["@types/jquery", "handlebars"],
"esModuleInterop": true, "esModuleInterop": true,
"moduleResolution": "node", "moduleResolution": "bundler",
"forceConsistentCasingInFileNames": true, "forceConsistentCasingInFileNames": true,
"strict": true, "strict": true,
"noUncheckedIndexedAccess": true, "noUncheckedIndexedAccess": true,

View file

@ -1,11 +0,0 @@
// SPDX-FileCopyrightText: 2022 Johannes Loher
//
// SPDX-License-Identifier: MIT
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
setupFiles: ["./spec/setup.ts"],
},
});