Add way to change whether heroes or geist go first in a combat
This commit is contained in:
parent
2a4ba73934
commit
5d8a4495a1
3 changed files with 65 additions and 3 deletions
|
|
@ -1,6 +1,38 @@
|
|||
const { CombatTracker } = foundry.applications.sidebar.tabs;
|
||||
|
||||
function createButtonInnerHTML() {
|
||||
const whoFirst = game.settings.get(`ripcrypt`, `whoFirst`);
|
||||
let icon = `evil`;
|
||||
let ariaLabel = `Geists go first, click to make heroes go first`;
|
||||
|
||||
if (whoFirst === `friendly`) {
|
||||
icon = `hero`;
|
||||
ariaLabel = `Heroes go first, click to make geists go first`;
|
||||
};
|
||||
|
||||
return `<rc-icon
|
||||
name="icons/${icon}"
|
||||
var:fill="currentColor"
|
||||
aria-label="${ariaLabel}"
|
||||
></rc-icon>`;
|
||||
};
|
||||
|
||||
function createButtonTooltip() {
|
||||
const whoFirst = game.settings.get(`ripcrypt`, `whoFirst`);
|
||||
if (whoFirst === `friendly`) {
|
||||
return `Heroes currently go first`;
|
||||
};
|
||||
return `Geists currently go first`;
|
||||
};
|
||||
|
||||
export class RipCryptCombatTracker extends CombatTracker {
|
||||
|
||||
static DEFAULT_OPTIONS = {
|
||||
actions: {
|
||||
toggleFirst: this.#toggleFirst,
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Changes the way the combat tracker renders combatant rows to account for
|
||||
* multiple combatants being in the same combat "group", thus all going at the
|
||||
|
|
@ -28,10 +60,30 @@ export class RipCryptCombatTracker extends CombatTracker {
|
|||
async _onRender(...args) {
|
||||
await super._onRender(...args);
|
||||
|
||||
const spacer = document.createElement(`div`);
|
||||
spacer.classList.add(`spacer`);
|
||||
|
||||
const button = document.createElement(`button`);
|
||||
button.classList.add(`inline-control`, `combat-control`, `icon`);
|
||||
button.type = `button`;
|
||||
button.dataset.tooltip = createButtonTooltip();
|
||||
button.dataset.action = `toggleFirst`;
|
||||
button.innerHTML = createButtonInnerHTML();
|
||||
button.disabled = !game.user.isGM;
|
||||
|
||||
// Purge the combat controls that I don't want to exist because they don't
|
||||
// make sense in the system.
|
||||
this.element?.querySelector(`[data-action="resetAll"]`)?.remove();
|
||||
this.element?.querySelector(`[data-action="rollNPC"]`)?.remove();
|
||||
this.element?.querySelector(`[data-action="rollAll"]`)?.remove();
|
||||
this.element?.querySelector(`[data-action="rollNPC"]`)?.replaceWith(spacer.cloneNode(true));
|
||||
this.element?.querySelector(`[data-action="rollAll"]`)?.replaceWith(button.cloneNode(true));
|
||||
};
|
||||
|
||||
static async #toggleFirst(_event, element) {
|
||||
game.tooltip.deactivate();
|
||||
const whoFirst = game.settings.get(`ripcrypt`, `whoFirst`);
|
||||
const otherFirst = whoFirst === `friendly` ? `hostile` : `friendly`;
|
||||
await game.settings.set(`ripcrypt`, `whoFirst`, otherFirst);
|
||||
element.innerHTML = createButtonInnerHTML();
|
||||
element.dataset.tooltip = createButtonTooltip();
|
||||
game.tooltip.activate(element);
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue