All user data for FoundryVTT. Includes worlds, systems, modules, and any asset in the "foundryuserdata" directory. Does NOT include the FoundryVTT installation itself.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.3 KiB

1 year ago
  1. import CONFIG from "./adventure.mjs";
  2. import PF2EAdventureImporter from "./importer.mjs";
  3. import {extractLocalization} from "./i18n.mjs";
  4. /* -------------------------------------------- */
  5. /* Initialize Module API */
  6. /* -------------------------------------------- */
  7. Hooks.once("init", () => {
  8. const module = game.modules.get(CONFIG.moduleId);
  9. module.api = {
  10. PF2EAdventureImporter,
  11. extractLocalization
  12. };
  13. // Register settings
  14. game.settings.register(CONFIG.moduleId, "startup", {
  15. name: "One-Time Startup Prompt",
  16. scope: "world",
  17. config: false,
  18. type: Boolean,
  19. default: false
  20. });
  21. // Register sheets
  22. DocumentSheetConfig.registerSheet(Adventure, CONFIG.moduleId, PF2EAdventureImporter, {
  23. label: "Abomination Vaults Importer"
  24. });
  25. })
  26. /* -------------------------------------------- */
  27. /* Activate Module Features */
  28. /* -------------------------------------------- */
  29. Hooks.on("ready", async (app, html, data) => {
  30. // Imported state.
  31. game.settings.register(CONFIG.moduleId, "imported", {
  32. scope: "world",
  33. type: Boolean,
  34. config: false,
  35. default: game.journal.has(CONFIG.adventure.gettingStartedId)
  36. });
  37. const module = game.modules.get(CONFIG.moduleId);
  38. const firstStartup = game.settings.get(CONFIG.moduleId, "startup") === false;
  39. if ( firstStartup ) {
  40. for ( const p of module.packs ) {
  41. const pack = game.packs.get(`${CONFIG.moduleId}.${p.name}`);
  42. const adventures = await pack.getDocuments();
  43. for ( const adventure of adventures ) {
  44. adventure.sheet.render(true);
  45. }
  46. }
  47. game.settings.set(CONFIG.moduleId, "startup", true);
  48. }
  49. });
  50. Hooks.on("importAdventure", () => game.settings.set(CONFIG.moduleId, "imported", true));
  51. /* -------------------------------------------- */
  52. /* Journal Styling */
  53. /* -------------------------------------------- */
  54. Hooks.on("renderJournalSheet", (app, html, data) => {
  55. const journal = app.document;
  56. if ( journal.getFlag(CONFIG.moduleId, CONFIG.journalFlag) ) html[0].classList.add(CONFIG.cssClass);
  57. });
  58. Hooks.on("renderJournalPageSheet", (app, html, data) => {
  59. const journal = app.document.parent;
  60. if ( journal.getFlag(CONFIG.moduleId, CONFIG.journalFlag) ) html[0].classList.add(CONFIG.cssClass);
  61. });