Skip to content

Commit

Permalink
fix: updateCreatureByName accepts a status array now
Browse files Browse the repository at this point in the history
  • Loading branch information
valentine195 committed May 13, 2023
1 parent 4d36f25 commit 7e8cf1f
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/tracker/stores/tracker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Creature } from "../../utils/creature";
import { Creature, getId } from "../../utils/creature";
import type InitiativeTracker from "../../main";
import { derived, get, Updater, Writable, writable } from "svelte/store";
import { equivalent } from "../../encounter";
Expand Down Expand Up @@ -306,7 +306,7 @@ function createTracker() {
updateTarget,
updateCreatures,
updateCreatureByName: (name: string, change: CreatureUpdate) =>
update((creatures) => {
updateAndSave((creatures) => {
const creature = creatures.find((c) => c.name == name);
if (creature) {
if (!isNaN(Number(change.hp))) {
Expand Down Expand Up @@ -371,6 +371,25 @@ function createTracker() {
if ("enabled" in change) {
creature.enabled = change.enabled;
}
if (Array.isArray(change.status) && change.status?.length) {
for (const status of change.status) {
if (typeof status == "string") {
let cond = _settings.statuses.find(
(c) => c.name == status
) ?? {
name: status,
description: "",
id: getId()
};
creature.status.add(cond);
} else if (
typeof status == "object" &&
status.name?.length
) {
creature.status.add(status as Condition);
}
}
}
}

return creatures;
Expand Down

0 comments on commit 7e8cf1f

Please sign in to comment.