A repository for a FoundryVTT plugin for Kingmaker homebrew.

Working to get back to the original dev cycle

+91 -4
+65
src/module/kingdom-sheet.ts
··· 1 + import Kingdom from "./kingdom"; 2 + 3 + interface NPCPF2e { 4 + flags: { 5 + "kingdom-homebrew": { 6 + kingdom: Kingdom 7 + } 8 + } 9 + } 10 + 11 + export default class KingdomSheet extends foundry.applications.sheets.ActorSheetV2 { 12 + static get defaultOptions(): object { 13 + return mergeObject( 14 + super.DEFAULT_OPTIONS, 15 + { 16 + template: "kmhb-sheet", 17 + height: "auto" 18 + } 19 + ); 20 + } 21 + 22 + static register(): void { 23 + foundry.documents.collections.Actors.registerSheet("pf2e", KingdomSheet, { 24 + types: [ 25 + "npc" 26 + ] 27 + }); 28 + } 29 + 30 + _renderHTML(context: any, options: foundry.applications.types.ApplicationRenderOptions): Promise<any> { 31 + console.log(context); 32 + if ((context.document as NPCPF2e).flags["kingdom-homebrew"] === undefined) { 33 + (context.document as NPCPF2e).flags["kingdom-homebrew"] = { kingdom: new Kingdom() }; 34 + } 35 + 36 + return new Promise((resolve: (value: Kingdom) => void, reject: (reason: string) => void): void => { 37 + if ((context.document as NPCPF2e).flags["kingdom-homebrew"].kingdom.constructor === Kingdom) { 38 + resolve((context.document as NPCPF2e).flags["kingdom-homebrew"].kingdom); 39 + } else { 40 + reject("data is not Kingdom"); 41 + } 42 + }); 43 + } 44 + 45 + _replaceHTML(data: Kingdom, element: HTMLElement, options: any): void { 46 + foundry.applications.handlebars.renderTemplate("kmhb-sheet", { 47 + tabs: [ 48 + "turn", 49 + "kingdom", 50 + "settlements", 51 + "relations", 52 + "effects" 53 + ] 54 + }).then((html: string) => { 55 + element.innerHTML = html; 56 + 57 + element.querySelectorAll("nav.kingdom-tabs a").forEach((tab: Element) => { 58 + (tab as HTMLElement).onclick = (ev: PointerEvent) => { 59 + element.querySelector(".active")?.classList.remove("active"); 60 + element.querySelector(`.kingdom-tab[data-tab="${(ev.target as HTMLElement).dataset.tab}"]`)!.classList.add("active"); 61 + }; 62 + }); 63 + }); 64 + } 65 + }
+3
src/module/kingdom.ts
··· 1 + export default class Kingdom { 2 + 3 + }
+8
src/module/main.ts
··· 1 + import KingdomSheet from "./kingdom-sheet"; 2 + import preloadTemplates from "./preloadTemplates"; 3 + 4 + Hooks.on("init", async () => { 5 + KingdomSheet.register(); 6 + await preloadTemplates(); 7 + console.log("Kingdom Homebrew loaded"); 8 + });
+3
src/module/preloadTemplates.ts
··· 1 + export default function preloadTemplates() { 2 + return foundry.applications.handlebars.loadTemplates([]); 3 + }
+12 -4
vite.config.ts
··· 7 7 ], 8 8 build: { 9 9 minify: "terser", 10 + terserOptions: { 11 + mangle: true, 12 + sourceMap: true, 13 + compress: { 14 + toplevel: true, 15 + sequences: false 16 + } 17 + }, 10 18 lib: { 11 19 "entry": "src/module/main.ts", 12 - "formats": [ 13 - "es" 14 - ], 15 20 name: "app", 16 - fileName: "main.min" 21 + fileName: "main", 22 + formats: [ 23 + "iife" 24 + ] 17 25 }, 18 26 watch: { 19 27 buildDelay: 1000