mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 03:31:07 +01:00
Feature/200 beastform (#255)
* Temp * Dialog setup * Fixed basic beastform * Reworked beastform to hold it's data entirely in the beastformEffect * UpdateActorTokens fix * Removed hardcoded tierlimit on beastform * PR fixes
This commit is contained in:
parent
c4448226e0
commit
d071fadf7d
41 changed files with 1102 additions and 298 deletions
86
module/dialogs/beastformDialog.mjs
Normal file
86
module/dialogs/beastformDialog.mjs
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
import { tiers } from '../config/generalConfig.mjs';
|
||||
|
||||
const { ApplicationV2, HandlebarsApplicationMixin } = foundry.applications.api;
|
||||
|
||||
export default class BeastformDialog extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||
constructor(configData) {
|
||||
super();
|
||||
|
||||
this.configData = configData;
|
||||
this.selected = null;
|
||||
}
|
||||
|
||||
static DEFAULT_OPTIONS = {
|
||||
tag: 'form',
|
||||
classes: ['daggerheart', 'views', 'dh-style', 'beastform-selection'],
|
||||
position: {
|
||||
width: 600,
|
||||
height: 'auto'
|
||||
},
|
||||
actions: {
|
||||
selectBeastform: this.selectBeastform,
|
||||
submitBeastform: this.submitBeastform
|
||||
},
|
||||
form: {
|
||||
handler: this.updateBeastform,
|
||||
submitOnChange: true,
|
||||
submitOnClose: false
|
||||
}
|
||||
};
|
||||
|
||||
get title() {
|
||||
return game.i18n.localize('DAGGERHEART.Sheets.Beastform.dialogTitle');
|
||||
}
|
||||
|
||||
/** @override */
|
||||
static PARTS = {
|
||||
beastform: {
|
||||
template: 'systems/daggerheart/templates/views/beastformDialog.hbs'
|
||||
}
|
||||
};
|
||||
|
||||
async _prepareContext(_options) {
|
||||
const context = await super._prepareContext(_options);
|
||||
|
||||
context.beastformTiers = game.items.reduce((acc, x) => {
|
||||
const tier = tiers[x.system.tier];
|
||||
if (x.type !== 'beastform' || tier.value > this.configData.tierLimit) return acc;
|
||||
|
||||
if (!acc[tier.value]) acc[tier.value] = { label: game.i18n.localize(tier.label), values: {} };
|
||||
acc[tier.value].values[x.uuid] = { selected: this.selected == x.uuid, value: x };
|
||||
|
||||
return acc;
|
||||
}, {}); // Also get from compendium when added
|
||||
context.canSubmit = this.selected;
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
static updateBeastform(event, _, formData) {
|
||||
this.selected = foundry.utils.mergeObject(this.selected, formData.object);
|
||||
|
||||
this.render();
|
||||
}
|
||||
|
||||
static selectBeastform(_, target) {
|
||||
this.selected = this.selected === target.dataset.uuid ? null : target.dataset.uuid;
|
||||
this.render();
|
||||
}
|
||||
|
||||
static async submitBeastform() {
|
||||
await this.close({ submitted: true });
|
||||
}
|
||||
|
||||
/** @override */
|
||||
_onClose(options = {}) {
|
||||
if (!options.submitted) this.config = false;
|
||||
}
|
||||
|
||||
static async configure(configData) {
|
||||
return new Promise(resolve => {
|
||||
const app = new this(configData);
|
||||
app.addEventListener('close', () => resolve(app.selected), { once: true });
|
||||
app.render({ force: true });
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue