Skip to content

Commit

Permalink
adding tidysheet5e support, adding inspiration message
Browse files Browse the repository at this point in the history
  • Loading branch information
mysurvive committed Jan 27, 2024
1 parent 59ac75c commit b019175
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions src/module/so-inspired.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function createInspoFlag() {
function renderNewInspoSheet(_sheet, html) {
if (_sheet.actor.type === "character") {
const actorUuid = _sheet.actor.uuid;
const actorOwner = game.users.find((u) => u.character.uuid === actorUuid);
const actorOwner = game.users.find((u) => u.character?.uuid === actorUuid);
let currentInspiration;
if (actorOwner) {
currentInspiration = actorOwner.getFlag(
Expand All @@ -62,19 +62,25 @@ function renderNewInspoSheet(_sheet, html) {
const inspirationArea = $(html).find(".inspiration");
inspirationArea.hide();

const counterArea = $(html).find(".counters");

const newInspirationArea = `<div class="counter flexrow new-inspiration"><h4>Inspiration</h4><div class="counter-value"><button type="button" class="add-inspiration-btn"><i class="fa-solid fa-plus" style="color: #000000;"></i></button><button type="button" class="remove-inspiration-btn"><i class="fa-solid fa-minus" style="color: #000000;"></i></button><span class="inspiration-span">${currentInspiration}</span></div></div>`;

counterArea.append(newInspirationArea);
let counterArea;
let newInspirationArea;
if (_sheet.options.classes.includes("tidy5e")) {
counterArea = $(html).find(".tidy5e-header");
newInspirationArea = `<div class="counter flexrow new-inspiration" style="width: 200px; height:25px; display:flex; margin: 10px 10px 10px 10px;"><h4>Inspiration</h4><div class="counter-value"><button type="button" class="add-inspiration-btn" style="height:20px;width:20px;line-height:0px;padding-left:2px;"><i class="fa-solid fa-plus" style="color: #000000;"></i></button><button type="button" class="remove-inspiration-btn" style="height:20px;width:20px;line-height:0px;padding-left:2px;"><i class="fa-solid fa-minus" style="color: #000000;"></i></button><span class="inspiration-span" style="margin-left:10px;">${currentInspiration}</span></div></div>`;
counterArea.after(newInspirationArea);
} else {
counterArea = $(html).find(".counters");
newInspirationArea = `<div class="counter flexrow new-inspiration"><h4>Inspiration</h4><div class="counter-value"><button type="button" class="add-inspiration-btn"><i class="fa-solid fa-plus" style="color: #000000;"></i></button><button type="button" class="remove-inspiration-btn"><i class="fa-solid fa-minus" style="color: #000000;"></i></button><span class="inspiration-span">${currentInspiration}</span></div></div>`;
counterArea.append(newInspirationArea);
}

$(counterArea)
$(html)
.find(".add-inspiration-btn")
.off("click")
.on("click", function () {
addInspiration(actorOwner, _sheet);
});
$(counterArea)
$(html)
.find(".remove-inspiration-btn")
.off("click")
.on("click", function () {
Expand All @@ -84,19 +90,39 @@ function renderNewInspoSheet(_sheet, html) {
}

function addInspiration(user, _sheet) {
if (!user) {
ui.notifications.error("Sheet has no owner assigned.");
return;
}
const maxInspo = game.settings.get("so-inspired", "maxInspiration");
const currentInspo = user.getFlag("so-inspired", "inspirationCount");

if (currentInspo < maxInspo) {
user.setFlag("so-inspired", "inspirationCount", currentInspo + 1);
ChatMessage.create({
user: user,
flavor: _sheet.actor.name + " has gained a point of inspiration!",
});
} else {
ChatMessage.create({
user: user,
flavor:
_sheet.actor.name +
" was granted inspiration, but can't have any more. Don't forget to use your inspiration!",
});
}

_sheet.render(true);
}

function removeInspiration(user, _sheet) {
const minInspo = 0;
const currentInspo = user.getFlag("so-inspired", "inspirationCount");
if (currentInspo > minInspo) {
user.setFlag("so-inspired", "inspirationCount", currentInspo - 1);
ChatMessage.create({
user: user,
flavor: _sheet.actor.name + " has used a point of inspiration!",
});
}
_sheet.render(true);
}
Expand Down

0 comments on commit b019175

Please sign in to comment.