add actor folder helpers
This commit is contained in:
parent
30b489e397
commit
04b9c21ea8
@ -9,10 +9,12 @@ export class api {
|
||||
static globals () {
|
||||
globalThis.swadeMBHelpers = {
|
||||
DEBUG: true,
|
||||
runOnTargetOrSelectedTokens: helpers.runOnTargetOrSelectedTokens,
|
||||
createEffectDocument: helpers.createEffectDocument,
|
||||
createMutationWithEffect: helpers.createMutationWithEffect,
|
||||
defaultMutationOptions: helpers.defaultMutationOptions
|
||||
defaultMutationOptions: helpers.defaultMutationOptions,
|
||||
getActorFolderByPath: helpers.getActorFolderByPath,
|
||||
getActorsInFolder: helpers.getActorsInFolder,
|
||||
runOnTargetOrSelectedTokens: helpers.runOnTargetOrSelectedTokens
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,4 +49,44 @@ export class helpers {
|
||||
}
|
||||
return mutateOptions
|
||||
}
|
||||
|
||||
static getActorFolderByPath (path) {
|
||||
const names = path.split('/')
|
||||
if (names[0] === '') {
|
||||
names.shift()
|
||||
}
|
||||
let name = names.shift()
|
||||
let folder = game.folders.find(f => f.name === name && !f.folder)
|
||||
while (names.length > 0) {
|
||||
name = names.shift()
|
||||
folder = folder.children.find(c => c.folder.name === name)
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user