update macros to use helper functions

This commit is contained in:
Mike Bloy 2023-03-01 17:49:41 -06:00
parent 821d2f36f9
commit b1d7a70185
7 changed files with 82 additions and 206 deletions

View File

@ -88,18 +88,8 @@ async function createEffect (tokens, options) {
if (mods.length > 0) {
namePart = `${namePart} (${mods.join(', ')})`
}
const minorEffect = {
icon,
id: `minor ${namePart}`,
label: `minor ${namePart}`,
duration: { rounds: 5 },
flags: {
swade: {
expiration: CONFIG.SWADE.CONST.STATUS_EFFECT_EXPIRATION.EndOfTurnPrompt,
loseTurnOnHold: true
}
},
changes: [
const minorEffect = swadeMBHelpers.createEffectDocument(
icon, `minor ${namePart}`, 5, [
{
key: options.trait.diekey,
mode,
@ -107,19 +97,9 @@ async function createEffect (tokens, options) {
priority: 0
}
]
}
const majorEffect = {
icon,
id: `major ${namePart}`,
label: `major ${namePart}`,
duration: { rounds: 5 },
flags: {
swade: {
expiration: CONFIG.SWADE.CONST.STATUS_EFFECT_EXPIRATION.EndOfTurnPrompt,
loseTurnOnHold: true
}
},
changes: [
)
const majorEffect = swadeMBHelpers.createEffectDocument(
icon, `major ${namePart}`, 5, [
{
key: options.trait.diekey,
mode,
@ -127,7 +107,7 @@ async function createEffect (tokens, options) {
priority: 0
}
]
}
)
if (options.direction === 'Lower' && options.greater === 'Greater') {
minorEffect.changes.push({
key: options.trait.modkey,
@ -146,12 +126,7 @@ async function createEffect (tokens, options) {
if (raise) {
mutate.embedded.ActiveEffect[majorEffect.id] = majorEffect
}
const mutateOptions = {
comparisonKeys: { ActiveEffect: 'label' },
name: namePart,
permanent: true,
description: namePart
}
const mutateOptions = swadeMBHelpers.defaultMutationOptions(namePart)
for (const token of tokens) {
await warpgate.mutate(token.document, mutate, {}, mutateOptions)
}

View File

@ -30,26 +30,8 @@ async function createEffect (tokens, choice) {
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
}
const mutate = swadeMBHelpers.createMutationWithEffect(icon, effectName, 5, [])
const mutateOptions = swadeMBHelpers.defaultMutationOptions(effectName)
await warpgate.mutate(token.document, mutate, {}, mutateOptions)
}
}

View File

@ -23,53 +23,29 @@ async function createEffect (tokens) {
const icon = 'icons/magic/light/explosion-star-blue-large.webp'
const effectName = 'Glow'
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 = swadeMBHelpers.createMutationWithEffect(icon, effectName, 5, [])
const mutateOptions = swadeMBHelpers.defaultMutationOptions(effectName)
mutate.token = {
light: {
alpha: 0.5,
angle: 360,
attenuation: 0.5,
animation: {
intensity: 5,
reverse: false,
speed: 5,
type: 'starlight'
},
bright: 0,
color: '#0f3fff',
coloration: 1,
contrast: 0,
dim: 0.5,
luminosity: 0.5,
saturation: 0,
shadows: 0
}
}
// const roiling = CONFIG.Canvas.lightAnimations.roiling
const mutate = {
token: {
light: {
alpha: 0.5,
angle: 360,
attenuation: 0.5,
animation: {
intensity: 5,
reverse: false,
speed: 5,
type: 'starlight'
},
bright: 0,
color: '#0f3fff',
coloration: 1,
contrast: 0,
dim: 0.5,
luminosity: 0.5,
saturation: 0,
shadows: 0
}
},
embedded: {
ActiveEffect: {
Glow: effectData
}
}
}
const mutateOptions = {
comparisonKeys: { ActiveEffect: 'label' },
name: effectName,
permanent: false,
description: effectName
}
await warpgate.mutate(token.document, mutate, {}, mutateOptions)
}
}

View File

@ -36,27 +36,9 @@ async function createEffect (tokens, choice) {
effectName = 'major Protection'
}
for (const token of tokens) {
const effectData = {
icon: baseEffect.icon,
id: effectName,
label: effectName,
duration: baseEffect.duration,
flags: {
swade: {
expiration: CONFIG.SWADE.CONST.STATUS_EFFECT_EXPIRATION.EndOfTurnPrompt,
loseTurnOnHold: true
}
},
changes
}
const mutate = { embedded: { ActiveEffect: { } } }
mutate.embedded.ActiveEffect[effectName] = effectData
const mutateOptions = {
comparisonKeys: { ActiveEffect: 'label' },
name: effectName,
permanent: true,
description: baseEffect.label
}
const mutate = swadeMBHelpers.createMutationWithEffect(
baseEffect.icon, effectName, 5, changes)
const mutateOptions = swadeMBHelpers.defaultMutationOptions(effectName)
await warpgate.mutate(token.document, mutate, {}, mutateOptions)
}
}

View File

@ -23,53 +23,29 @@ async function createEffect (tokens) {
const icon = 'icons/magic/perception/silhouette-stealth-shadow.webp'
const effectName = 'Shroud'
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 = swadeMBHelpers.createMutationWithEffect(icon, effectName, 5, [])
const mutateOptions = swadeMBHelpers.defaultMutationOptions(effectName)
mutate.token = {
light: {
alpha: 0.5,
angle: 360,
attenuation: 0.1,
animation: {
intensity: 5,
reverse: false,
speed: 5,
type: 'roiling'
},
bright: 0,
color: null,
coloration: 0,
contrast: 0,
dim: 0.1,
luminosity: -0.15,
saturation: 0,
shadows: 0.25
}
}
// const roiling = CONFIG.Canvas.lightAnimations.roiling
const mutate = {
token: {
light: {
alpha: 0.5,
angle: 360,
attenuation: 0.1,
animation: {
intensity: 5,
reverse: false,
speed: 5,
type: 'roiling'
},
bright: 0,
color: null,
coloration: 0,
contrast: 0,
dim: 0.1,
luminosity: -0.15,
saturation: 0,
shadows: 0.25
}
},
embedded: {
ActiveEffect: {
Shroud: effectData
}
}
}
const mutateOptions = {
comparisonKeys: { ActiveEffect: 'label' },
name: effectName,
permanent: false,
description: effectName
}
await warpgate.mutate(token.document, mutate, {}, mutateOptions)
}
}

View File

@ -11,7 +11,8 @@ async function main (tokens) {
const menuData = {
inputs: [
{ type: 'header', label: 'Smite' },
{ type: 'info', label: `Apply Smite to ${tokenList}` }
{ type: 'info', label: `Apply Smite to ${tokenList}` },
{ type: 'checkbox', label: 'Greater', options: false }
],
buttons: [
{ label: 'Apply', value: 'apply' },
@ -21,7 +22,7 @@ async function main (tokens) {
}
const tokenWeapons = {}
let index = 1
let index = 2
for (const token of tokens) {
index += 2
tokenWeapons[token.id] = index
@ -35,17 +36,20 @@ async function main (tokens) {
for (const tokenId in tokenWeapons) {
tokenWeapons[tokenId] = inputs[tokenWeapons[tokenId]]
}
const greater = (inputs[2] === 'Greater')
if (buttons && buttons !== 'cancel') {
await createEffect(tokens, tokenWeapons, buttons)
await createEffect(tokens, tokenWeapons, buttons, greater)
}
}
async function createEffect (tokens, tokenWeapons, choice) {
async function createEffect (tokens, tokenWeapons, choice, greater) {
const baseEffect = CONFIG.statusEffects.find(se => se.label === 'SWADE.Smite')
const effectIcon = baseEffect.icon
const effectId = baseEffect.id
const changeValue = (choice === 'raise' ? '+4' : '+2')
let changeValue = (choice === 'raise' ? '+4' : '+2')
if (greater) {
changeValue = (choice === 'raise' ? '+6' : '+4')
}
for (const token of tokens) {
const weaponName = tokenWeapons[token.id]
const weaponId = token.actor.items.getName(weaponName)?.id
@ -53,37 +57,18 @@ async function createEffect (tokens, tokenWeapons, choice) {
if (!weaponId) {
continue
}
const effectName = `${choice === 'raise' ? 'major' : 'minor'} Smite (${weaponName})`
const effectData = {
icon: effectIcon,
id: effectId,
label: effectName,
duration: { rounds: 5 },
flags: {
swade: {
expiration: CONFIG.SWADE.CONST.STATUS_EFFECT_EXPIRATION.EndOfTurnPrompt,
loseTurnOnHold: true
}
},
changes: [
{
key: changeKey,
mode: foundry.CONST.ACTIVE_EFFECT_MODES.ADD,
value: changeValue,
priority: 0
}
]
}
const mutate = {
embedded: { ActiveEffect: {} }
}
mutate.embedded.ActiveEffect[effectName] = effectData
const mutateOptions = {
comparisonKeys: { ActiveEffect: 'label' },
name: effectName,
permanent: true,
description: effectName
}
const effectName = `${choice === 'raise' ? 'major' : 'minor'} Smite${greater ? '(greater)' : ''} (${weaponName})`
const changes = [
{
key: changeKey,
mode: foundry.CONST.ACTIVE_EFFECT_MODES.ADD,
value: changeValue,
priority: 0
}
]
const mutate = swadeMBHelpers.createMutationWithEffect(
effectIcon, effectName, 5, changes)
const mutateOptions = swadeMBHelpers.defaultMutationOptions(effectName)
await warpgate.mutate(token.document, mutate, {}, mutateOptions)
}
}

File diff suppressed because one or more lines are too long