20 lines
837 B
JavaScript
20 lines
837 B
JavaScript
import { MODULE_ID, SETTINGS } from "../constants.js";
|
|
|
|
export async function getAssignedReactionsForContext(context) {
|
|
const reactions = game.settings.get(MODULE_ID, SETTINGS.REACTIONS) ?? [];
|
|
const assignments = game.settings.get(MODULE_ID, SETTINGS.ASSIGNMENTS) ?? [];
|
|
|
|
const actorUuid = context.targetActor?.uuid ?? context.actor?.uuid ?? null;
|
|
const tokenUuid = context.targetTokenDocument?.uuid ?? context.tokenDocument?.uuid ?? null;
|
|
|
|
const matching = assignments.filter(assignment => {
|
|
if (assignment.mode === "actor" && assignment.actorUuid === actorUuid) return true;
|
|
if (assignment.mode === "token" && assignment.tokenUuid === tokenUuid) return true;
|
|
return false;
|
|
});
|
|
|
|
return matching
|
|
.map(assignment => reactions.find(reaction => reaction.id === assignment.reactionId))
|
|
.filter(Boolean);
|
|
}
|