Skip to content

Commit

Permalink
Merge pull request #344 from aMediocreDad/fix/adventure-site-sheets
Browse files Browse the repository at this point in the history
  • Loading branch information
aMediocreDad authored Jun 4, 2023
2 parents 92897a0 + 27d7bbe commit b80e484
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/journal/adventure-sites/adventure-site-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, " ")
Expand Down
15 changes: 11 additions & 4 deletions src/journal/adventure-sites/templates/adventure-site-sheet.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
data-action="toggleView"
data-tooltip="{{localize viewMode.label}}"
><i class="{{viewMode.icon}}"></i></a>
<a
class="action-button toggle-search-mode"
data-action="toggleSearch"
data-tooltip="{{localize searchTooltip}}"
><i class="fas {{searchIcon}}"></i></a>
<input
type="search"
name="search"
Expand All @@ -30,7 +35,7 @@
<nav class="pages-list" aria-label="{{localize 'JOURNAL.NavLabel'}}" data-tooltip-direction="RIGHT">
<ol class="directory-list scrollable">
{{#each toc as |page|}}
<li class="directory-item {{page.cssClass}}" data-page-id="{{page._id}}">
<li class="directory-item {{page.tocClass}}" data-page-id="{{page._id}}">
<div class="page-heading">
<span class="page-number" data-tooltip="{{page.name}}">{{page.number}}.</span>
<span class="page-title">{{page.name}}</span>
Expand Down Expand Up @@ -60,7 +65,9 @@
</button>
&nbsp;
{{#if (or (eq type "ice_cave") (eq type "dungeon") (eq type "elven_ruin"))}}
<button type="button" class="create" data-action="add-room"><i class="fas fa-plus-circle"></i>{{localize "JOURNAL.AddRoom"}}
<button type="button" class="create" data-action="add-room"><i
class="fas fa-plus-circle"
></i>{{localize "JOURNAL.AddRoom"}}
</button>
{{/if}}
{{/if}}
Expand All @@ -82,10 +89,10 @@
/>
</form>

<div class="journal-entry-pages {{cssClass}}">
<div class="journal-entry-pages {{cssClass}} {{viewMode.cls}}">
<div class="scrollable">
{{#each pages as |page|}}
<article class="journal-entry-page {{page.type}}" data-page-id="{{page._id}}">
<article class="journal-entry-page {{page.viewClass}}" data-page-id="{{page._id}}">
{{#if page.editable}}
<div class="edit-container">
<a class="editor-edit"><i class="fas fa-edit"></i></a>
Expand Down
48 changes: 48 additions & 0 deletions src/journal/journal-document.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
}

0 comments on commit b80e484

Please sign in to comment.