This repository has been archived by the owner on Feb 5, 2022. It is now read-only.
forked from mclemente/fvtt-initiative-double-click
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCombat.js
47 lines (44 loc) · 2.08 KB
/
Combat.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class FurnaceCombatQoL {
static renderCombatTracker(tracker, html, data) {
if (game.user.role < parseInt(game.settings.get("initiative-double-click","player-access")) ) return;
html.find(".token-initiative").off("click").on("click", FurnaceCombatQoL._onInitiativeDblClick)
for (let combatant of html.find("#combat-tracker li.combatant")) {
if (combatant.classList.contains("active"))
break;
combatant.classList.add("turn-done");
}
}
static _onInitiativeDblClick(event) {
event.stopPropagation();
event.preventDefault();
let html = $(event.target).closest(".combatant")
let cid = html.data("combatant-id")
let initiative = html.find(".token-initiative")
let combatant = game.combat.combatants.get(cid)
if (!combatant.isOwner) return;
let input = $(`<input class="initiative" style="width: 90%" value="${combatant.initiative}"/>`)
initiative.off("dblclick")
initiative.empty().append(input)
input.focus().select()
input.on('change', ev => game.combat.updateCombatant({ _id: cid, initiative: input.val() }))
input.on('focusout', ev => game.combats.render())
}
}
Hooks.on('renderCombatTracker', FurnaceCombatQoL.renderCombatTracker)
Hooks.once("init", () => {
game.settings.register("initiative-double-click", "player-access", {
name: game.i18n.localize("initiative-double-click.settings.player-access.name"),
hint: game.i18n.localize("initiative-double-click.settings.player-access.hint"),
scope: "world",
config: true,
type: String,
default: "4",
choices: {
"0": "initiative-double-click.settings.player-access.roles.none",
"1": "initiative-double-click.settings.player-access.roles.player",
"2": "initiative-double-click.settings.player-access.roles.trusted",
"3": "initiative-double-click.settings.player-access.roles.assistant",
"4": "initiative-double-click.settings.player-access.roles.gamemaster"
}
});
});