Skip to content

Commit 58baabf

Browse files
committed
fix: 🐛 Adventure Site button disappears
Fixes #446
1 parent b315c2a commit 58baabf

File tree

2 files changed

+50
-43
lines changed

2 files changed

+50
-43
lines changed

Diff for: .changeset/lazy-penguins-run.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"forbidden-lands": patch
3+
---
4+
5+
Fixed an issue where the Adventure Site creation button would disappear when creating and adventure site

Diff for: src/system/core/hooks.js

+45-43
Original file line numberDiff line numberDiff line change
@@ -257,54 +257,56 @@ export default function registerHooks() {
257257
});
258258
});
259259

260-
Hooks.on("changeSidebarTab", (app) => {
261-
const shouldRender =
262-
app.tabName === "journal" &&
263-
Object.keys(CONFIG.fbl.adventureSites.types).length &&
264-
!app.element.find("#create-adventure-site").length;
260+
for (const hook of ["renderSidebarTab", "changeSidebarTab"]) {
261+
Hooks.on(hook, (app) => {
262+
const shouldRender =
263+
app.tabName === "journal" &&
264+
Object.keys(CONFIG.fbl.adventureSites.types).length &&
265+
!app.element.find("#create-adventure-site").length;
265266

266-
if (!shouldRender) return;
267+
if (!shouldRender) return;
267268

268-
const adventureSiteButton = $(
269-
`<button id="create-adventure-site"><i class="fas fa-castle"></i> Create Adventure Site</button>`,
270-
);
271-
adventureSiteButton.on("click", () => {
272-
adventureSiteCreateDialog();
269+
const adventureSiteButton = $(
270+
`<button id="create-adventure-site"><i class="fas fa-castle"></i> Create Adventure Site</button>`,
271+
);
272+
adventureSiteButton.on("click", () => {
273+
adventureSiteCreateDialog();
274+
});
275+
276+
app.element.find(".header-actions").append(adventureSiteButton);
273277
});
278+
}
274279

275-
app.element.find(".header-actions").append(adventureSiteButton);
276-
});
277-
}
280+
Hooks.on("renderJournalSheet", (app, html) => {
281+
const type = app.object.getFlag("forbidden-lands", "adventureSiteType");
282+
const isDungeon = ["dungeon", "ice_cave", "elven_ruin"].includes(type);
283+
if (!isDungeon) return;
278284

279-
Hooks.on("renderJournalSheet", (app, html) => {
280-
const type = app.object.getFlag("forbidden-lands", "adventureSiteType");
281-
const isDungeon = ["dungeon", "ice_cave", "elven_ruin"].includes(type);
282-
if (!isDungeon) return;
285+
const button = $(
286+
`<button type="button" class="create" data-action="add-room"><i class="fas fa-plus-circle"></i> ${t("ADVENTURE_SITE.ADD_ROOM")}</button>`,
287+
);
283288

284-
const button = $(
285-
`<button type="button" class="create" data-action="add-room"><i class="fas fa-plus-circle"></i> ${t("ADVENTURE_SITE.ADD_ROOM")}</button>`,
286-
);
289+
button.on("click", async () => {
290+
const path = CONFIG.fbl.adventureSites.types[type];
291+
const room = await CONFIG.fbl.adventureSites?.generate(
292+
path,
293+
`${type}_rooms`,
294+
);
295+
const pageName = $(room)
296+
.find("h4, strong")
297+
?.first()
298+
.text()
299+
.replace(/[^\p{L}]+/u, " ")
300+
.trim();
301+
await app.object.createEmbeddedDocuments("JournalEntryPage", [
302+
{
303+
name: pageName,
304+
title: { level: 2, show: false },
305+
text: { content: `<div class="adventure-site">${room}</div>` },
306+
},
307+
]);
308+
});
287309

288-
button.on("click", async () => {
289-
const path = CONFIG.fbl.adventureSites.types[type];
290-
const room = await CONFIG.fbl.adventureSites?.generate(
291-
path,
292-
`${type}_rooms`,
293-
);
294-
const pageName = $(room)
295-
.find("h4, strong")
296-
?.first()
297-
.text()
298-
.replace(/[^\p{L}]+/u, " ")
299-
.trim();
300-
await app.object.createEmbeddedDocuments("JournalEntryPage", [
301-
{
302-
name: pageName,
303-
title: { level: 2, show: false },
304-
text: { content: `<div class="adventure-site">${room}</div>` },
305-
},
306-
]);
310+
html.find('[data-action="createPage"]').after(button);
307311
});
308-
309-
html.find('[data-action="createPage"]').after(button);
310-
});
312+
}

0 commit comments

Comments
 (0)