Skip to content
26 changes: 26 additions & 0 deletions src/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,32 @@ export default class InitiativeTrackerSettings extends PluginSettingTab {
}
);
});
new Setting(additionalContainer)
.setName("Reveal AC of hurt creatures")
.setDesc(
"Reveal AC of creatures in Player View after they are first hit."
)
.addToggle((t) => {
t.setValue(this.plugin.data.displayCreatureACInPlayerView).onChange(
async (v) => {
this.plugin.data.displayCreatureACInPlayerView = v;
await this.plugin.saveSettings();
}
);
})
new Setting(additionalContainer)
.setName("Reveal AC For Creatures of Same Type")
.setDesc(
"Whenever the AC of a creature is revealed to players, also reveal the AC for all other creatures of the same type (i.e. all Goblins)."
)
.addToggle((t) => {
t.setValue(this.plugin.data.revealCreatureACForSameType).onChange(
async (v) => {
this.plugin.data.revealCreatureACForSameType = v;
await this.plugin.saveSettings();
}
);
})
new Setting(additionalContainer)
.setName("Roll HP for Creatures")
.setDesc(
Expand Down
2 changes: 2 additions & 0 deletions src/settings/settings.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export interface InitiativeTrackerData {
resolveTies: string;
useLegacy: boolean;
diplayPlayerHPValues: boolean;
displayCreatureACInPlayerView: boolean;
revealCreatureACForSameType: boolean;
rollHP: boolean;
builder: BuilderState;
descending: boolean;
Expand Down
25 changes: 25 additions & 0 deletions src/tracker/player/PlayerView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@
const friendIcon = (node: HTMLElement) => {
setIcon(node, FRIENDLY);
};

const showACColumn = (activeAndVisible: Creature[]) => {
// for the header, check if any creature has visible AC at the moment
const anyRevealed = activeAndVisible.some(
(creature) => creature.revealAc
);

// also check if general ac setting is enabled
return anyRevealed;
}

const showCreatureAc = (creature: Creature) => {
return creature.revealAc;
}

</script>

<table class="initiative-tracker-table" transition:fade>
Expand All @@ -55,6 +70,9 @@
<th class="left" style="width:30%"><strong>Name</strong></th>
<th style="width:15%" class="center"><strong use:hpIcon /></th>
<th><strong> Statuses </strong></th>
{#if showACColumn(activeAndVisible)}
<th><strong use:acIcon /></th>
{/if}
</thead>
<tbody>
{#each activeAndVisible as creature (creature.id)}
Expand Down Expand Up @@ -83,6 +101,13 @@
<td class="center">
{[...creature.status].map((s) => s.name).join(", ")}
</td>
{#if showACColumn(activeAndVisible)}
<td class="center">
{#if showCreatureAc(creature)}
<span class="armor-class">{@html creature.current_ac || creature.ac}</span>
{/if}
</td>
{/if}
</tr>
{/each}
</tbody>
Expand Down
25 changes: 25 additions & 0 deletions src/tracker/stores/tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type CreatureUpdate = {
//this is so dirty
set_hp?: number;
set_max_hp?: number;
reveal_ac?: boolean;
};
type CreatureUpdates = { creature: Creature; change: CreatureUpdate };
const modifier = Platform.isMacOS ? "Meta" : "Control";
Expand Down Expand Up @@ -176,6 +177,10 @@ function createTracker() {
creature.name = change.name;
creature.number = 0;
}

if (change.reveal_ac !== undefined) {
creature.revealAc = change.reveal_ac;
}
if (change.hp) {
// Reduce temp HP first
change.hp = Number(change.hp);
Expand Down Expand Up @@ -390,6 +395,7 @@ function createTracker() {
updateCreatureByName: (name: string, change: CreatureUpdate) =>
updateAndSave((creatures) => {
const creature = creatures.find((c) => c.name == name);

if (creature) {
if (!isNaN(Number(change.hp))) {
creature.hp = change.hp;
Expand Down Expand Up @@ -423,6 +429,9 @@ function createTracker() {
);
}
}
if (change.reveal_ac !== undefined) {
creature.revealAc = change.reveal_ac;
}
if (change.marker) {
creature.marker = change.marker;
}
Expand Down Expand Up @@ -539,6 +548,22 @@ function createTracker() {
Math.max(Math.abs(toAdd) * modifier, 1);
toAdd = roundHalf ? Math.trunc(toAdd) : toAdd;
message.hp = toAdd;

// reveal ac to players, if setting for auto reveal is enabled
if (toAdd < 0 && _settings.displayCreatureACInPlayerView) {
const creatures = get(ordered);

creatures
.filter(c => {
if (_settings.revealCreatureACForSameType) {
return c.name === creature.name;
}

return c === creature;
})
.map(creature => updates.push({creature, change: {reveal_ac: true}}));
};

if (maxHpDamage) {
message.max = true;
change.max = toAdd;
Expand Down
39 changes: 39 additions & 0 deletions src/tracker/ui/creatures/CreatureControls.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import type InitiativeTracker from "src/main";
import { tracker } from "src/tracker/stores/tracker";

const { data } = tracker;
const dispatch = createEventDispatcher();

export let creature: Creature;
Expand Down Expand Up @@ -45,6 +46,44 @@
});
});
}

const revealAcMenuItemTitles = $data.revealCreatureACForSameType ? {
hide: "Hide AC of Creature Type",
reveal: "Reveal AC of Creature Type",
} : {
hide: "Hide AC of Creature",
reveal: "Reveal AC of Creature",
};

// Get right menu item title for this creature
const menuItemTitle = revealAcMenuItemTitles[
creature.revealAc ? 'hide' : 'reveal'
];

const reveal_ac = !creature.revealAc;

menu.addItem((item) => {
item.setTitle(menuItemTitle)
.onClick(() => {
tracker.getOrderedCreatures()
.filter((c) => {
if ($data.revealCreatureACForSameType) {
return c.name === creature.name
}

return c === creature;
})
.map((c) => {
tracker.updateCreatures({
creature: c,
change: { reveal_ac }
});
});

tracker.updateAndSave();
});
});

menu.addItem((item) => {
item.setIcon("pencil")
.setTitle("Edit")
Expand Down
2 changes: 2 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export const DEFAULT_SETTINGS: InitiativeTrackerData = {
players: [],
parties: [],
defaultParty: null,
displayCreatureACInPlayerView: false,
revealCreatureACForSameType: false,
statuses: [...Conditions],
unconsciousId: "Unconscious",
version: [],
Expand Down
1 change: 1 addition & 0 deletions src/utils/creature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class Creature {
status: Set<Condition> = new Set();
marker: string;
initiative: number;
revealAc: boolean = false;
manualOrder: number;
static: boolean = false;
source: string | string[];
Expand Down