Skip to content

Commit

Permalink
Treat empty available Limited Uses as 0, fixes #41
Browse files Browse the repository at this point in the history
  • Loading branch information
illandril committed Dec 8, 2023
1 parent d8c57e4 commit 63b0da3
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions module/scripts/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,33 @@ export const showUses = (slotElem, uses) => {
let display = '';
if (typeof uses === 'number') {
hasUsesAvailable = uses > 0;
display = uses;
display = `${uses}`;
} else if (typeof uses === 'string') {
hasUsesAvailable = true;
display = uses;
} else if (typeof uses === 'object') {
if (typeof uses.available === 'number') {
hasUsesAvailable = uses.available !== 0;
showZeroUses = uses.showZeroUses;
display = uses.available;
display = `${uses.available}`;
} else if (typeof uses.consumed === 'number') {
if (typeof uses.maximum === 'number') {
hasUsesAvailable = uses.consumed < uses.maximum;
} else {
hasUsesAvailable = true;
}
display = uses.consumed;
display = `${uses.consumed}`;
} else if (uses.showZeroUses) {
hasUsesAvailable = false;
showZeroUses = true;
display = '0';
} else {
console.error('Unable to determine uses', uses);
display = '?';
}
if (getShowMax() && typeof uses.maximum === 'number') {
hasMaximum = true;
display += '/' + uses.maximum;
display = `${display}/${uses.maximum}`
}
}
usesDisplay.innerText = display;
Expand Down

0 comments on commit 63b0da3

Please sign in to comment.