diff --git a/rollup.config.js b/rollup.config.js index 7a6a8c4a..98331152 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -38,7 +38,7 @@ const config = { assetFileNames: "[name].[ext]", }, plugins: [ - typescript({ noEmitOnError: true }), + typescript(), styles({ mode: ["extract", `css/${name}.css`], url: false, diff --git a/src/hooks/init.ts b/src/hooks/init.ts index 75353d2e..45264fe4 100644 --- a/src/hooks/init.ts +++ b/src/hooks/init.ts @@ -24,6 +24,7 @@ import { createCheckRoll } from "../rolls/check-factory"; import { DS4Roll } from "../rolls/roll"; import registerSlayingDiceModifier from "../rolls/slaying-dice-modifier"; import { registerSystemSettings } from "../settings"; +import { DS4TokenDocument } from "../token-document"; export default function registerForInitHook(): void { Hooks.once("init", init); @@ -47,6 +48,7 @@ async function init() { CONFIG.Item.documentClass = DS4Item; CONFIG.ActiveEffect.documentClass = DS4ActiveEffect; CONFIG.ChatMessage.documentClass = DS4ChatMessage; + CONFIG.Token.documentClass = DS4TokenDocument; CONFIG.Actor.typeLabels = DS4.i18n.actorTypes; CONFIG.Item.typeLabels = DS4.i18n.itemTypes; diff --git a/src/token-document.ts b/src/token-document.ts new file mode 100644 index 00000000..0491f13e --- /dev/null +++ b/src/token-document.ts @@ -0,0 +1,30 @@ +// SPDX-FileCopyrightText: 2021 Johannes Loher +// +// SPDX-License-Identifier: MIT + +import { DS4Actor } from "./actor/actor"; +import { getGame } from "./helpers"; + +let fallbackData: foundry.data.ActorData["data"] | undefined = undefined; + +function getFallbackData() { + if (!fallbackData) { + fallbackData = {} as foundry.data.ActorData["data"]; + for (const type of getGame().system.template.Actor?.types ?? []) { + foundry.utils.mergeObject( + fallbackData, + new DS4Actor({ type: type as foundry.data.ActorData["type"], name: "temporary" }).data.data, + ); + } + } + return fallbackData; +} + +export class DS4TokenDocument extends TokenDocument { + static getTrackedAttributes(data?: foundry.data.ActorData["data"], _path: string[] = []) { + if (!data) { + data = getFallbackData(); + } + return super.getTrackedAttributes(data, _path); + } +}