Skip to content

Commit

Permalink
Fix combat tracker config and actorsDeadAtZero option (foundryvtt#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
In3luki authored and CarlosFdez committed May 29, 2024
1 parent a84a763 commit b4d0732
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
4 changes: 1 addition & 3 deletions src/module/actor/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1722,9 +1722,7 @@ class ActorPF2e<TParent extends TokenDocumentPF2e | null = TokenDocumentPF2e | n
if (combatant) {
combatant.toggleDefeated({ to: false });
} else {
for (const tokenDoc of this.getActiveTokens(false, true)) {
tokenDoc.update({ overlayEffect: "" });
}
this.toggleStatusEffect("dead");
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/scripts/hooks/close-combat-tracker-config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { htmlQuery } from "@util";

/** Add a deathIcon setting to the CombatTrackerConfig application */
export const CloseCombatTrackerConfig = {
listen: (): void => {
Hooks.on("closeCombatTrackerConfig", async (_app, $html): Promise<void> => {
const newIcon = String($html.find<HTMLInputElement>('input[name="deathIcon"]').val()).trim();
const html = $html[0];
const newIcon = htmlQuery<HTMLInputElement>(html, "file-picker")?.value;
if (newIcon && newIcon !== game.settings.get("pf2e", "deathIcon")) {
await game.settings.set("pf2e", "deathIcon", newIcon);
}

const currentDeadAtZero = game.settings.get("pf2e", "automation.actorsDeadAtZero");
const newDeadAtZero = String($html.find<HTMLSelectElement>('select[name="actorsDeadAtZero"]').val());
if (currentDeadAtZero !== newDeadAtZero) {
const newDeadAtZero = htmlQuery<HTMLSelectElement>(html, "select[name=actorsDeadAtZero]")?.value;
if (newDeadAtZero && currentDeadAtZero !== newDeadAtZero) {
await game.settings.set("pf2e", "automation.actorsDeadAtZero", newDeadAtZero);
}
});
Expand Down
5 changes: 5 additions & 0 deletions src/scripts/hooks/render-combat-tracker-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ export const RenderCombatTrackerConfig = {
values: {
deathIcon: game.settings.get("pf2e", "deathIcon"),
actorsDeadAtZero: game.settings.get("pf2e", "automation.actorsDeadAtZero"),
deadAtZeroOptions: [
{ value: "both", label: "PF2E.SETTINGS.Automation.ActorsDeadAtZero.Both" },
{ value: "npcsOnly", label: "PF2E.SETTINGS.Automation.ActorsDeadAtZero.NPCsOnly" },
{ value: "neither", label: "PF2E.SETTINGS.Automation.ActorsDeadAtZero.Neither" },
],
},
});
const tempElem = document.createElement("div");
Expand Down
9 changes: 2 additions & 7 deletions static/templates/sidebar/encounter-tracker/config.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@
<div class="form-group">
<label>{{localize "PF2E.SETTINGS.DeathIcon.Name"}}</label>
<div class="form-fields">
{{filePicker target="deathIcon" type="imagevideo"}}
<input class="image" type="text" name="deathIcon" placeholder="path/image.png" value="{{values.deathIcon}}" />
<file-picker name="deathIcon" type="imagevideo" value="{{values.deathIcon}}"></file-picker>
</div>
<p class="hint">{{localize "PF2E.SETTINGS.DeathIcon.Hint"}}</p>
</div>
<div class="form-group">
<label>{{localize "PF2E.SETTINGS.Automation.ActorsDeadAtZero.Name"}}</label>
<div class="form-fields">
<select name="actorsDeadAtZero">
{{#select values.actorsDeadAtZero}}
<option value="both">{{localize "PF2E.SETTINGS.Automation.ActorsDeadAtZero.Both"}}</option>
<option value="npcsOnly">{{localize "PF2E.SETTINGS.Automation.ActorsDeadAtZero.NPCsOnly"}}</option>
<option value="neither">{{localize "PF2E.SETTINGS.Automation.ActorsDeadAtZero.Neither"}}</option>
{{/select}}
{{selectOptions values.deadAtZeroOptions selected=values.actorsDeadAtZero localize=true}}
</select>
</div>
<p class="hint">{{localize "PF2E.SETTINGS.Automation.ActorsDeadAtZero.Hint"}}</p>
Expand Down

0 comments on commit b4d0732

Please sign in to comment.