From c31306f15470ea9946fdbc31c22b0a16c5fd4c11 Mon Sep 17 00:00:00 2001 From: sladecraven Date: Mon, 8 Feb 2021 22:51:31 +0100 Subject: [PATCH] =?UTF-8?q?#156=20Drag&Drop=20de=20comp=C3=A9tences/armes/?= =?UTF-8?q?acteur/journal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/rdd-hotbar-drop.js | 84 +++++++++++++++++++++++++++++++++++++++ module/rdd-main.js | 5 ++- system.json | 2 +- 3 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 module/rdd-hotbar-drop.js diff --git a/module/rdd-hotbar-drop.js b/module/rdd-hotbar-drop.js new file mode 100644 index 00000000..12b925bb --- /dev/null +++ b/module/rdd-hotbar-drop.js @@ -0,0 +1,84 @@ + +export class RdDHotbar { + + /** + * Create a macro when dropping an entity on the hotbar + * Item - open roll dialog for item + * Actor - open actor sheet + * Journal - open journal sheet + */ + static initDropbar( ) { + + Hooks.on("hotbarDrop", async (bar, data, slot) => { + // Create item macro if rollable item - weapon, spell, prayer, trait, or skill + if (data.type == "Item") { + if (data.data.type != "arme" && data.data.type != "competence" ) + return + let item = data.data + let command = `game.system.rdd.RdDHotbar.rollMacro("${item.name}", "${item.type}");`; + let macro = game.macros.entities.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 }) + } + game.user.assignHotbarMacro(macro, slot); + } + // Create a macro to open the actor sheet of the actor dropped on the hotbar + else if (data.type == "Actor") { + let actor = game.actors.get(data.id); + let command = `game.actors.get("${data.id}").sheet.render(true)` + let macro = game.macros.entities.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); + } + } + // Create a macro to open the journal sheet of the journal dropped on the hotbar + else if (data.type == "JournalEntry") { + let journal = game.journal.get(data.id); + let command = `game.journal.get("${data.id}").sheet.render(true)` + let macro = game.macros.entities.find(m => (m.name === journal.name) && (m.command === command)); + if (!macro) { + macro = await Macro.create({ + name: journal.data.name, + type: "script", + img: "systems/wfrp4e/icons/buildings/scroll.png", + command: command + }, { displaySheet: false }) + game.user.assignHotbarMacro(macro, slot); + } + } + return false; + }); + } + + /** Roll macro */ + static rollMacro(itemName, itemType, bypassData) { + const speaker = ChatMessage.getSpeaker(); + let actor; + if (speaker.token) actor = game.actors.tokens[speaker.token]; + if (!actor) actor = game.actors.get(speaker.actor); + let item = actor ? actor.items.find(i => i.name === itemName && i.type == itemType) : null; + if (!item) return ui.notifications.warn(`Impossible de trouver l'objet de cette macro`); + + item = item.data; + + // Trigger the item roll + switch (item.type) { + case "arme": + return actor.rollArme(item.data.competence, itemName); + case "competence": + return actor.rollCompetence( itemName ); + } + } + +} diff --git a/module/rdd-main.js b/module/rdd-main.js index aab4d527..898b1ebe 100644 --- a/module/rdd-main.js +++ b/module/rdd-main.js @@ -27,6 +27,7 @@ import { StatusEffects } from "./status-effects.js"; import { RddCompendiumOrganiser } from "./rdd-compendium-organiser.js"; import { ReglesOptionelles } from "./regles-optionelles.js"; import { TMRRencontres } from "./tmr-rencontres.js"; +import { RdDHotbar } from "./rdd-hotbar-drop.js" /* -------------------------------------------- */ /* Foundry VTT Initialization */ @@ -113,7 +114,8 @@ Hooks.once("init", async function () { // Create useful storage space game.system.rdd = { TMRUtility, - RdDUtility + RdDUtility, + RdDHotbar } /* -------------------------------------------- */ @@ -233,6 +235,7 @@ Hooks.once("init", async function () { ReglesOptionelles.init(); TMRUtility.init(); TMRRencontres.init(); + RdDHotbar.initDropbar(); }); /* -------------------------------------------- */ diff --git a/system.json b/system.json index e0db5a9b..ffb88e17 100644 --- a/system.json +++ b/system.json @@ -2,7 +2,7 @@ "name": "foundryvtt-reve-de-dragon", "title": "Rêve de Dragon", "description": "Rêve de Dragon RPG for FoundryVTT", - "version": "1.3.18", + "version": "1.3.19", "manifestPlusVersion": "1.0.0", "minimumCoreVersion": "0.7.5", "compatibleCoreVersion": "0.7.9",