2021-02-08 22:51:31 +01:00
|
|
|
|
|
|
|
export class RdDHotbar {
|
|
|
|
|
2022-09-25 21:21:28 +02:00
|
|
|
static async addToHotbar(item, slot) {
|
|
|
|
let command = `game.system.rdd.RdDHotbar.rollMacro("${item.name}", "${item.type}");`;
|
|
|
|
let macro = game.macros.contents.find(m => (m.name === item.name) && (m.command === command));
|
|
|
|
if (!macro) {
|
|
|
|
macro = await Macro.create({
|
|
|
|
name: item.name,
|
|
|
|
type: "script",
|
|
|
|
img: item.img,
|
|
|
|
command: command
|
|
|
|
}, { displaySheet: false })
|
|
|
|
}
|
|
|
|
await game.user.assignHotbarMacro(macro, slot);
|
|
|
|
}
|
|
|
|
|
2021-02-08 22:51:31 +01:00
|
|
|
/**
|
|
|
|
* Create a macro when dropping an entity on the hotbar
|
|
|
|
* Item - open roll dialog for item
|
|
|
|
* Actor - open actor sheet
|
|
|
|
* Journal - open journal sheet
|
|
|
|
*/
|
2022-09-07 09:14:42 +02:00
|
|
|
static initDropbar() {
|
2021-02-08 22:51:31 +01:00
|
|
|
|
2022-09-25 21:21:28 +02:00
|
|
|
Hooks.on("hotbarDrop", (bar, documentData, slot) => {
|
2022-09-06 23:52:21 +02:00
|
|
|
|
2022-09-07 09:14:42 +02:00
|
|
|
// Create item macro if rollable item - weapon, spell, prayer, trait, or skill
|
|
|
|
if (documentData.type == "Item") {
|
|
|
|
let item = fromUuidSync(documentData.uuid)
|
|
|
|
if (item == undefined) {
|
|
|
|
item = this.actor.items.get(documentData.uuid)
|
|
|
|
}
|
|
|
|
console.log("DROP", documentData, item)
|
|
|
|
if (!item || (item.type != "arme" && item.type != "competence")) {
|
|
|
|
return true
|
|
|
|
}
|
2022-09-25 21:21:28 +02:00
|
|
|
this.addToHotbar(item, slot)
|
2022-09-07 09:14:42 +02:00
|
|
|
return false
|
2021-02-08 22:51:31 +01:00
|
|
|
}
|
2022-09-06 23:52:21 +02:00
|
|
|
|
2022-09-25 21:17:47 +02:00
|
|
|
return true
|
2022-09-25 21:21:28 +02:00
|
|
|
})
|
|
|
|
}
|
2021-02-08 22:51:31 +01:00
|
|
|
|
|
|
|
/** Roll macro */
|
|
|
|
static rollMacro(itemName, itemType, bypassData) {
|
2022-09-25 21:21:28 +02:00
|
|
|
const speaker = ChatMessage.getSpeaker();
|
|
|
|
let actor;
|
|
|
|
if (speaker.token) actor = game.actors.tokens[speaker.token];
|
|
|
|
if (!actor) actor = game.actors.get(speaker.actor);
|
2021-02-08 22:51:31 +01:00
|
|
|
|
2022-09-25 21:21:28 +02:00
|
|
|
let item = actor?.items.find(it => it.name === itemName && it.type == itemType) ?? undefined;
|
|
|
|
if (!item) {
|
|
|
|
return ui.notifications.warn(`Impossible de trouver l'objet de cette macro`);
|
|
|
|
}
|
2021-02-08 22:51:31 +01:00
|
|
|
|
2022-09-25 21:21:28 +02:00
|
|
|
// Trigger the item roll
|
|
|
|
switch (item.type) {
|
|
|
|
case "arme":
|
|
|
|
return actor.rollArme(item);
|
|
|
|
case "competence":
|
|
|
|
return actor.rollCompetence(itemName);
|
|
|
|
}
|
2021-02-08 22:51:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|