Merge conteneur + fix hotbar
This commit is contained in:
parent
b35eaad757
commit
1b8ad316b9
@ -2,6 +2,20 @@ import { Misc } from "./misc.js";
|
|||||||
|
|
||||||
export class RdDHotbar {
|
export class RdDHotbar {
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a macro when dropping an entity on the hotbar
|
* Create a macro when dropping an entity on the hotbar
|
||||||
* Item - open roll dialog for item
|
* Item - open roll dialog for item
|
||||||
@ -10,7 +24,7 @@ export class RdDHotbar {
|
|||||||
*/
|
*/
|
||||||
static initDropbar() {
|
static initDropbar() {
|
||||||
|
|
||||||
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
|
// Create item macro if rollable item - weapon, spell, prayer, trait, or skill
|
||||||
if (documentData.type == "Item") {
|
if (documentData.type == "Item") {
|
||||||
@ -22,43 +36,33 @@ export class RdDHotbar {
|
|||||||
if (!item || (item.type != "arme" && item.type != "competence")) {
|
if (!item || (item.type != "arme" && item.type != "competence")) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
let command = `game.system.rdd.RdDHotbar.rollMacro("${item.name}", "${item.type}");`;
|
this.addToHotbar(item, slot)
|
||||||
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 })
|
|
||||||
}
|
|
||||||
game.user.assignHotbarMacro(macro, slot);
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Roll macro */
|
/** Roll macro */
|
||||||
static rollMacro(itemName, itemType, bypassData) {
|
static rollMacro(itemName, itemType, bypassData) {
|
||||||
const speaker = ChatMessage.getSpeaker();
|
const speaker = ChatMessage.getSpeaker();
|
||||||
let actor;
|
let actor;
|
||||||
if (speaker.token) actor = game.actors.tokens[speaker.token];
|
if (speaker.token) actor = game.actors.tokens[speaker.token];
|
||||||
if (!actor) actor = game.actors.get(speaker.actor);
|
if (!actor) actor = game.actors.get(speaker.actor);
|
||||||
|
|
||||||
let item = actor?.items.find(it => it.name === itemName && it.type == itemType) ?? undefined;
|
let item = actor?.items.find(it => it.name === itemName && it.type == itemType) ?? undefined;
|
||||||
if (!item) {
|
if (!item) {
|
||||||
return ui.notifications.warn(`Impossible de trouver l'objet de cette macro`);
|
return ui.notifications.warn(`Impossible de trouver l'objet de cette macro`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trigger the item roll
|
||||||
|
switch (item.type) {
|
||||||
|
case "arme":
|
||||||
|
return actor.rollArme(item);
|
||||||
|
case "competence":
|
||||||
|
return actor.rollCompetence(itemName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trigger the item roll
|
|
||||||
switch (item.type) {
|
|
||||||
case "arme":
|
|
||||||
return actor.rollArme(item);
|
|
||||||
case "competence":
|
|
||||||
return actor.rollCompetence(itemName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user