2021-05-24 22:12:37 +02:00
|
|
|
import { Misc } from "./misc.js";
|
2021-02-08 22:51:31 +01:00
|
|
|
|
|
|
|
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( ) {
|
|
|
|
|
2021-03-25 03:18:27 +01:00
|
|
|
Hooks.on("hotbarDrop", async (bar, documentData, slot) => {
|
2022-09-06 23:52:21 +02:00
|
|
|
|
|
|
|
|
2021-02-08 22:51:31 +01:00
|
|
|
// Create item macro if rollable item - weapon, spell, prayer, trait, or skill
|
2021-03-25 03:18:27 +01:00
|
|
|
if (documentData.type == "Item") {
|
2022-09-06 23:52:21 +02:00
|
|
|
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" ) ) {
|
2021-02-08 22:51:31 +01:00
|
|
|
return
|
2022-09-06 23:52:21 +02:00
|
|
|
}
|
2021-02-08 22:51:31 +01:00
|
|
|
let command = `game.system.rdd.RdDHotbar.rollMacro("${item.name}", "${item.type}");`;
|
2022-01-07 19:14:00 +01:00
|
|
|
let macro = game.macros.contents.find(m => (m.name === item.name) && (m.command === command));
|
2021-02-08 22:51:31 +01:00
|
|
|
if (!macro) {
|
|
|
|
macro = await Macro.create({
|
|
|
|
name: item.name,
|
|
|
|
type: "script",
|
|
|
|
img: item.img,
|
|
|
|
command: command
|
|
|
|
}, { displaySheet: false })
|
|
|
|
}
|
|
|
|
game.user.assignHotbarMacro(macro, slot);
|
|
|
|
}
|
2022-09-06 23:52:21 +02:00
|
|
|
|
2021-02-08 22:51:31 +01:00
|
|
|
// Create a macro to open the actor sheet of the actor dropped on the hotbar
|
2021-03-25 03:18:27 +01:00
|
|
|
else if (documentData.type == "Actor") {
|
|
|
|
let actor = game.actors.get(documentData.id);
|
|
|
|
let command = `game.actors.get("${documentData.id}").sheet.render(true)`
|
2022-01-07 19:14:00 +01:00
|
|
|
let macro = game.macros.contents.find(m => (m.name === actor.name) && (m.command === command));
|
2021-02-08 22:51:31 +01:00
|
|
|
if (!macro) {
|
|
|
|
macro = await Macro.create({
|
2022-09-06 23:52:21 +02:00
|
|
|
name: actor.name,
|
2021-02-08 22:51:31 +01:00
|
|
|
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
|
2021-03-25 03:18:27 +01:00
|
|
|
else if (documentData.type == "JournalEntry") {
|
2022-09-06 23:52:21 +02:00
|
|
|
let journal = fromUuidSync(documentData.uuid)
|
2021-03-25 03:18:27 +01:00
|
|
|
let command = `game.journal.get("${documentData.id}").sheet.render(true)`
|
2022-01-07 19:14:00 +01:00
|
|
|
let macro = game.macros.contents.find(m => (m.name === journal.name) && (m.command === command));
|
2021-02-08 22:51:31 +01:00
|
|
|
if (!macro) {
|
|
|
|
macro = await Macro.create({
|
2022-09-06 23:52:21 +02:00
|
|
|
name: journal.name,
|
2021-02-08 22:51:31 +01:00
|
|
|
type: "script",
|
2021-11-10 20:03:04 +01:00
|
|
|
img: "systems/foundryvtt-reve-de-dragon/icons/templates/icone_parchement_vierge.webp",
|
2021-02-08 22:51:31 +01:00
|
|
|
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);
|
|
|
|
|
2021-05-24 22:12:37 +02:00
|
|
|
let item = Misc.data(actor?.items.find(it => it.name === itemName && it.type == itemType));
|
|
|
|
if (!item) return ui.notifications.warn(`Impossible de trouver l'objet de cette macro`);
|
2021-02-08 22:51:31 +01:00
|
|
|
|
|
|
|
// Trigger the item roll
|
|
|
|
switch (item.type) {
|
|
|
|
case "arme":
|
2021-05-24 22:12:37 +02:00
|
|
|
return actor.rollArme(item);
|
2021-02-08 22:51:31 +01:00
|
|
|
case "competence":
|
|
|
|
return actor.rollCompetence( itemName );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|