Skip to content

Commit

Permalink
feat: Temporarily change AC on the fly (#118)
Browse files Browse the repository at this point in the history
* feat: Temporarily change AC on the fly

By clicking on the AC field of creatures you can type a new value directly in.
Values differing from the creatures' original AC will be shown in **bold**, and hovering will display a label with the original value.
Although not exactly what they asked for, I believe this would help with [#88].

Small changes have been made to the selection boxes for opening the creature statblock, adjusting HP/status and the newly added AC feature. [#96]

To reflect strings being allowed in the AC field, the number validation for the AC field of players when setting up for parties has been removed. [#103]

Check-in to: master

* Commonizes AC editing with HP/Status

* Separate menu for AC input

* fix: can switch between hp and ac

---------

Co-authored-by: Jeremy Valentine <38669521+valentine195@users.noreply.github.com>
  • Loading branch information
SondreElg and valentine195 authored Apr 25, 2023
1 parent c328623 commit ac03929
Show file tree
Hide file tree
Showing 13 changed files with 346 additions and 208 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ The temp HP and max HP modifiers also support the "-" symbol to remove temp HP a

If a creature's `hit_dice` property is set (whether from the add menu or in the bestiary), there is the option to Roll for HP. This can be set globally in settings, per-encounter, or when adding creatures to a combat.

### AC

Creatures can have their ACs temporarily adjusted for effects such as the Shield spell by typing directly into the AC field.

### Actions

Creatures may be edited, disabled / removed from the combat in the `Actions` menu located to the right of each creature.
Expand Down
3 changes: 3 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export interface CreatureState extends HomebrewCreature {
currentMaxHP: number;
currentHP: number;
tempHP: number;
currentAC: number | string;
initiative: number;
player: boolean;
xp: number;
Expand Down Expand Up @@ -206,6 +207,8 @@ export interface UpdateLogMessage {
max: boolean;
saved: boolean;
unc: boolean;
ac: string;
ac_add: boolean;
}

export interface BuilderPartyPlayer {
Expand Down
28 changes: 19 additions & 9 deletions src/logger/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export default class Logger {
async setFile() {
const file = (await this.adapter.exists(normalizePath(this.logFile)))
? await this.vault.getAbstractFileByPath(
normalizePath(this.logFile)
)
normalizePath(this.logFile)
)
: await this.vault.create(this.logFile, ``);

if (file instanceof TFile) {
Expand All @@ -38,7 +38,7 @@ export default class Logger {
return this.file;
}
private file: TFile;
constructor(public plugin: InitiativeTracker) {}
constructor(public plugin: InitiativeTracker) { }
get enabled() {
return this.plugin.data.logging;
}
Expand Down Expand Up @@ -137,26 +137,36 @@ export default class Logger {
if (message.hp) {
if (message.temp) {
perCreature.push(
`${
message.name
`${message.name
} gained ${message.hp.toString()} temporary HP`
);
} else if (message.hp < 0) {
perCreature.push(
`${message.name} took ${(
-1 * message.hp
).toString()} damage${
message.unc ? " and was knocked unconscious" : ""
).toString()} damage${message.unc ? " and was knocked unconscious" : ""
}`
);
} else if (message.hp > 0) {
perCreature.push(
`${
message.name
`${message.name
} was healed for ${message.hp.toString()} HP`
);
}
}
if (message.ac) {
if (perCreature.length && !message.status) {
perCreature.push("and");
} else if (perCreature.length) {
perCreature.push(",");
}

if (message.ac_add) {
perCreature.push(`${message.name} added ${message.ac} to AC`);
} else {
perCreature.push(`${message.name} AC set to ${message.ac}`);
}
}
if (message.status) {
if (perCreature.length) {
perCreature.push("and");
Expand Down
18 changes: 2 additions & 16 deletions src/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,6 @@ class NewPlayerModal extends Modal {
let nameInput: InputValidate,
levelInput: InputValidate,
hpInput: InputValidate,
acInput: InputValidate,
modInput: InputValidate;

new Setting(contentEl)
Expand Down Expand Up @@ -1202,21 +1201,9 @@ class NewPlayerModal extends Modal {
});
});
new Setting(contentEl).setName("Armor Class").addText((t) => {
acInput = {
input: t.inputEl,
validate: (i) => {
let error = false;
if (isNaN(Number(i.value))) {
t.inputEl.addClass("has-error");
error = true;
}
return error;
}
};
t.setValue(`${this.player.ac ?? ""}`);
t.onChange((v) => {
t.inputEl.removeClass("has-error");
this.player.ac = Number(v);
this.player.ac = v;
});
});
new Setting(contentEl)
Expand Down Expand Up @@ -1281,7 +1268,6 @@ class NewPlayerModal extends Modal {
.onClick(async () => {
let error = this.validateInputs(
nameInput,
acInput,
hpInput,
modInput
);
Expand All @@ -1304,7 +1290,7 @@ class NewPlayerModal extends Modal {
return b;
});

this.validateInputs(nameInput, acInput, hpInput, modInput);
this.validateInputs(nameInput, hpInput, modInput);
}
validateInputs(...inputs: InputValidate[]) {
let error = false;
Expand Down
15 changes: 14 additions & 1 deletion src/tracker/player/PlayerView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { fade } from "svelte/transition";
import { SyncLoader } from "svelte-loading-spinners";
import { HP, INITIATIVE } from "src/utils";
import { AC, HP, INITIATIVE } from "src/utils";
import type { Creature } from "src/utils/creature";
import { createEventDispatcher } from "svelte";
Expand All @@ -13,6 +13,9 @@
const hpIcon = (node: HTMLElement) => {
setIcon(node, HP);
};
const acIcon = (node: HTMLElement) => {
setIcon(node, AC);
};
const iniIcon = (node: HTMLElement) => {
setIcon(node, INITIATIVE);
};
Expand Down Expand Up @@ -48,6 +51,7 @@
<th style="width:5%"><strong use:iniIcon /></th>
<th class="left" style="width:30%"><strong>Name</strong></th>
<th style="width:15%" class="center"><strong use:hpIcon /></th>
<th style="width:15%" class="center"><strong use:acIcon /></th>
<th><strong> Statuses </strong></th>
</thead>
<tbody>
Expand All @@ -67,6 +71,12 @@
<span>{getHpStatus(creature.hp, creature.max)}</span>
{/if}
</td>
<td
class="ac center"
class:dirty-ac={creature.current_ac != creature.ac}
>
<span>{creature.current_ac ?? ""}</span>
</td>
<td class="center">
{[...creature.status].map((s) => s.name).join(", ")}
</td>
Expand Down Expand Up @@ -118,4 +128,7 @@
:global(.theme-dark) .active {
background-color: rgba(255, 255, 255, 0.1);
}
.dirty-ac {
font-weight: var(--font-bold);
}
</style>
Loading

0 comments on commit ac03929

Please sign in to comment.