From b4089e4b713d550d29a5f1e396492a636edb886c Mon Sep 17 00:00:00 2001 From: Mike Bloy Date: Sun, 28 Apr 2024 21:38:20 -0500 Subject: [PATCH] temp commit --- scripts/api.js | 2 + scripts/powers.js | 111 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 scripts/powers.js diff --git a/scripts/api.js b/scripts/api.js index 274ff95..6a1b339 100644 --- a/scripts/api.js +++ b/scripts/api.js @@ -1,6 +1,7 @@ import { log, module } from './globals.js' import { requestFearRollFromTokens, requestRollFromTokens } from './helpers.js' import { powerEffects } from './powerEffects.js' +import { powers } from './powers.js' export class api { static registerFunctions () { @@ -14,6 +15,7 @@ export class api { rulesVersion: module.rulesVersion, fearTable: module.fearTableHelper, powerEffects, + powers, requestRollFromTokens, requestFearRollFromTokens } diff --git a/scripts/powers.js b/scripts/powers.js new file mode 100644 index 0000000..85172bd --- /dev/null +++ b/scripts/powers.js @@ -0,0 +1,111 @@ +export async function powers (options = {}) { + const token = 'token' in options ? options.token : null + if (token === undefined || token === null) { + ui.notifications.error('Please select one token to be the caster') + return + } + + const targets = 'targets' in options ? Array.from(options.targets) : [] + const item = 'item' in options ? options.item : null + const swid = options?.name || item?.system.swid || null + + if (swid in PowerClasses) { + const runner = new PowerClasses[name](token, targets) + runner.powerEffect() + return + } + ui.notifications.error(`No power effect found for ${name}`) +} + +const PowerClasses = { + 'burrow': BurrowEffect +} + +class PowerEffect { + constructor (token, targets) { + this.source = token + this.targets = targets + this.modifiers = [ + {name: 'Glow', id: 'glow', value: 1, advanced: false}, + {name: 'Shroud', id: 'shroud', value: 1, advanced: false}, + {name: 'Hinder', id: 'hinder', value: 1, advanced: false}, + {name: 'Hurry', id: 'hurry', value: 1, advanced: false}, + ] + } + + get name () { return 'Unknown Power' } + get icon () { return 'icons/magic/symbols/question-stone-yellow.webp' } + get duration () { return 5 } + + get menuData () { + return { + inputs: this.menuInputs, + buttons: this.menuButtons, + } + } + + get menuInputs () { + const data = [ + { type: 'header', label: `${this.name} Effect` }, + { type: 'info', label: `Apply ${this.name} Effect` }, + ] + if (this.targets.length > 0) { + data.push({ + type: 'info', + label: `Targets: ${this.targets.map(t => t.name).join(',')}` + }) + } + for (const mod of this.modifiers) { + data.push({ + type: 'checkbox', + label: ( + `${mod.advanced ? '⭐ ' : ''}${mod.name} ` + + `(${mod.value >= 0 ? '+' : ''}${mod.value}` + ), + }) + } + data.push({ type: 'header', label: '---------------' }) + return data + } + + get menuButtons () { + const data = [ + { label: 'Apply', value: 'apply' }, + { label: 'Apply with Raise', value: 'raise' }, + { label: 'Cancel', value: 'cancel' } + ] + return data + } + + get menuOptions () { + return { + title: `${this.name} Effect`, + defaultButton: 'Cancel', + options: {} + } + } + + async powerEffect () { + const { buttons, inputs } = await warpgate.menu( + this.menuData, this.menuOptions + ) + this.choice = buttons + this.values = inputs + if (this.choice && this.choice !== 'cancel') { + await this.parseValues() + await this.apply() + } + } + + async parseValues () { + } + + async applyResult () { + } +} + +class BurrowEffect extends PowerEffect { + get name () { return 'Burrow' } + get duration () { return 5 } + get icon () { return 'icons/magic/earth/projectile-stone-landslide.webp' } +}