Skip to content

Commit

Permalink
fix: Respect never rolling initiative when launching encounter
Browse files Browse the repository at this point in the history
  • Loading branch information
valentine195 committed Sep 20, 2023
1 parent 3890ec6 commit 1ab1271
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/tracker/stores/tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -707,9 +707,34 @@ function createTracker() {
$round.set(state?.round ?? 1);
$state.set(state?.state ?? false);
$name.set(state?.name ?? null);
creatures = state?.creatures

if (!state?.creatures) {
/**
* New encounter button was clicked, only maintain the players.
*/
creatures = creatures.filter((c) => c.player);
} else {
/**
* Encounter is being started. Keep any pre-existing players that are incoming.
*/
const tempCreatureArray: Creature[] = [];
for (const creature of state.creatures) {
const existingPlayer = creatures.find(
(c) => c.player && c.id === creature.id
);
if (existingPlayer) {
tempCreatureArray.push(existingPlayer);
} else {
tempCreatureArray.push(
Creature.fromJSON(creature, plugin)
);
}
}
creatures = tempCreatureArray;
}
/* creatures = state?.creatures
? state.creatures.map((c) => Creature.fromJSON(c, plugin))
: creatures.filter((c) => c.player);
: creatures.filter((c) => c.player); */
if (!state || state?.roll) {
rollIntiative(plugin, creatures);
}
Expand Down

0 comments on commit 1ab1271

Please sign in to comment.