From a7991bce92e1934ad1d04efebd7d127e386a07d6 Mon Sep 17 00:00:00 2001 From: sladecraven Date: Sun, 25 Sep 2022 21:13:15 +0200 Subject: [PATCH] Fix hotbar + tooltip --- module/system/bol-hotbar.js | 72 ++++++++--------------- templates/dialogs/attribute-roll-part.hbs | 2 +- templates/dialogs/boons-roll-part.hbs | 2 +- templates/dialogs/career-roll-part.hbs | 2 +- templates/dialogs/flaws-roll-part.hbs | 2 +- 5 files changed, 30 insertions(+), 50 deletions(-) diff --git a/module/system/bol-hotbar.js b/module/system/bol-hotbar.js index 7884153..2909547 100644 --- a/module/system/bol-hotbar.js +++ b/module/system/bol-hotbar.js @@ -2,6 +2,21 @@ import { BoLRoll } from "../controllers/bol-rolls.js"; export class BoLHotbar { + + static async assignToHotBar( item, slot) { + let command = `game.bol.BoLHotbar.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); + } + /** * Create a macro when dropping an entity on the hotbar * Item - open roll dialog for item @@ -10,55 +25,20 @@ export class BoLHotbar { */ static init( ) { - Hooks.on("hotbarDrop", async (bar, documentData, slot) => { + Hooks.on("hotbarDrop", (bar, documentData, slot) => { // Create item macro if rollable item - weapon, spell, prayer, trait, or skill if (documentData.type == "Item") { - console.log("Drop done !!!", bar, documentData, slot) - let item = documentData.data - let command = `game.bol.BoLHotbar.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 }) + let item = fromUuidSync(documentData.uuid) + if (item == undefined) { + item = this.actor.items.get(documentData.uuid) } - game.user.assignHotbarMacro(macro, slot); - } - // Create a macro to open the actor sheet of the actor dropped on the hotbar - else if (documentData.type == "Actor") { - let actor = game.actors.get(documentData.id); - let command = `game.actors.get("${documentData.id}").sheet.render(true)` - let macro = game.macros.contents.find(m => (m.name === actor.name) && (m.command === command)); - if (!macro) { - macro = await Macro.create({ - name: actor.data.name, - type: "script", - img: actor.data.img, - command: command - }, { displaySheet: false }) - game.user.assignHotbarMacro(macro, slot); + if (item && (item.system.subtype === "weapon" || item.system.category === "spell")) { + this.assignToHotBar( item, slot ) + return false } } - // Create a macro to open the journal sheet of the journal dropped on the hotbar - else if (documentData.type == "JournalEntry") { - let journal = game.journal.get(documentData.id); - let command = `game.journal.get("${documentData.id}").sheet.render(true)` - let macro = game.macros.contents.find(m => (m.name === journal.name) && (m.command === command)); - if (!macro) { - macro = await Macro.create({ - name: journal.data.name, - type: "script", - img: "systems/bol/icons/images/icone_parchement_vierge.webp", - command: command - }, { displaySheet: false }) - game.user.assignHotbarMacro(macro, slot); - } - } - return false; - }); + return true + }) } /** Roll macro */ @@ -76,10 +56,10 @@ export class BoLHotbar { return ui.notifications.warn(`Impossible de trouver l'objet de cette macro`) } // Trigger the item roll - if (item.data.data.category === "equipment" && item.data.data.subtype === "weapon") { + if (item.system.category === "equipment" && item.system.subtype === "weapon") { return BoLRoll.weaponCheckWithWeapon( actor, item) } - if (item.data.data.category === "spell") { + if (item.system.category === "spell") { return BoLRoll.spellCheckWithSpell( actor, item) } } diff --git a/templates/dialogs/attribute-roll-part.hbs b/templates/dialogs/attribute-roll-part.hbs index 5ed3a37..a544fe3 100644 --- a/templates/dialogs/attribute-roll-part.hbs +++ b/templates/dialogs/attribute-roll-part.hbs @@ -1,5 +1,5 @@
-
+
diff --git a/templates/dialogs/boons-roll-part.hbs b/templates/dialogs/boons-roll-part.hbs index bf993f0..8e8084a 100644 --- a/templates/dialogs/boons-roll-part.hbs +++ b/templates/dialogs/boons-roll-part.hbs @@ -1,6 +1,6 @@ {{#if (count boons)}}
-
+
diff --git a/templates/dialogs/career-roll-part.hbs b/templates/dialogs/career-roll-part.hbs index 1af2b4d..c521850 100644 --- a/templates/dialogs/career-roll-part.hbs +++ b/templates/dialogs/career-roll-part.hbs @@ -1,6 +1,6 @@ {{#if careers}}
-
+
diff --git a/templates/dialogs/flaws-roll-part.hbs b/templates/dialogs/flaws-roll-part.hbs index 7351e0e..21e52b8 100644 --- a/templates/dialogs/flaws-roll-part.hbs +++ b/templates/dialogs/flaws-roll-part.hbs @@ -1,6 +1,6 @@ {{#if (count flaws)}}
-
+