add deflection macro, fix close button behavior for all macros

This commit is contained in:
Mike Bloy 2023-02-28 22:50:10 -06:00
parent 310ea55f21
commit 38a60f8671
5 changed files with 62 additions and 6 deletions

View File

@ -57,7 +57,7 @@ async function main (tokens) {
]
}
const { buttons, inputs } = await warpgate.menu(menuData, menuOptions)
if (buttons !== 'cancel') {
if (buttons && buttons !== 'cancel') {
const options = {
action: buttons,
name: inputs[2],

55
macros/deflection.js Normal file
View File

@ -0,0 +1,55 @@
swadeMBHelpers.runOnTargetOrSelectedTokens(main)
async function main (tokens) {
const tokenList = tokens.map(t => t.name).join(', ')
const dialogOptions = {
title: 'Deflection',
content: `Apply <em>Deflection</em> to ${tokenList}`,
default: 'cancel',
buttons: [
{ label: 'Apply (melee)', value: 'melee' },
{ label: 'Apply (ranged)', value: 'ranged' },
{ label: 'Apply with raise (both)', value: 'raise' },
{ label: 'Cancel', value: 'cancel' }
]
}
const choice = await warpgate.buttonDialog(dialogOptions)
if (choice && choice !== 'cancel') {
await createEffect(tokens, choice)
}
}
async function createEffect (tokens, choice) {
const icon = 'icons/magic/defensive/shield-barrier-deflect-teal.webp'
let effectName = 'Deflection'
if (choice === 'raise') {
effectName = `${effectName} (all)`
} else {
effectName = `${effectName} (${choice})`
}
for (const token of tokens) {
const effectData = {
icon,
id: effectName,
label: effectName,
duration: { rounds: 5 },
flags: {
swade: {
expiration: CONFIG.SWADE.CONST.STATUS_EFFECT_EXPIRATION.EndOfTurnPrompt,
loseTurnOnHold: true
}
}
}
const mutate = { embedded: { ActiveEffect: { } } }
mutate.embedded.ActiveEffect[effectName] = effectData
const mutateOptions = {
comparisonKeys: { ActiveEffect: 'label' },
name: effectName,
permanent: true,
description: effectName
}
await warpgate.mutate(token.document, mutate, {}, mutateOptions)
}
}

View File

@ -15,7 +15,7 @@ async function main (tokens) {
const choice = await warpgate.buttonDialog(dialogOptions)
if (choice !== 'cancel') {
if (choice && choice !== 'cancel') {
await createEffect(tokens, choice)
}
}

View File

@ -36,7 +36,7 @@ async function main (tokens) {
tokenWeapons[tokenId] = inputs[tokenWeapons[tokenId]]
}
if (buttons !== 'cancel') {
if (buttons && buttons !== 'cancel') {
await createEffect(tokens, tokenWeapons, buttons)
}
}

File diff suppressed because one or more lines are too long