diff --git a/src/journal/adventure-sites/adventure-site-sheet.js b/src/journal/adventure-sites/adventure-site-sheet.js index 48ad2290..349acaf1 100644 --- a/src/journal/adventure-sites/adventure-site-sheet.js +++ b/src/journal/adventure-sites/adventure-site-sheet.js @@ -3,19 +3,21 @@ export class AdventureSitesSheet extends JournalSheet { return "systems/forbidden-lands/templates/journal/adventure-sites/adventure-site-sheet.hbs"; } - getData() { - const data = super.getData(); + getData(options) { + const data = super.getData(options); data.type = this.object.type; return data; } activateListeners(html) { super.activateListeners(html); + html.find('[data-action="add-room"]').on("click", async () => { const type = this.object.type; const path = CONFIG.fbl.adventureSites.types[type]; const room = await CONFIG.fbl.adventureSites?.generate(path, type + "_rooms"); - const pageName = ($(room).find("h4") || $(room).find("strong")) + const pageName = $(room) + .find("h4, strong") ?.first() .text() .replace(/[^\p{L}]+/u, " ") diff --git a/src/journal/adventure-sites/templates/adventure-site-sheet.hbs b/src/journal/adventure-sites/templates/adventure-site-sheet.hbs index 78b6afe9..882aa410 100644 --- a/src/journal/adventure-sites/templates/adventure-site-sheet.hbs +++ b/src/journal/adventure-sites/templates/adventure-site-sheet.hbs @@ -11,6 +11,11 @@ data-action="toggleView" data-tooltip="{{localize viewMode.label}}" > +
    {{#each toc as |page|}} -
  1. +
  2. {{page.number}}. {{page.name}} @@ -60,7 +65,9 @@   {{#if (or (eq type "ice_cave") (eq type "dungeon") (eq type "elven_ruin"))}} - {{/if}} {{/if}} @@ -82,10 +89,10 @@ /> -
    +
    {{#each pages as |page|}} -
    +
    {{#if page.editable}}
    diff --git a/src/journal/journal-document.js b/src/journal/journal-document.js index af0c8038..34638bbf 100644 --- a/src/journal/journal-document.js +++ b/src/journal/journal-document.js @@ -9,9 +9,57 @@ export class ForbiddenLandsJournalEntry extends JournalEntry { data.pages = [{ name: "Overview", title: { show: false }, text: { content } }]; super.create(data, options); } + get type() { const type = this.getFlag("forbidden-lands", "type"); if (type) return type; else return CONST.BASE_DOCUMENT_TYPE; } + + // Lifted straight out of Foundry because in V11 it removes the base type from the list of types + static async createDialog(data = {}, { parentFolder = null, pack = null, ...options } = {}) { + // Collect data + const documentName = this.metadata.name; + const types = game.documentTypes[documentName]; + let folders = []; + if (!parentFolder) { + if (pack) folders = game.packs.get(pack).folders.contents; + else folders = game.folders.filter((f) => f.type === documentName && f.displayed); + } + const label = game.i18n.localize(this.metadata.label); + const title = game.i18n.format("DOCUMENT.Create", { type: label }); + + // Render the document creation form + const html = await renderTemplate("templates/sidebar/document-create.html", { + folders, + name: data.name || game.i18n.format("DOCUMENT.New", { type: label }), + folder: data.folder, + hasFolders: folders.length >= 1, + type: data.type || CONFIG[documentName]?.defaultType || types[0], + types: types.reduce((obj, t) => { + const typeLabel = CONFIG[documentName]?.typeLabels?.[t] ?? t; + obj[t] = game.i18n.has(typeLabel) ? game.i18n.localize(typeLabel) : t; + return obj; + }, {}), + hasTypes: types.length > 1, + }); + + // Render the confirmation dialog window + return Dialog.prompt({ + title: title, + content: html, + label: title, + callback: (JQhtml) => { + const form = JQhtml[0].querySelector("form"); + const fd = new FormDataExtended(form); + foundry.utils.mergeObject(data, fd.object, { inplace: true }); + if (!data.folder) delete data.folder; + if (types.length === 1) data.type = types[0]; + if (!data.name?.trim()) data.name = this.defaultName(); + return this.create(data, { parent: parentFolder, pack, renderSheet: true }); + }, + rejectClose: false, + options, + }); + } }