develop #34
@ -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)
|
||||
})
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user