From ea4129c927117e002494bb04318c491380e31bab Mon Sep 17 00:00:00 2001 From: Mike Bloy Date: Mon, 25 Sep 2023 00:12:48 -0500 Subject: [PATCH] finish shape change functionality --- scripts/module.js | 2 ++ scripts/powerEffects.js | 47 +++++++++++++++++++++++++++++++++++------ scripts/shim.js | 12 +++++++---- 3 files changed, 51 insertions(+), 10 deletions(-) diff --git a/scripts/module.js b/scripts/module.js index 71ec9e8..70760fe 100644 --- a/scripts/module.js +++ b/scripts/module.js @@ -1,4 +1,5 @@ import { api } from './api.js' +import { shapeChangeOnDismiss } from './powerEffects.js' import { log } from './shim.js' function _checkModule (name) { @@ -15,4 +16,5 @@ Hooks.on('setup', api.registerFunctions) Hooks.on('ready', () => { _checkModule('warpgate') log('Initialized SWADE MB Helpers') + warpgate.event.watch(warpgate.EVENT.DISMISS, shapeChangeOnDismiss) }) diff --git a/scripts/powerEffects.js b/scripts/powerEffects.js index 6d21fcd..4a324d1 100644 --- a/scripts/powerEffects.js +++ b/scripts/powerEffects.js @@ -684,6 +684,9 @@ class ShapeChangeEffect extends TargetedPowerEffect { } }, token: { + flags: { + 'swade-mb-helpers.shapeChange.srcTokenId': this.targets[0].id + }, actorLink: false, name: `${this.targets[0].name} (${this.protoDoc.name} form) `, elevation: this.targets[0].document.elevation, @@ -720,11 +723,20 @@ class ShapeChangeEffect extends TargetedPowerEffect { {}, this.spawnOptions ))[0] - if (!this.targets[0].document.hidden) { - await this.targets[0].toggleVisibility() - } - await this.targets[0].document.setFlag('swade-mb-helpers', 'shapeChange.to', newTokenId) - await this.targets[0].document.update({ x: 0, y: 0 }) + await this.targets[0].document.setFlag('swade-mb-helpers', 'shapeChange', { + toId: newTokenId, + saved: { + alpha: this.targets[0].document.alpha, + hidden: this.targets[0].document.hidden, + x: this.targets[0].document.x, + y: this.targets[0].document.y, + elevation: this.targets[0].document.elevation + } + }) + await this.targets[0].document.update({ + hidden: true, + alpha: 0.05 + }) } } @@ -1195,7 +1207,8 @@ const PowerClasses = { 'summon monster': SummonMonsterEffect, "summon nature's ally": SummonNaturesAllyEffect, 'summon planar ally': SummonPlanarAllyEffect, - 'summon undead': SummonUndeadEffect + 'summon undead': SummonUndeadEffect, + zombie: SummonUndeadEffect } export async function powerEffects (options = {}) { @@ -1219,3 +1232,25 @@ export async function powerEffects (options = {}) { } shim.notifications.error(`No power effect found for ${name}`) } + +export async function shapeChangeOnDismiss (data) { + if (shim.user.id !== data.userId) { return } + const dismissedToken = data.actorData.prototypeToken + const flags = dismissedToken.flags['swade-mb-helpers']?.shapeChange + const srcTokenId = flags?.srcTokenId + if (!srcTokenId) { return } + const scene = shim.scenes.get(data.sceneId) + const token = scene.tokens.get(srcTokenId) + if (!token) { return } + const saved = token.flags['swade-mb-helpers']?.shapeChange?.saved + if (saved) { + const update = { + alpha: saved.alpha, + hidden: saved.hidden, + x: dismissedToken.x, + y: dismissedToken.y, + elevation: dismissedToken.elevation + } + await token.update(update) + } +} diff --git a/scripts/shim.js b/scripts/shim.js index 28f3384..fef99b3 100644 --- a/scripts/shim.js +++ b/scripts/shim.js @@ -33,18 +33,22 @@ export class shim { return game.user.targets } - static get notifications () { - return ui.notifications - } - static get user () { return game.user } + static get notifications () { + return ui.notifications + } + static get actors () { return game.actors } + static get scenes () { + return game.scenes + } + static mergeObject (...args) { return mergeObject(...args) }