Skip to content

Commit

Permalink
fix: better handling for multiple modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
valentine195 committed May 3, 2023
1 parent b1e6b00 commit 6a866f6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default class InitiativeTracker extends Plugin {
}
let dice = this.data.initiative;
if (typeof modifier == "number") {
dice = dice.replace(/%mod\d?%/g, `(${modifier})`);
dice = dice.replace(/%mod\d?%/g, `${modifier}`);
} else {
for (let i = 0; i < modifier.length; i++) {
dice = dice.replace(`%mod${i + 1}%`, `${modifier[i]}`);
Expand Down
11 changes: 9 additions & 2 deletions src/tracker/ui/create/Create.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
creature = c;
});
let modifier = JSON.stringify(creature.modifier ?? 0);
const saveButton = (node: HTMLElement) => {
new ExtraButtonComponent(node)
.setTooltip("Add Creature")
Expand Down Expand Up @@ -75,7 +77,6 @@
if (!creature.modifier) {
creature.modifier = 0;
}
creature.modifier = JSON.parse(`${creature.modifier}`);
if (
creature.initiative <= 0 ||
creature.initiative == null ||
Expand Down Expand Up @@ -146,6 +147,12 @@
.setValue(creature.friendly)
.onChange((v) => (creature.friendly = v));
};
$: {
try {
creature.modifier = JSON.parse(`${modifier}`);
} catch (e) {}
}
</script>

<div class="initiative-tracker-editor">
Expand Down Expand Up @@ -208,7 +215,7 @@
<div>
<label for="add-mod">Modifier</label>
<input
bind:value={creature.modifier}
bind:value={modifier}
id="add-mod"
type="text"
name="add-mod"
Expand Down
2 changes: 0 additions & 2 deletions src/tracker/ui/create/Creator.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
creature.dirty_ac = false;
}
creature.modifier = JSON.parse(`${creature.modifier}`);
tracker.replace(creature, $editing);
} else {
const creatures = $adding.flatMap(([creature, amount]) =>
Expand Down

0 comments on commit 6a866f6

Please sign in to comment.