/* globals coreFearDialog */ /* globals swpfFearDialog */ export const moduleName = 'swade-mb-helpers'; export function log(...args) { console.log('SWADE MB HELPERS |', ...args); } export class moduleHelpers { static _socket = null; static get socket() { return moduleHelpers._socket; } static get rulesVersion() { if (game.modules.get('swpf-core-rules')?.active) { return 'swpf'; } if (game.modules.get('swade-core-rules')?.active) { return 'swade'; } return 'system'; } static get useVAE() { return !!game.modules.get('visual-active-effects')?.active; } static getActorFolderByPath(path) { const names = path.split('/'); if (names[0] === '') { names.shift(); } let name = names.shift(); let folder = game.folders.filter((f) => f.type === 'Actor' && !f.folder).find((f) => f.name === name); if (!folder) { return undefined; } while (names.length > 0) { name = names.shift(); folder = folder.children.find((c) => c.folder.name === name); if (!folder) { return undefined; } folder = folder.folder; } return folder; } static getActorsInFolder(inFolder) { const prefixStack = ['']; const actors = {}; const folderStack = [inFolder]; while (folderStack.length > 0) { const prefix = prefixStack.shift(); const folder = folderStack.shift(); for (const actor of folder.contents) { if (game.user.isGM || actor.testUserPermission(game.user, foundry.CONST.DOCUMENT_OWNERSHIP_LEVELS.OBSERVER)) { actors[`${prefix}${actor.name}`] = actor; } } for (const child of folder.children) { const newPrefix = `${prefix}${child.folder.name} | `; prefixStack.push(newPrefix); folderStack.push(child.folder); } } return actors; } static get fearTableHelper() { switch (moduleHelpers.rulesVersion) { case 'swade': return coreFearDialog; // defined as global by the swade module case 'swpf': return swpfFearDialog; // defined as global by the swpf module } throw new ReferenceError('No premium module active. No fear table found'); } }