From 1a27fa7e9752bcf388978286490f67d1821d49e8 Mon Sep 17 00:00:00 2001
From: Johannes Loher <johannes.loher@fg4f.de>
Date: Sat, 12 Feb 2022 04:01:38 +0100
Subject: [PATCH] feat: allow selecting all resources in the combat tracker
 config and the default token config

---
 src/hooks/init.ts     |  2 ++
 src/token-document.ts | 30 ++++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+)
 create mode 100644 src/token-document.ts

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);
+    }
+}