Update vtt types
This commit is contained in:
parent
623558dc78
commit
c57960c153
24 changed files with 144 additions and 107 deletions
|
@ -3,7 +3,7 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { DS4Actor } from "../actor/actor";
|
||||
import { getCanvas } from "../helpers";
|
||||
import { getCanvas, getGame } from "../helpers";
|
||||
|
||||
/**
|
||||
* Gets the currently active actor based on how {@link ChatMessage} determines
|
||||
|
@ -18,7 +18,7 @@ export function getActiveActor(): DS4Actor | undefined {
|
|||
return speakerToken.actor ?? undefined;
|
||||
}
|
||||
|
||||
const speakerActor = speaker.actor ? game.actors?.get(speaker.actor) : undefined;
|
||||
const speakerActor = speaker.actor ? getGame().actors?.get(speaker.actor) : undefined;
|
||||
if (speakerActor) {
|
||||
return speakerActor;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
import { Check } from "../actor/actor-data-properties";
|
||||
import { DS4 } from "../config";
|
||||
import { getGame } from "../helpers";
|
||||
import notifications from "../ui/notifications";
|
||||
import { getActiveActor } from "./helpers";
|
||||
|
||||
|
@ -15,13 +16,15 @@ import { getActiveActor } from "./helpers";
|
|||
*/
|
||||
export async function createRollCheckMacro(check: Check, slot: string): Promise<void> {
|
||||
const macro = await getOrCreateRollCheckMacro(check);
|
||||
game.user?.assignHotbarMacro(macro ?? null, slot);
|
||||
getGame().user?.assignHotbarMacro(macro ?? null, slot);
|
||||
}
|
||||
|
||||
async function getOrCreateRollCheckMacro(check: Check): Promise<Macro | undefined> {
|
||||
const command = `game.ds4.macros.rollCheck("${check}");`;
|
||||
const command = `getGame().ds4.macros.rollCheck("${check}");`;
|
||||
|
||||
const existingMacro = game.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.data.command === command,
|
||||
);
|
||||
if (existingMacro) {
|
||||
return existingMacro;
|
||||
}
|
||||
|
@ -44,7 +47,7 @@ async function getOrCreateRollCheckMacro(check: Check): Promise<Macro | undefine
|
|||
export async function rollCheck(check: Check): Promise<void> {
|
||||
const actor = getActiveActor();
|
||||
if (!actor) {
|
||||
return notifications.warn(game.i18n.localize("DS4.WarningMustControlActorToUseRollCheckMacro"));
|
||||
return notifications.warn(getGame().i18n.localize("DS4.WarningMustControlActorToUseRollCheckMacro"));
|
||||
}
|
||||
|
||||
return actor.rollCheck(check).catch((e) => notifications.error(e, { log: true }));
|
||||
|
|
|
@ -2,15 +2,17 @@
|
|||
//
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { getGame } from "../helpers";
|
||||
import notifications from "../ui/notifications";
|
||||
import { getActiveActor } from "./helpers";
|
||||
|
||||
/**
|
||||
* Executes the roll generic check macro.
|
||||
*/
|
||||
export async function rollGenericCheck(): Promise<void> {
|
||||
const actor = getActiveActor();
|
||||
if (!actor) {
|
||||
return notifications.warn(game.i18n.localize("DS4.WarningMustControlActorToUseRollCheckMacro"));
|
||||
return notifications.warn(getGame().i18n.localize("DS4.WarningMustControlActorToUseRollCheckMacro"));
|
||||
}
|
||||
|
||||
return actor.rollGenericCheck().catch((e) => notifications.error(e, { log: true }));
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
//
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { getGame } from "../helpers";
|
||||
import notifications from "../ui/notifications";
|
||||
import { getActiveActor } from "./helpers";
|
||||
|
||||
|
@ -13,13 +14,13 @@ import { getActiveActor } from "./helpers";
|
|||
*/
|
||||
export async function createRollItemMacro(itemData: foundry.data.ItemData["_source"], slot: string): Promise<void> {
|
||||
const macro = await getOrCreateRollItemMacro(itemData);
|
||||
game.user?.assignHotbarMacro(macro ?? null, slot);
|
||||
getGame().user?.assignHotbarMacro(macro ?? null, slot);
|
||||
}
|
||||
|
||||
async function getOrCreateRollItemMacro(itemData: foundry.data.ItemData["_source"]): Promise<Macro | undefined> {
|
||||
const command = `game.ds4.macros.rollItem("${itemData._id}");`;
|
||||
const command = `getGame().ds4.macros.rollItem("${itemData._id}");`;
|
||||
|
||||
const existingMacro = game.macros?.find((m) => m.name === itemData.name && m.data.command === command);
|
||||
const existingMacro = getGame().macros?.find((m) => m.name === itemData.name && m.data.command === command);
|
||||
if (existingMacro) {
|
||||
return existingMacro;
|
||||
}
|
||||
|
@ -42,13 +43,13 @@ async function getOrCreateRollItemMacro(itemData: foundry.data.ItemData["_source
|
|||
export async function rollItem(itemId: string): Promise<void> {
|
||||
const actor = getActiveActor();
|
||||
if (!actor) {
|
||||
return notifications.warn(game.i18n.localize("DS4.WarningMustControlActorToUseRollItemMacro"));
|
||||
return notifications.warn(getGame().i18n.localize("DS4.WarningMustControlActorToUseRollItemMacro"));
|
||||
}
|
||||
|
||||
const item = actor.items?.get(itemId);
|
||||
if (!item) {
|
||||
return notifications.warn(
|
||||
game.i18n.format("DS4.WarningControlledActorDoesNotHaveItem", {
|
||||
getGame().i18n.format("DS4.WarningControlledActorDoesNotHaveItem", {
|
||||
actorName: actor.name,
|
||||
actorId: actor.id,
|
||||
itemId,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue