A FoundryVTT module for playing at an in-person table.
at main 54 lines 1.9 kB view raw
1import { registerSocket } from "./socket"; 2import UniversalControl from "./unicontrol"; 3import { editPlayerModes, tokenControlCB } from "./utils"; 4 5Hooks.once("init", (): void => { 6 ((game as foundry.Game).modules as { get: (val: string) => any }).get("pf2e-table-mode")!.macros = { 7 editPlayerModes 8 }; 9 10 console.log("PF2E Table Mode - Loaded"); 11}); 12 13Hooks.once("socketlib.ready", registerSocket); 14 15Hooks.once("ready", (): void => { 16 if ((game as foundry.Game).user.getFlag("pf2e-table-mode", "mobile")) { 17 document.body.classList.add("mobile-mode"); 18 19 if (document.body.classList.contains("system-pf2e")) { 20 (game as foundry.Game).user.character.sheet.render(true); 21 } else { 22 const app = new UniversalControl(); 23 app.render(true); 24 } 25 } 26 27 if ((game as foundry.Game).user.getFlag("pf2e-table-mode", "display")) { 28 document.body.classList.add("display-mode"); 29 } 30}); 31 32Hooks.on("renderActorSheet", (sheet: any, element: Element[], _options: any): void => { 33 if ((game as foundry.Game).user.getFlag("pf2e-table-mode", "mobile")) { 34 sheet.setPosition({ 35 left: 0, 36 top: 0, 37 width: window.innerWidth, 38 height: window.innerHeight 39 }); 40 41 const sheetBody = element[0].querySelector("section.sheet-body"); 42 const tokenButtons = document.createElement("section"); 43 tokenButtons.classList.add("token-buttons"); 44 sheetBody!.appendChild(tokenButtons); 45 46 ["left", "right", "down", "up"].forEach((direction: string): void => { 47 const button = document.createElement("button"); 48 button.dataset.direction = direction; 49 button.addEventListener("click", tokenControlCB); 50 button.innerHTML = `<i class="fas fa-arrow-${direction}"></i>`; 51 tokenButtons.appendChild(button); 52 }); 53 } 54});