updates and prep for macro-action style
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { helpers } from './helpers.js'
|
||||
import { powerEffects } from './powerEffects.js'
|
||||
|
||||
export class api {
|
||||
static registerFunctions () {
|
||||
@@ -9,6 +10,7 @@ export class api {
|
||||
static globals () {
|
||||
globalThis.swadeMBHelpers = {
|
||||
DEBUG: true,
|
||||
powerEffects,
|
||||
createEffectDocument: helpers.createEffectDocument,
|
||||
createMutationWithEffect: helpers.createMutationWithEffect,
|
||||
defaultMutationOptions: helpers.defaultMutationOptions,
|
||||
|
||||
+11
-11
@@ -1,28 +1,29 @@
|
||||
import { CONST, shim } from './shim.js'
|
||||
|
||||
export class helpers {
|
||||
static runOnTargetOrSelectedTokens (runFunc) {
|
||||
let tokens = []
|
||||
const targets = Array.from(game.user.targets)
|
||||
const targets = Array.from(shim.targets)
|
||||
if (targets.length > 0) {
|
||||
tokens = targets
|
||||
} else if (canvas.tokens.controlled.length > 0) {
|
||||
tokens = canvas.tokens.controlled
|
||||
} else if (shim.controlled.length > 0) {
|
||||
tokens = shim.controlled
|
||||
}
|
||||
if (tokens.length > 0) {
|
||||
runFunc(tokens)
|
||||
} else {
|
||||
ui.notifications.error('Please select or target a token')
|
||||
shim.notifications.error('Please select or target a token')
|
||||
}
|
||||
}
|
||||
|
||||
static createEffectDocument (icon, name, durationRounds, changes) {
|
||||
const effectData = {
|
||||
icon,
|
||||
id: name,
|
||||
label: name,
|
||||
name,
|
||||
duration: { rounds: durationRounds },
|
||||
flags: {
|
||||
swade: {
|
||||
expiration: CONFIG.SWADE.CONST.STATUS_EFFECT_EXPIRATION.EndOfTurnPrompt,
|
||||
expiration: CONST.SWADE.STATUS_EFFECT_EXPIRATION.EndOfTurnPrompt,
|
||||
loseTurnOnHold: true
|
||||
}
|
||||
},
|
||||
@@ -42,7 +43,6 @@ export class helpers {
|
||||
|
||||
static defaultMutationOptions (name) {
|
||||
const mutateOptions = {
|
||||
comparisonKeys: { ActiveEffect: 'label' },
|
||||
name,
|
||||
permanent: true,
|
||||
description: name
|
||||
@@ -56,7 +56,7 @@ export class helpers {
|
||||
names.shift()
|
||||
}
|
||||
let name = names.shift()
|
||||
let folder = game.folders.find(f => f.name === name && !f.folder)
|
||||
let folder = shim.folders.find(f => f.name === name && !f.folder)
|
||||
while (names.length > 0) {
|
||||
name = names.shift()
|
||||
folder = folder.children.find(c => c.folder.name === name)
|
||||
@@ -75,8 +75,8 @@ export class helpers {
|
||||
const folder = folderStack.shift()
|
||||
for (const actor of folder.contents) {
|
||||
if (
|
||||
game.user.isGM || actor.testUserPermission(
|
||||
game.user, foundry.CONST.DOCUMENT_OWNERSHIP_LEVELS.OBSERVER)
|
||||
shim.user.isGM || actor.testUserPermission(
|
||||
shim.user, CONST.FOUNDRY.DOCUMENT_OWNERSHIP_LEVELS.OBSERVER)
|
||||
) {
|
||||
actors[`${prefix}${actor.name}`] = actor
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { api } from './api.js'
|
||||
import { log, shim, CONST } from './shim.js'
|
||||
|
||||
function _checkModule (name) {
|
||||
if (!game.modules.get(name)?.active && game.user.isGM) {
|
||||
@@ -13,4 +14,7 @@ Hooks.on('setup', api.registerFunctions)
|
||||
|
||||
Hooks.on('ready', () => {
|
||||
_checkModule('warpgate')
|
||||
CONST.FOUNDRY = foundry.CONST
|
||||
CONST.SWADE = CONFIG.SWADE.CONST
|
||||
log('Initialized SWADE MB Helpers')
|
||||
})
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
import { CONST, shim } from './shim.js'
|
||||
|
||||
function baseMenu (title, targets) {
|
||||
const targetList = targets.map(t => t.name).join(', ')
|
||||
return {
|
||||
menuOptions: {
|
||||
title,
|
||||
defaultButton: 'Cancel',
|
||||
options: {}
|
||||
},
|
||||
menuData: {
|
||||
inputs: [
|
||||
{ type: 'header', label: title },
|
||||
{ type: 'info', label: `Apply ${title} to ${targetList}` },
|
||||
{ type: 'header', label: 'Global Modifiers' },
|
||||
{ type: 'checkbox', label: 'Glow (+1)' },
|
||||
{ type: 'checkbox', label: 'Shroud (+1)' },
|
||||
{ type: 'checkbox', label: 'Hinder (+1)' },
|
||||
{ type: 'checkbox', label: 'Hurry (+1)' },
|
||||
{ type: 'header', label: 'Power Modifiers' }
|
||||
],
|
||||
buttons: [
|
||||
{ label: 'Apply', value: 'apply' },
|
||||
{ label: 'Apply with Raise', value: 'raise' },
|
||||
{ label: 'Cancel', value: 'cancel' }
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ModifierEffects {
|
||||
static glow (basename, durationRounds) {
|
||||
const effectDoc = shim.createEffectDocument(
|
||||
'icons/magic/light/orb-shadow-blue.webp',
|
||||
'Glow',
|
||||
durationRounds
|
||||
)
|
||||
effectDoc.changes = [
|
||||
{
|
||||
key: '@Skill{Stealth}[system.die.modifier]',
|
||||
mode: CONST.FOUNDRY.ACTIVE_EFFECT_MODES.ADD,
|
||||
value: -2,
|
||||
priority: 0
|
||||
}
|
||||
]
|
||||
return effectDoc
|
||||
}
|
||||
|
||||
static shroud (basename, durationRounds) {
|
||||
const effectDoc = shim.createEffectDocument(
|
||||
'icons/magic/perception/shadow-stealth-eyes-purple.webp',
|
||||
'Shroud',
|
||||
durationRounds
|
||||
)
|
||||
effectDoc.changes = [
|
||||
{
|
||||
key: '@Skill{Stealth}[system.die.modifier]',
|
||||
mode: CONST.FOUNDRY.ACTIVE_EFFECT_MODES.ADD,
|
||||
value: 1,
|
||||
priority: 0
|
||||
}
|
||||
]
|
||||
return effectDoc
|
||||
}
|
||||
|
||||
static hinder (basename, durationRounds) {
|
||||
const effectDoc = shim.createEffectDocument(
|
||||
'icons/magic/control/debuff-chains-shackle-movement-red.webp',
|
||||
'Hinder',
|
||||
durationRounds
|
||||
)
|
||||
effectDoc.changes = [
|
||||
{
|
||||
key: 'system.stats.speed.value',
|
||||
mode: CONST.FOUNDRY.ACTIVE_EFFECT_MODES.ADD,
|
||||
value: -2,
|
||||
priority: 0
|
||||
}
|
||||
]
|
||||
return effectDoc
|
||||
}
|
||||
|
||||
static hurry (basename, durationRounds) {
|
||||
const effectDoc = shim.createEffectDocument(
|
||||
'icons/skills/movement/feet-winged-sandals-tan.webp',
|
||||
'Hurry',
|
||||
durationRounds
|
||||
)
|
||||
effectDoc.changes = [
|
||||
{
|
||||
key: 'system.stats.speed.value',
|
||||
mode: CONST.FOUNDRY.ACTIVE_EFFECT_MODES.ADD,
|
||||
value: 2,
|
||||
priority: 0
|
||||
}
|
||||
]
|
||||
return effectDoc
|
||||
}
|
||||
}
|
||||
|
||||
function globalModifierEffects (inputs, basename, durationRounds) {
|
||||
const effectDocs = []
|
||||
const inputIndex = 8
|
||||
if (inputs[3]) { // glow
|
||||
effectDocs.push(ModifierEffects.glow(basename, durationRounds))
|
||||
}
|
||||
if (inputs[4]) { // shroud
|
||||
effectDocs.push(ModifierEffects.shroud(basename, durationRounds))
|
||||
}
|
||||
if (inputs[5]) { // hinder
|
||||
effectDocs.push(ModifierEffects.hinder(basename, durationRounds))
|
||||
}
|
||||
if (inputs[6]) { // hurry
|
||||
effectDocs.push(ModifierEffects.hurry(basename, durationRounds))
|
||||
}
|
||||
return { effectDocs, inputIndex }
|
||||
}
|
||||
|
||||
class PowerMenus {
|
||||
static blind (token, targets) {
|
||||
const { menuOptions, menuData } = baseMenu('Blind', targets)
|
||||
menuData.inputs.push({
|
||||
type: 'checkbox',
|
||||
label: 'Strong (+1 point)',
|
||||
options: false
|
||||
})
|
||||
return { menuOptions, menuData }
|
||||
}
|
||||
}
|
||||
|
||||
class PowerHandlers {
|
||||
static async blind (token, targets, buttons, inputs) {
|
||||
const raise = (buttons === 'raise')
|
||||
const { effectDocs, inputIndex } = globalModifierEffects(inputs, 'Blind', 1)
|
||||
const strong = !!inputs[inputIndex]
|
||||
const icon = 'icons/skills/wounds/injury-eyes-blood-red.webp'
|
||||
const changes = [
|
||||
{
|
||||
key: 'system.stats.globalMods.trait',
|
||||
mode: CONST.FOUNDRY.ACTIVE_EFFECT_MODES.ADD,
|
||||
value: -2,
|
||||
priority: 0
|
||||
}
|
||||
]
|
||||
effectDocs.push(
|
||||
shim.createEffectDocument(
|
||||
icon, `minor Blindness (Vigor ${strong ? '-2 ' : ''}ends)`, 1)
|
||||
)
|
||||
effectDocs[effectDocs.length - 1].changes = changes
|
||||
if (raise) {
|
||||
effectDocs.push(
|
||||
shim.createEffectDocument(
|
||||
icon, `major Blindness (Vigor ${strong ? '-2 ' : ''}ends)`, 1)
|
||||
)
|
||||
effectDocs[effectDocs.length - 1].changes = changes
|
||||
}
|
||||
for (const target of targets) {
|
||||
shim.applyActiveEffects(target, effectDocs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function powerEffects (options = {}) {
|
||||
// options available
|
||||
const token = 'token' in options ? options.token : []
|
||||
const targets = 'targets' in options ? Array.from(options.targets) : []
|
||||
const item = 'item' in options ? options.item : null
|
||||
const name = 'name' in options
|
||||
? options.name
|
||||
: (
|
||||
item !== null ? item.name : null)
|
||||
|
||||
const lcName = name.toLowerCase()
|
||||
if (lcName in PowerMenus && lcName in PowerHandlers) {
|
||||
const { menuOptions, menuData } = PowerMenus[lcName](token, targets)
|
||||
const { buttons, inputs } = await shim.warpgateMenu(menuData, menuOptions)
|
||||
if (buttons && buttons !== 'cancel') {
|
||||
await PowerHandlers[lcName](token, targets, buttons, inputs)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
export const CONST = {
|
||||
SWADE: null,
|
||||
FOUNDRY: null
|
||||
}
|
||||
|
||||
export class shim {
|
||||
static get folders () {
|
||||
return game.folders
|
||||
}
|
||||
|
||||
static get controlled () {
|
||||
return canvas.tokens.controlled
|
||||
}
|
||||
|
||||
static get targets () {
|
||||
return game.user.targets
|
||||
}
|
||||
|
||||
static get notifications () {
|
||||
return ui.notifications
|
||||
}
|
||||
|
||||
static get user () {
|
||||
return game.user
|
||||
}
|
||||
|
||||
static createEffectDocument (icon, name, durationRounds) {
|
||||
return {
|
||||
icon,
|
||||
name,
|
||||
duration: { rounds: durationRounds },
|
||||
flags: {
|
||||
swade: {
|
||||
expiration: CONST.SWADE.STATUS_EFFECT_EXPIRATION.EndOfTurnPrompt
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static async applyActiveEffects (token, effectDocuments) {
|
||||
const mutation = {
|
||||
embedded: { ActiveEffect: {} }
|
||||
}
|
||||
const mutateOptions = {
|
||||
permanent: true,
|
||||
description: effectDocuments[effectDocuments.length - 1]
|
||||
}
|
||||
for (const effectDocument of effectDocuments) {
|
||||
mutation.embedded.ActiveEffect[effectDocument.name] = effectDocument
|
||||
}
|
||||
await warpgate.mutate(token.document, mutation, {}, mutateOptions)
|
||||
}
|
||||
|
||||
static warpgateMenu (menuData, menuOptions) {
|
||||
return warpgate.menu(menuData, menuOptions)
|
||||
}
|
||||
}
|
||||
|
||||
export function log (...args) {
|
||||
console.log('SWADE MB HELPERS |', ...args)
|
||||
}
|
||||
Reference in New Issue
Block a user