itteerde / fvttconfig

Configuration for our Foundry VTT environments
2 stars 1 forks source link

Display Spell Item Uses on CharacterSheet #230

Closed itteerde closed 5 months ago

itteerde commented 8 months ago
Hooks.on("renderActorSheet5eCharacter2", (app, [html]) => {
  if (!app.document.testUserPermission(game.user, CONST.DOCUMENT_OWNERSHIP_LEVELS.OBSERVER)) return;
  const spellTab = html.querySelector(".items-list.spells-list").querySelectorAll(".item-list");
  for (const list of spellTab) {
    const spells = list.querySelectorAll(".item");
    for (const spell of spells) {
      const item = app.document.items.get(spell.dataset.itemId);
      const uses = item.system.uses;
      if (uses.max > 0 && uses.per) {
        const per = (uses.per === "lr" || uses.per === "sr") ? uses.per : "";
        const newHTML = `
          <div class="item-detail item-range item-casts">
            <span class="value">${uses.value}/${uses.max}</span>
            <span class="unit">${per}</span>
          </div>
        `;
        spell.querySelector(".item-school").insertAdjacentHTML("beforebegin", newHTML);
      };
    };
  };
});
itteerde commented 8 months ago

https://github.com/foundryvtt/dnd5e/issues/2773

itteerde commented 8 months ago

for tonight: works as a player in console, too

itteerde commented 5 months ago

Not sure if it is dnd5e already, but certainly is there with the Sidebar improving Module we are currently using (from which's pre-alpha the hotfix code was, too)