Skip to content

Commit

Permalink
Merge pull request #449 from Stew-rt/rolltable_on_hotbar
Browse files Browse the repository at this point in the history
fix(macros): #355 Accept RollTable drops onto Macro hotbar
  • Loading branch information
anthonyronda authored Jun 4, 2023
2 parents aad6548 + 1916af6 commit b7bf229
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@
"OSE.warn.macrosNotAnItem": "Unable to create macro, not an item.",

"OSE.error.macrosOnlyForOwnedItems": "You can only create macro buttons for owned Items",
"OSE.error.noRollTableWithUuId": "RollTable with uuid, {uuid} did not or no longer exists in this world.",
"OSE.error.noItemWithName": "Your controlled Actor {actorName} does not have an item named {itemName}.",
"OSE.error.notEnoughGP": "This Actor doesn't have enough GP to pay for its inventory.",
"OSE.error.itemNoLongerExistsOnActor": "The requested Item {itemId} no longer exists on Actor {actorName}.",
Expand Down
36 changes: 36 additions & 0 deletions src/module/helpers-macros.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* @file Functions that make working with hotbar macros easier
*/
import {rollTreasure} from "./helpers-treasure";
/* -------------------------------------------- */
/* Hotbar Macros */
/* -------------------------------------------- */
Expand All @@ -17,6 +18,18 @@ export async function createOseMacro(data, slot) {
if (data.type === "Macro") {
return game.user.assignHotbarMacro(await fromUuid(data.uuid), slot);
}
if (data.type === "RollTable") {
const command = `game.ose.rollTableMacro("${data.uuid}");`;
const table = await fromUuid(data.uuid);
const macro = await Macro.create({
name: table.name,
type: "script",
img: table.img,
command,
flags: { "ose.tableMacro": true },
});
return game.user.assignHotbarMacro(macro, slot);
}
if (data.type !== "Item")
return ui.notifications.warn(
game.i18n.localize("OSE.warn.macrosNotAnItem")
Expand Down Expand Up @@ -87,3 +100,26 @@ export function rollItemMacro(itemName) {
// Trigger the item roll
return item.roll();
}

/**
* Roll on a RollTable by uuid if it exists.
*
* @param {string} tableUuId - UuId of the RollTable
*/
export function rollTableMacro(tableUuId) {
fromUuid(tableUuId).then((table) => {
if (table === null) {
return ui.notifications.error(
game.i18n.format("OSE.error.noRollTableWithUuId", {
uuid: tableUuId,
})
);
}
//

if (table.getFlag(game.system.id, "treasure")) {
return rollTreasure(table);
}
return table.draw({ displayChat: true });
});
}
2 changes: 1 addition & 1 deletion src/module/helpers-treasure.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async function drawTreasure(table, data) {
* @param table
* @param options
*/
async function rollTreasure(table, options = {}) {
export async function rollTreasure(table, options = {}) {
// Draw treasure
const data = await drawTreasure(table, {});
const templateData = {
Expand Down
1 change: 1 addition & 0 deletions src/ose.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Hooks.once("init", async () => {

game.ose = {
rollItemMacro: macros.rollItemMacro,
rollTableMacro: macros.rollTableMacro,
oseCombat: OseCombat,
};

Expand Down

0 comments on commit b7bf229

Please sign in to comment.