2021-03-14 19:04:28 +01:00
|
|
|
import { DS4Item } from "../item/item";
|
|
|
|
import { DS4ItemData } from "../item/item-data";
|
2021-03-16 07:42:00 +01:00
|
|
|
import { createRollItemMacro } from "../macros/roll-item-macro";
|
2021-03-14 19:04:28 +01:00
|
|
|
import notifications from "../ui/notifications";
|
|
|
|
|
2021-03-16 07:42:00 +01:00
|
|
|
export default function registerForHotbarDropHook(): void {
|
2021-03-14 19:04:28 +01:00
|
|
|
Hooks.on("hotbarDrop", async (hotbar: Hotbar, data: { type: string } & Record<string, unknown>, slot: string) => {
|
|
|
|
switch (data.type) {
|
|
|
|
case "Item": {
|
|
|
|
if (!("data" in data)) {
|
|
|
|
return notifications.warn(game.i18n.localize("DS4.WarningMacrosCanOnlyBeCreatedForOwnedItems"));
|
|
|
|
}
|
|
|
|
const itemData = data.data as DS4ItemData;
|
|
|
|
|
|
|
|
if (!DS4Item.rollableItemTypes.includes(itemData.type)) {
|
|
|
|
return notifications.warn(
|
|
|
|
game.i18n.format("DS4.WarningItemIsNotRollable", {
|
|
|
|
name: itemData.name,
|
|
|
|
id: itemData._id,
|
|
|
|
type: itemData.type,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
2021-03-16 07:42:00 +01:00
|
|
|
await createRollItemMacro(itemData, slot);
|
2021-03-14 19:04:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|