Skip to content

Commit

Permalink
Merge pull request #1 from foundryvtt/map-page
Browse files Browse the repository at this point in the history
Introduce map location journal entry page type
  • Loading branch information
arbron authored Nov 20, 2023
2 parents 13f0798 + e36f9e0 commit 0e8395a
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 4 deletions.
9 changes: 9 additions & 0 deletions dnd5e.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,19 @@ 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"]
});
DocumentSheetConfig.registerSheet(JournalEntryPage, "dnd5e", applications.journal.JournalMapLocationPageSheet, {
label: "DND5E.SheetClassMapLocation",
types: ["map"]
});

// Preload Handlebars helpers & partials
utils.registerHandlebarsHelpers();
Expand Down
3 changes: 3 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -989,10 +989,12 @@
"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",
"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",
Expand Down Expand Up @@ -1317,6 +1319,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",
Expand Down
21 changes: 21 additions & 0 deletions less/journal.less
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,24 @@
}
}
}

.journal-entry-page.map {
.journal-header {
gap: 1rem;

[name="system.code"] {
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-inline-start: 0;
}
}
[data-map-location-code]::before {
content: attr(data-map-location-code) ': ';
}
}
4 changes: 3 additions & 1 deletion module/applications/journal/_module.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +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-page-sheet.mjs";
export {default as JournalSheet5e} from "./journal-sheet.mjs";
export {default as SRDCompendium} from "./srd-compendium.mjs";
File renamed without changes.
24 changes: 24 additions & 0 deletions module/applications/journal/journal-sheet.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* 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;
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;
}
}
42 changes: 42 additions & 0 deletions module/applications/journal/map-page-sheet.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* 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`;
}

/* -------------------------------------------- */

/** @inheritdoc */
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";
input.type = "text";
input.value = this.document.system.code ?? "";
editingHeader.insertAdjacentElement("afterbegin", input);
}

else if ( viewingHeader && this.document.system.code ) {
viewingHeader.dataset.mapLocationCode = this.document.system.code;
}

return jQuery;
}
}
7 changes: 5 additions & 2 deletions module/data/journal/_module.mjs
Original file line number Diff line number Diff line change
@@ -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
};
24 changes: 24 additions & 0 deletions module/data/journal/map.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* 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()
};
}

/* -------------------------------------------- */

/**
* 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 };
}
}
2 changes: 1 addition & 1 deletion template.json
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@
}
},
"JournalEntryPage": {
"types": ["class"],
"types": ["class", "map"],
"htmlFields": ["description.value", "description.additionalHitPoints", "description.additionalTraits", "description.additionalEquipment", "description.subclass"],
"class": {
"item": "",
Expand Down

0 comments on commit 0e8395a

Please sign in to comment.