zombie complete + summon costs setup macro
This commit is contained in:
parent
5cb15bcedd
commit
20871bcdef
@ -1,6 +1,7 @@
|
||||
import { log, moduleHelpers } from './globals.js';
|
||||
import { requestFearRollFromTokens, requestRollFromTokens } from './helpers.js';
|
||||
import { powers } from './powers/powers.js';
|
||||
import { setSummonCosts } from './powers/summonSupport.js';
|
||||
|
||||
export class api {
|
||||
static registerFunctions() {
|
||||
@ -11,11 +12,12 @@ export class api {
|
||||
static globals() {
|
||||
const moduleName = 'swade-mb-helpers';
|
||||
game.modules.get(moduleName).api = {
|
||||
rulesVersion: moduleHelpers.rulesVersion,
|
||||
fearTable: moduleHelpers.fearTableHelper,
|
||||
powerEffects: powers,
|
||||
requestRollFromTokens,
|
||||
requestFearRollFromTokens,
|
||||
requestRollFromTokens,
|
||||
rulesVersion: moduleHelpers.rulesVersion,
|
||||
setSummonCosts,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { BaseSummonEffect } from './summonSupport.js';
|
||||
|
||||
class BaseAllyEffect extends BaseSummonEffect {
|
||||
get values() {
|
||||
return {};
|
||||
get actorFolder() {
|
||||
return `${this.actorFolderBase}/Creatures`;
|
||||
}
|
||||
|
||||
get basePowerPoints() {
|
||||
@ -229,13 +229,17 @@ export class SummonAllyEffect extends BaseAllyEffect {
|
||||
return 'icons/magic/control/silhouette-hold-beam-blue.webp';
|
||||
}
|
||||
|
||||
get values() {
|
||||
return {
|
||||
actorValue(actor) {
|
||||
const values = {
|
||||
attendant: 1,
|
||||
bodyguard: 3,
|
||||
sentinel: 5,
|
||||
'mirror self': 7,
|
||||
};
|
||||
if (actor.name.toLowerCase() in values) {
|
||||
return values[actor.name.toLowerCase()];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
get _edges() {
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
/* globals Portal */
|
||||
import { moduleName } from '../globals.js';
|
||||
import { log, moduleHelpers, moduleName } from '../globals.js';
|
||||
import { templates } from '../preloadTemplates.js';
|
||||
import { ActorFolderEffect } from './basePowers.js';
|
||||
|
||||
export class BaseSummonEffect extends ActorFolderEffect {
|
||||
@ -11,10 +12,6 @@ export class BaseSummonEffect extends ActorFolderEffect {
|
||||
return 'Summonables';
|
||||
}
|
||||
|
||||
get actorFolder() {
|
||||
return `${this.actorFolderBase}/Creatures`;
|
||||
}
|
||||
|
||||
get summonCount() {
|
||||
return 0;
|
||||
}
|
||||
@ -49,3 +46,101 @@ export class BaseSummonEffect extends ActorFolderEffect {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class SummonCostApplication extends FormApplication {
|
||||
constructor(actors, powers) {
|
||||
super();
|
||||
this.actors = actors;
|
||||
this.powers = powers;
|
||||
}
|
||||
|
||||
static get defaultOptions() {
|
||||
return mergeObject(super.defaultOptions, {
|
||||
classes: ['sheet', 'mbSwadeForm', 'mbSwadeSummonCostForm'],
|
||||
popOut: true,
|
||||
template: templates['summonCosts.html'],
|
||||
id: ['mbSwadeSummonCostFormApplication'],
|
||||
title: 'Summoning Costs',
|
||||
width: 750,
|
||||
});
|
||||
}
|
||||
|
||||
getData() {
|
||||
const actorNames = Object.keys(this.actors).map((k) => {
|
||||
let splitName = k.split(' | ');
|
||||
splitName.pop();
|
||||
let folder = splitName.length ? splitName.join(' | ') : '';
|
||||
return { name: this.actors[k].name, folder, fullName: k };
|
||||
});
|
||||
actorNames.sort((a, b) => {
|
||||
if (a.name < b.name) {
|
||||
return -1;
|
||||
} else if (a.name > b.name) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
const data = {
|
||||
powers: this.powers,
|
||||
actors: [],
|
||||
};
|
||||
for (const actor of actorNames) {
|
||||
const summon = this.actors[actor.fullName].getFlag(moduleName, 'summonData') ?? {
|
||||
cost: 0,
|
||||
powers: {},
|
||||
};
|
||||
const hbSummon = {
|
||||
cost: summon.cost,
|
||||
powers: [],
|
||||
};
|
||||
for (const power of this.powers) {
|
||||
hbSummon.powers.push({ power, value: summon.powers?.[power] ?? false });
|
||||
}
|
||||
data.actors.push({ actor, summon: hbSummon });
|
||||
}
|
||||
log('summon data');
|
||||
log(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
async _updateObject(ev, formData) {
|
||||
const submit = ev?.submitter?.value ?? 'cancel';
|
||||
if (submit === 'cancel') {
|
||||
return;
|
||||
}
|
||||
log('FORMDATA |', formData);
|
||||
const updates = {};
|
||||
for (const key of Object.keys(formData)) {
|
||||
const value = formData[key];
|
||||
const [name, subKey] = key.split(':;:');
|
||||
if (!(name in updates)) {
|
||||
updates[name] = { powers: {} };
|
||||
}
|
||||
if (subKey === 'cost') {
|
||||
updates[name].cost = value;
|
||||
} else {
|
||||
updates[name].powers[subKey] = value;
|
||||
}
|
||||
}
|
||||
log('FORMUPDATES |', updates);
|
||||
for (const key of Object.keys(updates)) {
|
||||
const update = updates[key];
|
||||
const flagValue = this.actors[key].getFlag(moduleName, 'summonData') ?? {};
|
||||
mergeObject(flagValue, update);
|
||||
const result = this.actors[key].setFlag(moduleName, 'summonData', flagValue);
|
||||
console.log('update', key, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function setSummonCosts(powers = [], folderName = null) {
|
||||
if (!folderName) {
|
||||
folderName = 'Summonables/Creatures';
|
||||
}
|
||||
const folder = moduleHelpers.getActorFolderByPath(folderName);
|
||||
if (!folder) {
|
||||
log(`ERROR: Could not find folder ${folderName}`);
|
||||
}
|
||||
const actors = moduleHelpers.getActorsInFolder(folder);
|
||||
new SummonCostApplication(actors, powers).render(true);
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
const _templatePaths = ['powerDialog.html'];
|
||||
const _templatePaths = ['powerDialog.html', 'summonCosts.html'];
|
||||
|
||||
export async function preloadTemplates() {
|
||||
return loadTemplates(_templatePaths.map((f) => `modules/swade-mb-helpers/templates/${f}`));
|
||||
|
||||
@ -3,3 +3,10 @@
|
||||
font-size: var(--font-size-14);
|
||||
}
|
||||
}
|
||||
|
||||
table.mbForm {
|
||||
th {
|
||||
padding-left: 0.25em;
|
||||
padding-right: 0.25em;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
<form class="flexcol"><!-- vim: set ft=handlebars: -->
|
||||
<form class="flexcol"><!-- vim: set ft=handlebars.html: -->
|
||||
<header class="sheet-header flexrow">
|
||||
<img src="{{icon}}" height="64" width="64" title="{{name}} Effect" alt=" " />
|
||||
<section class="flexcol">
|
||||
|
||||
44
src/templates/summonCosts.html
Normal file
44
src/templates/summonCosts.html
Normal file
@ -0,0 +1,44 @@
|
||||
<form class='flexcol'>
|
||||
<!-- vim: set ft=handlebars.html:-->
|
||||
<header class='sheet-header'>
|
||||
<h2>Set Summon Parameters</h2>
|
||||
</header>
|
||||
<table class="mbForm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th rowspan='2'>Folder</th>
|
||||
<th rowspan='2'>Actor</th>
|
||||
<th rowspan='2'>Cost</th>
|
||||
<th colspan='{{powers.length}}'>Available Powers</th>
|
||||
</tr>
|
||||
<tr>
|
||||
{{#each powers}}
|
||||
<th>{{this}}?</th>
|
||||
{{/each}}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#each actors}}
|
||||
<tr>
|
||||
<td>{{actor.folder}}</td>
|
||||
<td>{{actor.name}}</td>
|
||||
<td><input type="number"
|
||||
value="{{summon.cost}}"
|
||||
name="{{actor.fullName}}:;:cost"
|
||||
step="1"
|
||||
min="0"/></td>
|
||||
{{#each summon.powers}}
|
||||
<td align="center"><input
|
||||
type="checkbox"
|
||||
name="{{../actor.fullName}}:;:{{power}}"
|
||||
{{checked value}}></td>
|
||||
{{/each}}
|
||||
</tr>
|
||||
{{/each}}
|
||||
</tbody>
|
||||
</table>
|
||||
<footer class="sheet-footer flexrow">
|
||||
<button type="submit" name="submit" value="submit">Submit</button>
|
||||
<button type="submit" name="submit" value="cancel">Cancel</button>
|
||||
</footer>
|
||||
</form>
|
||||
Loading…
x
Reference in New Issue
Block a user