Fix combat tracker
parent
6b5011cfd6
commit
7088263c05
|
@ -4,7 +4,7 @@ export class AcksCombat {
|
||||||
data.combatants = [];
|
data.combatants = [];
|
||||||
let groups = {};
|
let groups = {};
|
||||||
combat.data.combatants.forEach((cbt) => {
|
combat.data.combatants.forEach((cbt) => {
|
||||||
groups[cbt.flags.acks.group] = { present: true };
|
groups[cbt.data.flags.acks.group] = { present: true };
|
||||||
data.combatants.push(cbt);
|
data.combatants.push(cbt);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ export class AcksCombat {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
data.combatants[i].initiative =
|
data.combatants[i].initiative =
|
||||||
groups[data.combatants[i].flags.acks.group].initiative;
|
groups[data.combatants[i].data.flags.acks.group].initiative;
|
||||||
if (data.combatants[i].actor.data.data.isSlow) {
|
if (data.combatants[i].actor.data.data.isSlow) {
|
||||||
data.combatants[i].initiative -= 1;
|
data.combatants[i].initiative -= 1;
|
||||||
}
|
}
|
||||||
|
@ -92,20 +92,21 @@ export class AcksCombat {
|
||||||
html.find(".combatant").each((_, ct) => {
|
html.find(".combatant").each((_, ct) => {
|
||||||
// Append spellcast and retreat
|
// Append spellcast and retreat
|
||||||
const controls = $(ct).find(".combatant-controls .combatant-control");
|
const controls = $(ct).find(".combatant-controls .combatant-control");
|
||||||
const cmbtant = object.combat.getCombatant(ct.dataset.combatantId);
|
const cmbtant = game.combat.combatants.get(ct.dataset.combatantId);
|
||||||
const moveActive = cmbtant.flags.acks && cmbtant.flags.acks.moveInCombat ? "active" : "";
|
const moveActive = cmbtant.data.flags.acks?.moveInCombat ? "active" : "";
|
||||||
controls.eq(1).after(
|
controls.eq(1).after(
|
||||||
`<a class='combatant-control move-combat ${moveActive}'><i class='fas fa-running'></i></a>`
|
`<a class='combatant-control move-combat ${moveActive}'><i class='fas fa-running'></i></a>`
|
||||||
);
|
);
|
||||||
const spellActive = cmbtant.flags.acks && cmbtant.flags.acks.prepareSpell ? "active" : "";
|
const spellActive = cmbtant.data.flags.acks?.prepareSpell ? "active" : "";
|
||||||
controls.eq(1).after(
|
controls.eq(1).after(
|
||||||
`<a class='combatant-control prepare-spell ${spellActive}'><i class='fas fa-magic'></i></a>`
|
`<a class='combatant-control prepare-spell ${spellActive}'><i class='fas fa-magic'></i></a>`
|
||||||
);
|
);
|
||||||
const holdActive = cmbtant.flags.acks && cmbtant.flags.acks.holdTurn ? "active" : "";
|
const holdActive = cmbtant.data.flags.acks?.holdTurn ? "active" : "";
|
||||||
controls.eq(1).after(
|
controls.eq(1).after(
|
||||||
`<a class='combatant-control hold-turn ${holdActive}'><i class='fas fa-pause-circle'></i></a>`
|
`<a class='combatant-control hold-turn ${holdActive}'><i class='fas fa-pause-circle'></i></a>`
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
AcksCombat.announceListener(html);
|
AcksCombat.announceListener(html);
|
||||||
|
|
||||||
let init = game.settings.get("acks", "initiative") === "group";
|
let init = game.settings.get("acks", "initiative") === "group";
|
||||||
|
@ -128,7 +129,7 @@ export class AcksCombat {
|
||||||
|
|
||||||
// Get group color
|
// Get group color
|
||||||
const cmbtant = object.combat.getCombatant(ct.dataset.combatantId);
|
const cmbtant = object.combat.getCombatant(ct.dataset.combatantId);
|
||||||
let color = cmbtant.flags.acks.group;
|
let color = cmbtant.data.flags.acks.group;
|
||||||
|
|
||||||
// Append colored flag
|
// Append colored flag
|
||||||
let controls = $(ct).find(".combatant-controls");
|
let controls = $(ct).find(".combatant-controls");
|
||||||
|
@ -155,7 +156,7 @@ export class AcksCombat {
|
||||||
ct.initiative &&
|
ct.initiative &&
|
||||||
ct.initiative != "-789.00" &&
|
ct.initiative != "-789.00" &&
|
||||||
ct._id != data._id &&
|
ct._id != data._id &&
|
||||||
ct.flags.acks.group == combatant.flags.acks.group
|
ct.data.flags.acks.group == combatant.data.flags.acks.group
|
||||||
) {
|
) {
|
||||||
groupInit = ct.initiative;
|
groupInit = ct.initiative;
|
||||||
// Set init
|
// Set init
|
||||||
|
@ -166,32 +167,37 @@ export class AcksCombat {
|
||||||
}
|
}
|
||||||
|
|
||||||
static announceListener(html) {
|
static announceListener(html) {
|
||||||
html.find(".combatant-control.hold-turn").click((ev) => {
|
html.find(".combatant-control.hold-turn").click(async (ev) => {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
// Toggle hold announcement
|
// Toggle hold announcement
|
||||||
let id = $(ev.currentTarget).closest(".combatant")[0].dataset.combatantId;
|
const id = $(ev.currentTarget).closest(".combatant")[0].dataset.combatantId;
|
||||||
let isActive = ev.currentTarget.classList.contains('active');
|
const isActive = ev.currentTarget.classList.contains('active');
|
||||||
game.combat.updateCombatant({
|
const combatant = game.combat.combatants.get(id);
|
||||||
|
await combatant.update({
|
||||||
_id: id,
|
_id: id,
|
||||||
flags: { acks: { holdTurn: !isActive } },
|
flags: { acks: { holdTurn: !isActive } },
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
html.find(".combatant-control.prepare-spell").click((ev) => {
|
|
||||||
|
html.find(".combatant-control.prepare-spell").click(async (ev) => {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
// Toggle spell announcement
|
// Toggle spell announcement
|
||||||
let id = $(ev.currentTarget).closest(".combatant")[0].dataset.combatantId;
|
const id = $(ev.currentTarget).closest(".combatant")[0].dataset.combatantId;
|
||||||
let isActive = ev.currentTarget.classList.contains('active');
|
const isActive = ev.currentTarget.classList.contains('active');
|
||||||
game.combat.updateCombatant({
|
const combatant = game.combat.combatants.get(id);
|
||||||
|
await combatant.update({
|
||||||
_id: id,
|
_id: id,
|
||||||
flags: { acks: { prepareSpell: !isActive } },
|
flags: { acks: { prepareSpell: !isActive } },
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
html.find(".combatant-control.move-combat").click((ev) => {
|
|
||||||
|
html.find(".combatant-control.move-combat").click(async (ev) => {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
// Toggle retreat announcement
|
// Toggle retreat announcement
|
||||||
let id = $(ev.currentTarget).closest(".combatant")[0].dataset.combatantId;
|
const id = $(ev.currentTarget).closest(".combatant")[0].dataset.combatantId;
|
||||||
let isActive = ev.currentTarget.classList.contains('active');
|
const isActive = ev.currentTarget.classList.contains('active');
|
||||||
game.combat.updateCombatant({
|
const combatant = game.combat.combatants.get(id);
|
||||||
|
await combatant.update({
|
||||||
_id: id,
|
_id: id,
|
||||||
flags: { acks: { moveInCombat: !isActive } },
|
flags: { acks: { moveInCombat: !isActive } },
|
||||||
});
|
});
|
||||||
|
@ -200,20 +206,22 @@ export class AcksCombat {
|
||||||
|
|
||||||
static addListeners(html) {
|
static addListeners(html) {
|
||||||
// Cycle through colors
|
// Cycle through colors
|
||||||
html.find(".combatant-control.flag").click((ev) => {
|
html.find(".combatant-control.flag").click(async (ev) => {
|
||||||
if (!game.user.isGM) {
|
if (!game.user.isGM) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let currentColor = ev.currentTarget.style.color;
|
const currentColor = ev.currentTarget.style.color;
|
||||||
let colors = Object.keys(CONFIG.ACKS.colors);
|
const colors = Object.keys(CONFIG.ACKS.colors);
|
||||||
let index = colors.indexOf(currentColor);
|
let index = colors.indexOf(currentColor);
|
||||||
if (index + 1 == colors.length) {
|
if (index + 1 == colors.length) {
|
||||||
index = 0;
|
index = 0;
|
||||||
} else {
|
} else {
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
let id = $(ev.currentTarget).closest(".combatant")[0].dataset.combatantId;
|
|
||||||
game.combat.updateCombatant({
|
const id = $(ev.currentTarget).closest(".combatant")[0].dataset.combatantId;
|
||||||
|
const combatant = game.combat.combatants.get(id);
|
||||||
|
await combatant.update({
|
||||||
_id: id,
|
_id: id,
|
||||||
flags: { acks: { group: colors[index] } },
|
flags: { acks: { group: colors[index] } },
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue