Skip to content

Commit

Permalink
fix: improved error handling around dice roller
Browse files Browse the repository at this point in the history
  • Loading branch information
valentine195 committed Dec 8, 2021
1 parent 9e29bda commit b0058c6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/view/Statblock.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
export let canSave: boolean;
let canExport = monster.export ?? plugin.settings.export;
let canDice = monster.dice ?? plugin.settings.useDice;
let canDice =
plugin.canUseDiceRoller && (monster.dice ?? plugin.settings.useDice);
let canRender = monster.render ?? plugin.settings.renderDice;
setContext<StatBlockPlugin>("plugin", plugin);
Expand Down
12 changes: 9 additions & 3 deletions src/view/ui/DiceRoll.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
export let text: string;
export let original: string | number = text;
const dice = getContext<boolean>("dice");
const plugin = getContext<StatBlockPlugin>("plugin");
const render = getContext<boolean>("render");
Expand All @@ -23,7 +25,7 @@
});
let roller: StackRoller = null;
if (!roller && plugin.canUseDiceRoller) {
if (!roller && dice) {
roller = plugin.getRoller(`${text}`) as StackRoller;
}
Expand Down Expand Up @@ -56,12 +58,16 @@
});
const rollerEl = (node: HTMLElement) => {
node.appendChild(roller.containerEl);
if (!roller || !roller.containerEl) {
node.setText(`${original}`);
} else {
node.appendChild(roller.containerEl);
}
};
</script>

{#key error}
{#if error}
{#if error || !dice}
{text}
{:else}
<span class="roller-result" use:rollerEl />
Expand Down

0 comments on commit b0058c6

Please sign in to comment.