Skip to content

Commit

Permalink
fix: handle players added directly in encounters, not just through pa…
Browse files Browse the repository at this point in the history
…rties (#197)
  • Loading branch information
valentine195 committed Aug 16, 2023
1 parent 51aed21 commit 4317e07
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
4 changes: 4 additions & 0 deletions src/encounter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ export class EncounterParser {
)
);
}
console.log(
"🚀 ~ file: index.ts:158 ~ playersToReturn:",
playersToReturn
);
return Array.from(new Set(playersToReturn));
}
async parseRawCreatures(rawMonsters: RawCreatureArray) {
Expand Down
51 changes: 34 additions & 17 deletions src/encounter/ui/Encounter.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,16 @@
})
.flat();
const transformedCreatures: CreatureState[] = [];
for (const creature of [
...plugin.getPlayersForParty(party),
...creatures
]) {
const combinedPlayers = [
...plugin.getPlayerNamesForParty(party),
...players
];
const playersForEncounter: Creature[] = [];
for (const name of new Set(combinedPlayers)) {
playersForEncounter.push(plugin.getPlayerByName(name));
}
for (const creature of [...playersForEncounter, ...creatures]) {
transformedCreatures.push(creature.toJSON());
}
tracker.new(plugin, {
Expand Down Expand Up @@ -194,7 +200,10 @@
>
<CreatureComponent
{creature}
xp={rpgSystem.getCreatureDifficulty(creature, playerLevels)}
xp={rpgSystem.getCreatureDifficulty(
creature,
playerLevels
)}
shouldShowRoll={!allRolling && rollHP}
{count}
>
Expand All @@ -218,17 +227,25 @@
aria-label={difficulty.summary}
class={difficulty.cssClass}
>
<strong class="difficulty-label">{difficulty.displayName}</strong>
<span class="xp-parent difficulty">
<span class="paren left">(</span>
<span class="xp-container">
{#if difficulty.value > 0}
<span class="xp number">{rpgSystem.formatDifficultyValue(difficulty.value)}</span>
<span class="xp text">{rpgSystem.valueUnit}</span>
{/if}
</span>
<span class="paren right">)</span>
</span>
<strong class="difficulty-label"
>{difficulty.displayName}</strong
>
<span class="xp-parent difficulty">
<span class="paren left">(</span>
<span class="xp-container">
{#if difficulty.value > 0}
<span class="xp number"
>{rpgSystem.formatDifficultyValue(
difficulty.value
)}</span
>
<span class="xp text"
>{rpgSystem.valueUnit}</span
>
{/if}
</span>
<span class="paren right">)</span>
</span>
</span>
{/if}
</div>
Expand Down Expand Up @@ -274,7 +291,7 @@
color: green;
}
.trivial .difficulty-label {
color: #AAAAAA;
color: #aaaaaa;
}
.icons {
display: flex;
Expand Down
4 changes: 4 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type {
HomebrewCreature,
InitiativeTrackerData,
InitiativeViewState,
Party,
SRDMonster
} from "../index";
import type { Plugins, StackRoller } from "obsidian-overload";
Expand Down Expand Up @@ -100,6 +101,9 @@ export default class InitiativeTracker extends Plugin {
if (!this.players.has(name)) return new Creature({ name });
return Creature.from(this.players.get(name));
}
getPlayerNamesForParty(party: string): string[] {
return this.data.parties?.find((p) => p.name === party)?.players ?? [];
}
getPlayersForParty(party: string) {
return (
this.data.parties
Expand Down

0 comments on commit 4317e07

Please sign in to comment.