diff --git a/assets/icons/evil.svg b/assets/icons/evil.svg
new file mode 100644
index 0000000..5d9fb11
--- /dev/null
+++ b/assets/icons/evil.svg
@@ -0,0 +1,4 @@
+
+
diff --git a/assets/icons/hero.svg b/assets/icons/hero.svg
new file mode 100644
index 0000000..55de62b
--- /dev/null
+++ b/assets/icons/hero.svg
@@ -0,0 +1,6 @@
+
+
diff --git a/module/Apps/sidebar/CombatTracker.mjs b/module/Apps/sidebar/CombatTracker.mjs
index 8cffd77..d976867 100644
--- a/module/Apps/sidebar/CombatTracker.mjs
+++ b/module/Apps/sidebar/CombatTracker.mjs
@@ -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 ``;
+};
+
+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);
};
};