Skip to content

Commit

Permalink
Merge pull request #18 from etriebe/etriebe/fix_v10_errors
Browse files Browse the repository at this point in the history
Fix button not appearing in V10
  • Loading branch information
etriebe authored Sep 11, 2022
2 parents 522048d + 9f537e5 commit 8b81f1f
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions scripts/module.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CombatEstimateDialog } from "./dialog.js";
import { FoundryUtils } from "./utils/FoundryUtils.js";

Hooks.once('init', async function ()
{
Expand All @@ -12,23 +13,35 @@ Hooks.once('ready', async function ()

Hooks.on("renderSidebarTab", (settings) =>
{
if (!game.user.isGM || settings.id != "combat")
{
return;
}
const html = settings.element;
if (html.find("#combatEstimateButton").length !== 0)
{
if(!game.user.isGM) {
return;
}

const button = `<button id="combatEstimateButton" style="flex-basis: auto;">
<i class="fas fa-calculator"></i> Combat Estimate
</button>`;
html.find(`#combat-round`).first().append(button);
html.find("#combatEstimateButton").on("click", async (e) =>
{
e.preventDefault();
if (!canvas.CombatEstimateDialog?.rendered) await canvas.CombatEstimateDialog.render(true);
});
});
if (settings.id === "combat"){
const html = settings.element;
if (html.find("#combatEstimateButton").length !== 0)
{
return;
}

const button = `<button id="combatEstimateButton" style="flex-basis: auto;">
<i class="fas fa-calculator"></i> Combat Estimate
</button>`;

let elementToAppendTo = ``;
if (FoundryUtils.isFoundryVersion10())
{
elementToAppendTo = `.combat-tracker-header`;
}
else
{
elementToAppendTo = `#combat-round`;
}
html.find(elementToAppendTo).first().append(button);
html.find("#combatEstimateButton").on("click", async (e) =>
{
e.preventDefault();
if (!canvas.CombatEstimateDialog?.rendered) await canvas.CombatEstimateDialog.render(true);
});
}
});

0 comments on commit 8b81f1f

Please sign in to comment.