-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from foundryvtt/map-page
Introduce map location journal entry page type
- Loading branch information
Showing
10 changed files
with
132 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters