-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteraction.js
More file actions
51 lines (46 loc) · 2.04 KB
/
Copy pathinteraction.js
File metadata and controls
51 lines (46 loc) · 2.04 KB
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
import { MODULE } from "./store.js";
import { openProxy, proxyChoices } from "./player.js";
export function playerProxy(actor) {
return !game.user.isGM && proxyChoices(actor).length > 0;
}
export function addProxyButton(app, actor, buttons) {
if (!playerProxy(actor) || buttons.some(button => button.class === "vr-ledger")) return;
buttons.unshift({ label: "Reputations", class: "vr-ledger", icon: "fas fa-book-open", onclick: async () => {
const interaction = await openProxy(actor);
if (interaction) await app.close();
return interaction;
} });
}
function directProxy(token) {
if (!playerProxy(token.actor) || token.document.hidden || !token.isVisible) return false;
return !(game.modules.get("item-piles")?.active && game.itempiles?.API?.isValidItemPile(token.document)); // Item Piles keeps its own double click
}
export function registerPlayerInteraction() {
const wrappers = {
_canView(wrapped, ...args) { // Lets players view a proxy they do not own
return directProxy(this) || wrapped(...args);
},
_onClickLeft2(wrapped, ...args) { // Double click opens the proxy dialog
return directProxy(this) ? openProxy(this.actor) : wrapped(...args);
}
};
for (const [method, wrapper] of Object.entries(wrappers)) { // libWrapper when present, manual prototype patch otherwise
if (globalThis.libWrapper) libWrapper.register(MODULE, `CONFIG.Token.objectClass.prototype.${method}`, wrapper, "MIXED");
else {
const prototype = CONFIG.Token.objectClass.prototype, original = prototype[method];
prototype[method] = function (...args) {
return wrapper.call(this, original.bind(this), ...args);
};
}
}
}
Hooks.on("item-piles-openInterface", (app, actor) => { // Adds the proxy button to Item Piles interfaces
if (game.user.isGM || app._vrProxyHeader) return;
const original = app._getHeaderButtons;
app._getHeaderButtons = function (...args) {
const buttons = original.apply(this, args);
addProxyButton(this, actor, buttons);
return buttons;
};
app._vrProxyHeader = true;
});