mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-13 04:01:06 +01:00
Added transfer logic
This commit is contained in:
parent
e701786f45
commit
b73c59dab7
9 changed files with 180 additions and 4 deletions
|
|
@ -6,6 +6,7 @@ export { default as DamageReductionDialog } from './damageReductionDialog.mjs';
|
|||
export { default as DeathMove } from './deathMove.mjs';
|
||||
export { default as Downtime } from './downtime.mjs';
|
||||
export { default as ImageSelectDialog } from './imageSelectDialog.mjs';
|
||||
export { default as ItemTransferDialog } from './itemTransfer.mjs';
|
||||
export { default as MulticlassChoiceDialog } from './multiclassChoiceDialog.mjs';
|
||||
export { default as OwnershipSelection } from './ownershipSelection.mjs';
|
||||
export { default as RerollDamageDialog } from './rerollDamageDialog.mjs';
|
||||
|
|
|
|||
69
module/applications/dialogs/itemTransfer.mjs
Normal file
69
module/applications/dialogs/itemTransfer.mjs
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
|
||||
|
||||
export default class ItemTransferDialog extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||
constructor(item) {
|
||||
super({});
|
||||
|
||||
this.item = item;
|
||||
this.quantity = item.system.quantity;
|
||||
}
|
||||
|
||||
static DEFAULT_OPTIONS = {
|
||||
tag: 'form',
|
||||
classes: ['daggerheart', 'dh-style', 'dialog', 'item-transfer'],
|
||||
position: { width: 300, height: 'auto' },
|
||||
window: { title: 'Transfer Quantity' },
|
||||
actions: {
|
||||
finish: ItemTransferDialog.#finish
|
||||
},
|
||||
form: { handler: this.updateData, submitOnChange: true, closeOnSubmit: false }
|
||||
};
|
||||
|
||||
static PARTS = {
|
||||
main: { template: 'systems/daggerheart/templates/dialogs/item-transfer/main.hbs' },
|
||||
footer: { template: 'systems/daggerheart/templates/dialogs/item-transfer/footer.hbs' }
|
||||
};
|
||||
|
||||
_attachPartListeners(partId, htmlElement, options) {
|
||||
super._attachPartListeners(partId, htmlElement, options);
|
||||
|
||||
if (partId === 'main') {
|
||||
htmlElement.querySelector('.number-display').addEventListener('change', event => {
|
||||
this.quantity = isNaN(event.target.value) ? this.quantity : Number(event.target.value);
|
||||
this.render();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async _prepareContext(_options) {
|
||||
const context = await super._prepareContext(_options);
|
||||
context.item = this.item;
|
||||
context.quantity = this.quantity;
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
static async updateData(_event, _element, formData) {
|
||||
const { quantity } = foundry.utils.expandObject(formData.object);
|
||||
this.quantity = quantity;
|
||||
this.render();
|
||||
}
|
||||
|
||||
static async #finish() {
|
||||
this.close({ submitted: true });
|
||||
}
|
||||
|
||||
close(options = {}) {
|
||||
if (!options.submitted) this.quantity = null;
|
||||
|
||||
super.close();
|
||||
}
|
||||
|
||||
static async configure(item) {
|
||||
return new Promise(resolve => {
|
||||
const app = new this(item);
|
||||
app.addEventListener('close', () => resolve(app.quantity), { once: true });
|
||||
app.render({ force: true });
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue