-
Notifications
You must be signed in to change notification settings - Fork 68
/
genericActionHandler.js
123 lines (106 loc) · 4 KB
/
genericActionHandler.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import * as settings from "../settings.js";
export class GenericActionHandler {
baseHandler;
constructor(baseHandler) {
this.baseHandler = baseHandler;
}
addGenericCategories(token, actionList, isMultipleTokens) {
this._addConditions(token, actionList, isMultipleTokens);
this._addUtilities(token, actionList, isMultipleTokens);
}
/** @private */
_addConditions(token, actionList, isMultipleTokens) {}
/** @private */
_addUtilities(token, actionList, isMultipleTokens) {
if (settings.get("showUtilityCategory") === false) return;
let utilityCategory = actionList.categories.find((c) => c.id === "utility");
if (!utilityCategory) {
utilityCategory = this.baseHandler.initializeEmptyCategory("utility");
utilityCategory.name = this.baseHandler.i18n("tokenActionHud.utility");
actionList.categories.push(utilityCategory);
}
if (isMultipleTokens) {
const tokens = canvas.tokens.controlled;
this._addMultiUtilities(utilityCategory, tokens);
} else {
this._getUtilityList(utilityCategory, token.id);
}
}
/** @private */
_getUtilityList(utilityCategory, tokenId) {
let macroType = "utility";
// Token Subcategory
let tokenSubcategory = this.baseHandler.initializeEmptySubcategory();
// Toggle Combat
const inCombat = canvas.tokens.placeables.find((t) => t.id === tokenId).inCombat
const name = (inCombat)
? this.baseHandler.i18n("tokenActionHud.removeFromCombat")
: this.baseHandler.i18n("tokenActionHud.addToCombat");
let combatStateValue = [macroType, tokenId, "toggleCombat"].join(
this.baseHandler.delimiter
);
let combatAction = {
id: "toggleCombat",
encodedValue: combatStateValue,
name: name,
};
tokenSubcategory.actions.push(combatAction);
// Toggle Visibility
if (game.user.isGM) {
const hidden = canvas.tokens.placeables.find((t) => t.id === tokenId).document.hidden
const name = (hidden)
? this.baseHandler.i18n("tokenActionHud.makeVisible")
: this.baseHandler.i18n("tokenActionHud.makeInvisible");
let visbilityValue = [macroType, tokenId, "toggleVisibility"].join(
this.baseHandler.delimiter
);
let visibilityAction = {
id: "toggleVisibility",
encodedValue: visbilityValue,
name: name,
};
tokenSubcategory.actions.push(visibilityAction);
}
const tokenTitle = this.baseHandler.i18n("tokenActionHud.token")
this.baseHandler._combineSubcategoryWithCategory(utilityCategory, tokenTitle, tokenSubcategory);
}
/** @private */
_addMultiUtilities(utilityCategory, tokens) {
let macroType = "utility";
let tokenId = "multi";
// Token Subcategory
let tokenSubcategory = this.baseHandler.initializeEmptySubcategory();
// Toggle Combat
const inCombat = tokens.every((t) => t.inCombat);
const name = (inCombat)
? this.baseHandler.i18n("tokenActionHud.removeFromCombat")
: this.baseHandler.i18n("tokenActionHud.addToCombat");
let combatStateValue = [macroType, tokenId, "toggleCombat"].join(
this.baseHandler.delimiter
);
let combatAction = {
id: "toggleCombat",
encodedValue: combatStateValue,
name: name,
};
tokenSubcategory.actions.push(combatAction);
// Toggle Visibility
if (game.user.isGM) {
const hidden = tokens.every((t) => !t.document.hidden);
const name = (hidden)
? this.baseHandler.i18n("tokenActionHud.makeVisible")
: this.baseHandler.i18n("tokenActionHud.makeInvisible");
let visbilityValue = [macroType, tokenId, "toggleVisibility"].join(
this.baseHandler.delimiter
);
let visibilityAction = {
id: "toggleVisibility",
encodedValue: visbilityValue,
name: name,
};
tokenSubcategory.actions.push(visibilityAction);
}
const tokenTitle = this.baseHandler.i18n("tokenActionHud.token")
this.baseHandler._combineSubcategoryWithCategory(utilityCategory, tokenTitle, tokenSubcategory);
}
}