feat: update for v10
This commit is contained in:
parent
6277e27056
commit
f25b46a226
63 changed files with 41349 additions and 24332 deletions
|
@ -3,6 +3,7 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { DS4 } from "../config";
|
||||
import { isCheck } from "../documents/actor/actor-data-properties-base";
|
||||
import { notifications } from "../ui/notifications";
|
||||
import { getGame } from "../utils/utils";
|
||||
import { getActiveActorAndToken } from "./helpers";
|
||||
|
@ -10,12 +11,15 @@ import { getActiveActorAndToken } from "./helpers";
|
|||
/**
|
||||
* Creates a macro from a check drop.
|
||||
* Get an existing roll check macro if one exists, otherwise create a new one.
|
||||
* @param {import("../documents/actor/actor-data-properties-base").Check} check The name of the check to perform
|
||||
* @param {string} slot The hotbar slot to use
|
||||
* @returns {Promise<void>} A promise that resoolves when the macro has been created.
|
||||
* @param {object} data The check drop data
|
||||
* @param {string} slot The hotbar slot to use
|
||||
* @returns {Promise<void>} A promise that resolves when the macro has been created.
|
||||
*/
|
||||
export async function createRollCheckMacro(check, slot) {
|
||||
const macro = await getOrCreateRollCheckMacro(check);
|
||||
export async function createRollCheckMacro(data, slot) {
|
||||
if (!("data" in data) || typeof data.data !== "string" || !isCheck(data.data)) {
|
||||
return notifications.warn(getGame().i18n.localize("DS4.WarningInvalidCheckDropped"));
|
||||
}
|
||||
const macro = await getOrCreateRollCheckMacro(data.data);
|
||||
await getGame().user?.assignHotbarMacro(macro ?? null, slot);
|
||||
}
|
||||
|
||||
|
@ -26,9 +30,7 @@ export async function createRollCheckMacro(check, slot) {
|
|||
async function getOrCreateRollCheckMacro(check) {
|
||||
const command = `game.ds4.macros.rollCheck("${check}");`;
|
||||
|
||||
const existingMacro = getGame().macros?.find(
|
||||
(m) => m.name === DS4.i18n.checks[check] && m.data.command === command,
|
||||
);
|
||||
const existingMacro = getGame().macros?.find((m) => m.name === DS4.i18n.checks[check] && m.command === command);
|
||||
if (existingMacro) {
|
||||
return existingMacro;
|
||||
}
|
||||
|
|
|
@ -2,18 +2,33 @@
|
|||
//
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { DS4Item } from "../documents/item/item";
|
||||
import { notifications } from "../ui/notifications";
|
||||
import { getGame } from "../utils/utils";
|
||||
import { getActiveActorAndToken } from "./helpers";
|
||||
|
||||
/**
|
||||
* Creates a macro from an item drop.
|
||||
* Create a macro from an item drop.
|
||||
* Get an existing roll item macro if one exists, otherwise create a new one.
|
||||
* @param {object} itemData The item data
|
||||
* @param {string} slot The hotbar slot to use
|
||||
* @param {object} data The item drop data
|
||||
* @param {string} slot The hotbar slot to use
|
||||
* @returns {Promise<void>} A promise that resolves once the macro has been created.
|
||||
*/
|
||||
export async function createRollItemMacro(itemData, slot) {
|
||||
export async function createRollItemMacro(data, slot) {
|
||||
const item = await Item.implementation.fromDropData(data);
|
||||
if (!item.parent) {
|
||||
return notifications.warn(getGame().i18n.localize("DS4.WarningMacrosCanOnlyBeCreatedForOwnedItems"));
|
||||
}
|
||||
if (!DS4Item.rollableItemTypes.includes(item.type)) {
|
||||
return notifications.warn(
|
||||
getGame().i18n.format("DS4.WarningItemIsNotRollable", {
|
||||
name: item.name,
|
||||
id: item.id,
|
||||
type: item.type,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
const macro = await getOrCreateRollItemMacro(itemData);
|
||||
await getGame().user?.assignHotbarMacro(macro ?? null, slot);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue