Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 🐛 Adventure Site button disappears #450

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
}
Loading