Skip to content

Commit

Permalink
fix: 🐛 Adventure Site button disappears
Browse files Browse the repository at this point in the history
Fixes #446
  • Loading branch information
aMediocreDad committed Aug 15, 2024
1 parent b315c2a commit 58baabf
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 43 deletions.
5 changes: 5 additions & 0 deletions .changeset/lazy-penguins-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"forbidden-lands": patch
---

Fixed an issue where the Adventure Site creation button would disappear when creating and adventure site
88 changes: 45 additions & 43 deletions src/system/core/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,54 +257,56 @@ export default function registerHooks() {
});
});

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

if (!shouldRender) return;
if (!shouldRender) return;

const adventureSiteButton = $(
`<button id="create-adventure-site"><i class="fas fa-castle"></i> Create Adventure Site</button>`,
);
adventureSiteButton.on("click", () => {
adventureSiteCreateDialog();
const adventureSiteButton = $(
`<button id="create-adventure-site"><i class="fas fa-castle"></i> Create Adventure Site</button>`,
);
adventureSiteButton.on("click", () => {
adventureSiteCreateDialog();
});

app.element.find(".header-actions").append(adventureSiteButton);
});
}

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

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

const button = $(
`<button type="button" class="create" data-action="add-room"><i class="fas fa-plus-circle"></i> ${t("ADVENTURE_SITE.ADD_ROOM")}</button>`,
);
button.on("click", async () => {
const path = CONFIG.fbl.adventureSites.types[type];
const room = await CONFIG.fbl.adventureSites?.generate(
path,
`${type}_rooms`,
);
const pageName = $(room)
.find("h4, strong")
?.first()
.text()
.replace(/[^\p{L}]+/u, " ")
.trim();
await app.object.createEmbeddedDocuments("JournalEntryPage", [
{
name: pageName,
title: { level: 2, show: false },
text: { content: `<div class="adventure-site">${room}</div>` },
},
]);
});

button.on("click", async () => {
const path = CONFIG.fbl.adventureSites.types[type];
const room = await CONFIG.fbl.adventureSites?.generate(
path,
`${type}_rooms`,
);
const pageName = $(room)
.find("h4, strong")
?.first()
.text()
.replace(/[^\p{L}]+/u, " ")
.trim();
await app.object.createEmbeddedDocuments("JournalEntryPage", [
{
name: pageName,
title: { level: 2, show: false },
text: { content: `<div class="adventure-site">${room}</div>` },
},
]);
html.find('[data-action="createPage"]').after(button);
});

html.find('[data-action="createPage"]').after(button);
});
}

0 comments on commit 58baabf

Please sign in to comment.