From f6ca63a9df60509b14b5e5ebd18d03e83ee53b72 Mon Sep 17 00:00:00 2001 From: Jeff Hitchcock Date: Wed, 15 Nov 2023 13:38:13 -0800 Subject: [PATCH 1/4] Introduce map location journal entry page type --- dnd5e.mjs | 4 +++ lang/en.json | 2 ++ less/journal.less | 24 +++++++++++++ module/applications/journal/_module.mjs | 1 + module/applications/journal/map-sheet.mjs | 43 +++++++++++++++++++++++ module/data/journal/_module.mjs | 7 ++-- module/data/journal/map.mjs | 12 +++++++ template.json | 2 +- 8 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 module/applications/journal/map-sheet.mjs create mode 100644 module/data/journal/map.mjs diff --git a/dnd5e.mjs b/dnd5e.mjs index b51d0f999e..15e07a6fbe 100644 --- a/dnd5e.mjs +++ b/dnd5e.mjs @@ -118,6 +118,10 @@ Hooks.once("init", function() { label: "DND5E.SheetClassClassSummary", types: ["class"] }); + DocumentSheetConfig.registerSheet(JournalEntryPage, "dnd5e", applications.journal.JournalMapLocationPageSheet, { + label: "DND5E.SheetClassMapLocation", + types: ["map"] + }); // Preload Handlebars helpers & partials utils.registerHandlebarsHelpers(); diff --git a/lang/en.json b/lang/en.json index 0bf27e2696..3947def056 100644 --- a/lang/en.json +++ b/lang/en.json @@ -989,6 +989,7 @@ "DND5E.SenseSpecial": "Special Senses", "DND5E.SheetClassCharacter": "Default 5e Character Sheet", "DND5E.SheetClassClassSummary": "Default 5e Class Summary Sheet", +"DND5E.SheetClassMapLocation": "Default 5e Map Location Sheet", "DND5E.SheetClassNPC": "Default 5e NPC Sheet", "DND5E.SheetClassVehicle": "Default 5e Vehicle Sheet", "DND5E.SheetClassGroup": "Default 5e Group Sheet", @@ -1317,6 +1318,7 @@ "JOURNALENTRYPAGE.TypeClass": "Class Summary", "TYPES.JournalEntryPage.class": "Class Summary", +"TYPES.JournalEntryPage.map": "Map Location", "JOURNALENTRYPAGE.DND5E.Class.AdditionalEquipment": "Equipment", "JOURNALENTRYPAGE.DND5E.Class.AdditionalEquipmentHint": "List of equipment granted by this class if taken at first level.", "JOURNALENTRYPAGE.DND5E.Class.AdditionalHitPoints": "Additional Hit Points Description", diff --git a/less/journal.less b/less/journal.less index 87055bf9f2..ca346607ad 100644 --- a/less/journal.less +++ b/less/journal.less @@ -148,3 +148,27 @@ } } } + +.journal-entry-page.map { + .journal-header { + gap: 1rem; + + [name="system.code"] { + width: 3em; + height: 100%; + background: rgb(0 0 0 / 0.1); + font-size: var(--font-size-24); + text-align: center; + } + + .page-level { + margin-left: 0; + } + } + .map-location-code { + margin-inline-end: 0.25em; + } + .map-location-code::after { + content: ":"; + } +} diff --git a/module/applications/journal/_module.mjs b/module/applications/journal/_module.mjs index 0919ca0d64..450ada131f 100644 --- a/module/applications/journal/_module.mjs +++ b/module/applications/journal/_module.mjs @@ -1,3 +1,4 @@ export {default as JournalClassPageSheet} from "./class-sheet.mjs"; export {default as JournalEditor} from "./journal-editor.mjs"; +export {default as JournalMapLocationPageSheet} from "./map-sheet.mjs"; export {default as SRDCompendium} from "./srd-compendium.mjs"; diff --git a/module/applications/journal/map-sheet.mjs b/module/applications/journal/map-sheet.mjs new file mode 100644 index 0000000000..ee52d65e6a --- /dev/null +++ b/module/applications/journal/map-sheet.mjs @@ -0,0 +1,43 @@ +/** + * Journal entry page that displays a controls for editing map markers. + */ +export default class JournalMapLocationPageSheet extends JournalTextPageSheet { + + /** @inheritdoc */ + static get defaultOptions() { + const options = super.defaultOptions; + options.classes.push("map"); + return options; + } + + /* -------------------------------------------- */ + + /** @inheritdoc */ + get template() { + return `templates/journal/page-text-${this.isEditable ? "edit" : "view"}.html`; + } + + /* -------------------------------------------- */ + + async _renderInner(...args) { + const jQuery = await super._renderInner(...args); + + const editingHeader = jQuery[0].querySelector(".journal-header"); + if ( editingHeader ) { + const input = document.createElement("input"); + input.name = "system.code"; + input.type = "text"; + input.value = this.document.system.code ?? ""; + editingHeader.insertAdjacentElement("afterbegin", input); + } + + else if ( jQuery[0].classList.contains("journal-page-header") && this.document.system.code ) { + const span = document.createElement("span"); + span.innerText = this.document.system.code; + span.classList.add("map-location-code"); + jQuery[0].querySelector(":is(h1, h2, h3)")?.insertAdjacentElement("afterbegin", span); + } + + return jQuery; + } +} diff --git a/module/data/journal/_module.mjs b/module/data/journal/_module.mjs index e94373caa6..9f592db9fb 100644 --- a/module/data/journal/_module.mjs +++ b/module/data/journal/_module.mjs @@ -1,9 +1,12 @@ import ClassJournalPageData from "./class.mjs"; +import MapLocationJournalPageData from "./map.mjs"; export { - ClassJournalPageData + ClassJournalPageData, + MapLocationJournalPageData }; export const config = { - class: ClassJournalPageData + class: ClassJournalPageData, + map: MapLocationJournalPageData }; diff --git a/module/data/journal/map.mjs b/module/data/journal/map.mjs new file mode 100644 index 0000000000..1542d42069 --- /dev/null +++ b/module/data/journal/map.mjs @@ -0,0 +1,12 @@ +/** + * Data definition for Map Location journal entry pages. + * + * @property {string} code Code for the location marker on the map. + */ +export default class MapLocationJournalPageData extends foundry.abstract.DataModel { + static defineSchema() { + return { + code: new foundry.data.fields.StringField() + }; + } +} diff --git a/template.json b/template.json index 0d4ffd9f21..6826d861e1 100644 --- a/template.json +++ b/template.json @@ -716,7 +716,7 @@ } }, "JournalEntryPage": { - "types": ["class"], + "types": ["class", "map"], "htmlFields": ["description.value", "description.additionalHitPoints", "description.additionalTraits", "description.additionalEquipment", "description.subclass"], "class": { "item": "", From b7ab67284b5a064c81781d1e1f24b611fb3e0534 Mon Sep 17 00:00:00 2001 From: Jeff Hitchcock Date: Wed, 15 Nov 2023 14:12:38 -0800 Subject: [PATCH 2/4] Adjust TOC numbering for map pages --- dnd5e.mjs | 5 ++++ lang/en.json | 1 + module/applications/journal/_module.mjs | 5 ++-- .../{class-sheet.mjs => class-page-sheet.mjs} | 0 module/applications/journal/journal-sheet.mjs | 26 +++++++++++++++++++ .../{map-sheet.mjs => map-page-sheet.mjs} | 0 module/data/journal/map.mjs | 12 +++++++++ 7 files changed, 47 insertions(+), 2 deletions(-) rename module/applications/journal/{class-sheet.mjs => class-page-sheet.mjs} (100%) create mode 100644 module/applications/journal/journal-sheet.mjs rename module/applications/journal/{map-sheet.mjs => map-page-sheet.mjs} (100%) diff --git a/dnd5e.mjs b/dnd5e.mjs index 15e07a6fbe..5d24495b3a 100644 --- a/dnd5e.mjs +++ b/dnd5e.mjs @@ -114,6 +114,11 @@ Hooks.once("init", function() { makeDefault: true, label: "DND5E.SheetClassItem" }); + + DocumentSheetConfig.unregisterSheet(JournalEntry, "core", JournalSheet); + DocumentSheetConfig.registerSheet(JournalEntry, "dnd5e", applications.journal.JournalSheet5e, { + label: "DND5E.SheetClassJournalEntry" + }); DocumentSheetConfig.registerSheet(JournalEntryPage, "dnd5e", applications.journal.JournalClassPageSheet, { label: "DND5E.SheetClassClassSummary", types: ["class"] diff --git a/lang/en.json b/lang/en.json index 3947def056..001f5f45fb 100644 --- a/lang/en.json +++ b/lang/en.json @@ -994,6 +994,7 @@ "DND5E.SheetClassVehicle": "Default 5e Vehicle Sheet", "DND5E.SheetClassGroup": "Default 5e Group Sheet", "DND5E.SheetClassItem": "Default 5e Item Sheet", +"DND5E.SheetClassJournalEntry": "Default 5e Journal Entry Sheet", "DND5E.SavingThrow": "Saving Throw", "DND5E.SaveDC": "DC {dc} {ability}", "DND5E.SavePromptTitle": "{ability} Saving Throw", diff --git a/module/applications/journal/_module.mjs b/module/applications/journal/_module.mjs index 450ada131f..045cc59090 100644 --- a/module/applications/journal/_module.mjs +++ b/module/applications/journal/_module.mjs @@ -1,4 +1,5 @@ -export {default as JournalClassPageSheet} from "./class-sheet.mjs"; +export {default as JournalClassPageSheet} from "./class-page-sheet.mjs"; export {default as JournalEditor} from "./journal-editor.mjs"; -export {default as JournalMapLocationPageSheet} from "./map-sheet.mjs"; +export {default as JournalMapLocationPageSheet} from "./map-page-sheet.mjs"; +export {default as JournalSheet5e} from "./journal-sheet.mjs"; export {default as SRDCompendium} from "./srd-compendium.mjs"; diff --git a/module/applications/journal/class-sheet.mjs b/module/applications/journal/class-page-sheet.mjs similarity index 100% rename from module/applications/journal/class-sheet.mjs rename to module/applications/journal/class-page-sheet.mjs diff --git a/module/applications/journal/journal-sheet.mjs b/module/applications/journal/journal-sheet.mjs new file mode 100644 index 0000000000..f40d29bdb8 --- /dev/null +++ b/module/applications/journal/journal-sheet.mjs @@ -0,0 +1,26 @@ +/** + * Variant of the standard journal sheet to handle custom TOC numbering. + */ +export default class JournalSheet5e extends JournalSheet { + /** @inheritdoc */ + _getPageData() { + const pageData = super._getPageData(); + + let adjustment = 0; + for ( const page of pageData ) { + const pageDocument = this.document.pages.get(page._id); + let needsAdjustment = true; + if ( foundry.utils.getType(pageDocument?.system?.adjustTOCNumbering) === "function" ) { + const numbering = pageDocument.system.adjustTOCNumbering(page.number); + if ( numbering ) { + page.number = numbering.number; + adjustment += numbering.adjustment ?? 0; + needsAdjustment = false; + } + } + if ( needsAdjustment ) page.number += adjustment; + } + + return pageData; + } +} diff --git a/module/applications/journal/map-sheet.mjs b/module/applications/journal/map-page-sheet.mjs similarity index 100% rename from module/applications/journal/map-sheet.mjs rename to module/applications/journal/map-page-sheet.mjs diff --git a/module/data/journal/map.mjs b/module/data/journal/map.mjs index 1542d42069..d8b58b6f26 100644 --- a/module/data/journal/map.mjs +++ b/module/data/journal/map.mjs @@ -9,4 +9,16 @@ export default class MapLocationJournalPageData extends foundry.abstract.DataMod code: new foundry.data.fields.StringField() }; } + + /* -------------------------------------------- */ + + /** + * Adjust the number of this entry in the table of contents. + * @param {number} number Current position number. + * @returns {{ number: string, adjustment: [number] }|void} + */ + adjustTOCNumbering(number) { + if ( !this.code ) return; + return { number: this.code, adjustment: -1 }; + } } From e344231ac47e2b040b2866cada0510c449b727d4 Mon Sep 17 00:00:00 2001 From: Jeff Hitchcock Date: Thu, 16 Nov 2023 09:22:45 -0800 Subject: [PATCH 3/4] Move location code in journal header into ::before --- less/journal.less | 13 +++++-------- module/applications/journal/map-page-sheet.mjs | 10 ++++------ 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/less/journal.less b/less/journal.less index ca346607ad..7426d9ec31 100644 --- a/less/journal.less +++ b/less/journal.less @@ -154,21 +154,18 @@ gap: 1rem; [name="system.code"] { - width: 3em; - height: 100%; + block-size: 100%; + inline-size: 3em; background: rgb(0 0 0 / 0.1); font-size: var(--font-size-24); text-align: center; } .page-level { - margin-left: 0; + margin-inline-start: 0; } } - .map-location-code { - margin-inline-end: 0.25em; - } - .map-location-code::after { - content: ":"; + [data-map-location-code]::before { + content: attr(data-map-location-code) ': '; } } diff --git a/module/applications/journal/map-page-sheet.mjs b/module/applications/journal/map-page-sheet.mjs index ee52d65e6a..421741e471 100644 --- a/module/applications/journal/map-page-sheet.mjs +++ b/module/applications/journal/map-page-sheet.mjs @@ -21,8 +21,9 @@ export default class JournalMapLocationPageSheet extends JournalTextPageSheet { async _renderInner(...args) { const jQuery = await super._renderInner(...args); - const editingHeader = jQuery[0].querySelector(".journal-header"); + const viewingHeader = jQuery[0].querySelector(":is(h1, h2, h3)"); + if ( editingHeader ) { const input = document.createElement("input"); input.name = "system.code"; @@ -31,11 +32,8 @@ export default class JournalMapLocationPageSheet extends JournalTextPageSheet { editingHeader.insertAdjacentElement("afterbegin", input); } - else if ( jQuery[0].classList.contains("journal-page-header") && this.document.system.code ) { - const span = document.createElement("span"); - span.innerText = this.document.system.code; - span.classList.add("map-location-code"); - jQuery[0].querySelector(":is(h1, h2, h3)")?.insertAdjacentElement("afterbegin", span); + else if ( viewingHeader && this.document.system.code ) { + viewingHeader.dataset.mapLocationCode = this.document.system.code; } return jQuery; From e36f9e065e14bdfceb6046998c1672df7741d063 Mon Sep 17 00:00:00 2001 From: Jeff Hitchcock Date: Mon, 20 Nov 2023 13:11:02 -0800 Subject: [PATCH 4/4] Minor style fixes to map journal pages --- module/applications/journal/journal-sheet.mjs | 12 +++++------- module/applications/journal/map-page-sheet.mjs | 1 + module/data/journal/map.mjs | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/module/applications/journal/journal-sheet.mjs b/module/applications/journal/journal-sheet.mjs index f40d29bdb8..7b9c63e8b8 100644 --- a/module/applications/journal/journal-sheet.mjs +++ b/module/applications/journal/journal-sheet.mjs @@ -10,13 +10,11 @@ export default class JournalSheet5e extends JournalSheet { for ( const page of pageData ) { const pageDocument = this.document.pages.get(page._id); let needsAdjustment = true; - if ( foundry.utils.getType(pageDocument?.system?.adjustTOCNumbering) === "function" ) { - const numbering = pageDocument.system.adjustTOCNumbering(page.number); - if ( numbering ) { - page.number = numbering.number; - adjustment += numbering.adjustment ?? 0; - needsAdjustment = false; - } + const numbering = pageDocument.system.adjustTOCNumbering?.(page.number); + if ( numbering ) { + page.number = numbering.number; + adjustment += numbering.adjustment ?? 0; + needsAdjustment = false; } if ( needsAdjustment ) page.number += adjustment; } diff --git a/module/applications/journal/map-page-sheet.mjs b/module/applications/journal/map-page-sheet.mjs index 421741e471..ae79dcb3ea 100644 --- a/module/applications/journal/map-page-sheet.mjs +++ b/module/applications/journal/map-page-sheet.mjs @@ -19,6 +19,7 @@ export default class JournalMapLocationPageSheet extends JournalTextPageSheet { /* -------------------------------------------- */ + /** @inheritdoc */ async _renderInner(...args) { const jQuery = await super._renderInner(...args); const editingHeader = jQuery[0].querySelector(".journal-header"); diff --git a/module/data/journal/map.mjs b/module/data/journal/map.mjs index d8b58b6f26..eb122b37bd 100644 --- a/module/data/journal/map.mjs +++ b/module/data/journal/map.mjs @@ -15,7 +15,7 @@ export default class MapLocationJournalPageData extends foundry.abstract.DataMod /** * Adjust the number of this entry in the table of contents. * @param {number} number Current position number. - * @returns {{ number: string, adjustment: [number] }|void} + * @returns {{ number: string, adjustment: number }|void} */ adjustTOCNumbering(number) { if ( !this.code ) return;