diff --git a/modules/heritiers-main.js b/modules/heritiers-main.js index 38672f9..e2118c8 100644 --- a/modules/heritiers-main.js +++ b/modules/heritiers-main.js @@ -110,7 +110,44 @@ Hooks.once("init", async function () { }); /* -------------------------------------------- */ -function welcomeMessage() { +async function getGuideFoundryJournalLink() { + const isGuideFoundryJournal = name => { + const normalizedName = name?.toLowerCase() ?? ""; + return normalizedName.includes("guide de jeu") && normalizedName.includes("foundry"); + }; + + let journal = game.journal.find(j => isGuideFoundryJournal(j.name)); + + if (!journal) { + for (const pack of game.packs) { + if (pack.documentName !== "JournalEntry") continue; + const entry = pack.index.find(e => isGuideFoundryJournal(e.name)); + if (!entry) continue; + journal = await pack.getDocument(entry._id ?? entry.id); + if (journal) break; + } + } + + if (!journal) return ""; + + return foundry.applications.ux.TextEditor.implementation.enrichHTML( + `@UUID[${journal.uuid}]{${journal.name}}`, + { async: true } + ); +} + +/* -------------------------------------------- */ +async function welcomeMessage() { + const guideFoundryLink = await getGuideFoundryJournalLink(); + const guideFoundrySection = guideFoundryLink + ? ` +
Consultez aussi le ${guideFoundryLink}.
+Système développé par LeRatierBretonnien
Support sur le Discord FR de Foundry
+ ${guideFoundrySection} ` @@ -163,7 +201,7 @@ async function importDefaultScene() { /* -------------------------------------------- */ /* Foundry VTT Initialization */ /* -------------------------------------------- */ -Hooks.once("ready", function () { +Hooks.once("ready", async function () { HeritiersUtility.ready() @@ -182,7 +220,7 @@ Hooks.once("ready", function () { }).catch(err => console.log("No stats available, giving up.") ) - welcomeMessage(); + await welcomeMessage(); importDefaultScene(); });