ds4/src/macros/helpers.js
Johannes Loher 6277e27056 refactor: convert to ECMAScript where necessary
Also drop @league-of-foundry-developers/foundry-vtt-types.
2022-11-28 02:38:17 +01:00

22 lines
820 B
JavaScript

// SPDX-FileCopyrightText: 2021 Johannes Loher
//
// SPDX-License-Identifier: MIT
import { getCanvas, getGame } from "../utils/utils";
/**
* Gets the currently active actor and token based on how {@link ChatMessage}
* determines the current speaker.
* @returns {{actor?: import("../documents/actor/actor").DS4Actor, token?: TokenDocument}} The currently active actor and token.
*/
export function getActiveActorAndToken() {
const speaker = ChatMessage.getSpeaker();
const speakerToken = speaker.token ? getCanvas().tokens?.get(speaker.token)?.document : undefined;
if (speakerToken) {
return { actor: speakerToken.actor ?? undefined, token: speakerToken };
}
const speakerActor = speaker.actor ? getGame().actors?.get(speaker.actor) : undefined;
return { actor: speakerActor };
}