mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 03:31:07 +01:00
Restore ItemTransferDialog subclass for module use
This commit is contained in:
parent
e506ef177f
commit
a133d5b41b
4 changed files with 95 additions and 53 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';
|
||||
|
|
|
|||
62
module/applications/dialogs/itemTransfer.mjs
Normal file
62
module/applications/dialogs/itemTransfer.mjs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
|
||||
|
||||
export default class ItemTransferDialog extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||
constructor(data) {
|
||||
super({});
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
get title() {
|
||||
return this.data.title;
|
||||
}
|
||||
|
||||
static DEFAULT_OPTIONS = {
|
||||
tag: 'form',
|
||||
classes: ['daggerheart', 'dh-style', 'dialog', 'item-transfer'],
|
||||
position: { width: 400, height: 'auto' },
|
||||
window: { icon: 'fa-solid fa-hand-holding-hand' },
|
||||
actions: {
|
||||
finish: ItemTransferDialog.#finish
|
||||
}
|
||||
};
|
||||
|
||||
static PARTS = {
|
||||
main: { template: 'systems/daggerheart/templates/dialogs/item-transfer.hbs', root: true }
|
||||
};
|
||||
|
||||
async _prepareContext(_options) {
|
||||
const context = await super._prepareContext(_options);
|
||||
return foundry.utils.mergeObject(context, this.data);
|
||||
}
|
||||
|
||||
static async #finish() {
|
||||
this.selected = this.form.elements.quantity.valueAsNumber || null;
|
||||
this.close();
|
||||
}
|
||||
|
||||
static #determineTransferOptions({ originActor, targetActor, item, currency }) {
|
||||
originActor ??= item?.actor;
|
||||
const homebrewKey = CONFIG.DH.SETTINGS.gameSettings.Homebrew;
|
||||
const currencySetting = game.settings.get(CONFIG.DH.id, homebrewKey).currency?.[currency] ?? null;
|
||||
|
||||
return {
|
||||
originActor,
|
||||
targetActor,
|
||||
itemImage: item?.img,
|
||||
currencyIcon: currencySetting?.icon,
|
||||
max: item?.system.quantity ?? originActor.system.gold[currency] ?? 0,
|
||||
title: item?.name ?? currencySetting?.label
|
||||
};
|
||||
}
|
||||
|
||||
static async configure(options) {
|
||||
return new Promise(resolve => {
|
||||
const data = this.#determineTransferOptions(options);
|
||||
if (data.max <= 1) return resolve(data.max);
|
||||
|
||||
const app = new this(data);
|
||||
app.addEventListener('close', () => resolve(app.selected), { once: true });
|
||||
app.render({ force: true });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -257,42 +257,6 @@ export default class DHBaseActorSheet extends DHApplicationMixin(ActorSheetV2) {
|
|||
/* Application Drag/Drop */
|
||||
/* -------------------------------------------- */
|
||||
|
||||
async #determineTransferQuantity({ originActor, item, currency }) {
|
||||
originActor ??= item?.actor;
|
||||
const max = item?.system.quantity ?? originActor.system.gold[currency] ?? null;
|
||||
if (!max || max === 0) return null;
|
||||
if (max === 1) return max;
|
||||
|
||||
const homebrewKey = CONFIG.DH.SETTINGS.gameSettings.Homebrew;
|
||||
const currencySetting = game.settings.get(CONFIG.DH.id, homebrewKey).currency?.[currency] ?? null;
|
||||
const name = item?.name ?? currencySetting?.label;
|
||||
|
||||
return foundry.applications.api.DialogV2.input({
|
||||
classes: ['daggerheart', 'dh-style', "item-transfer"],
|
||||
content: await foundry.applications.handlebars.renderTemplate(
|
||||
"systems/daggerheart/templates/dialogs/item-transfer.hbs",
|
||||
{
|
||||
originActor: originActor,
|
||||
targetActor: this.document,
|
||||
itemImage: item?.img,
|
||||
currencyIcon: currencySetting?.icon,
|
||||
max,
|
||||
}
|
||||
),
|
||||
window: {
|
||||
title: name,
|
||||
icon: 'fa-solid fa-hand-holding-hand'
|
||||
},
|
||||
position: {
|
||||
width: 400,
|
||||
},
|
||||
ok: {
|
||||
label: game.i18n.localize("DAGGERHEART.APPLICATIONS.ItemTransfer.transfer"),
|
||||
callback: (_, button) => button.form.elements.quantity.value || null,
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async _onDrop(event) {
|
||||
event.stopPropagation();
|
||||
const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event);
|
||||
|
|
@ -300,7 +264,11 @@ export default class DHBaseActorSheet extends DHApplicationMixin(ActorSheetV2) {
|
|||
const originActor = await foundry.utils.fromUuid(data.originActor);
|
||||
if (!originActor || originActor.uuid === this.document.uuid) return;
|
||||
const currency = data.currency;
|
||||
const quantity = await this.#determineTransferQuantity({ originActor, currency });
|
||||
const quantity = await game.system.api.applications.dialogs.ItemTransferDialog.configure({
|
||||
originActor,
|
||||
targetActor: this.document,
|
||||
currency
|
||||
});
|
||||
if (quantity) {
|
||||
originActor.update({ [`system.gold.${currency}`]: Math.max(0, originActor.system.gold[currency] - quantity) });
|
||||
this.document.update({ [`system.gold.${currency}`]: this.document.system.gold[currency] + quantity });
|
||||
|
|
@ -326,7 +294,10 @@ export default class DHBaseActorSheet extends DHApplicationMixin(ActorSheetV2) {
|
|||
if (item.system.metadata.isInventoryItem) {
|
||||
if (item.system.metadata.isQuantifiable) {
|
||||
const actorItem = originActor.items.get(data.originId);
|
||||
const quantityTransfered = await this.#determineTransferQuantity({ item });
|
||||
const quantityTransfered = await game.system.api.applications.dialogs.ItemTransferDialog.configure({
|
||||
item,
|
||||
targetActor: this.document
|
||||
});
|
||||
|
||||
if (quantityTransfered) {
|
||||
if (quantityTransfered === actorItem.system.quantity) {
|
||||
|
|
|
|||
|
|
@ -1,18 +1,26 @@
|
|||
<div class="summary">
|
||||
<img class="actor-img" src="{{originActor.img}}" />
|
||||
<div class="granted-item">
|
||||
{{#if itemImage}}
|
||||
<img src="{{itemImage}}" />
|
||||
{{else}}
|
||||
<i inert class="currency-icon {{currencyIcon}}"></i>
|
||||
{{/if}}
|
||||
<i inert class="fa-solid fa-hand-holding"></i>
|
||||
<div class="dialog-content standard-form">
|
||||
<div class="summary">
|
||||
<img class="actor-img" src="{{originActor.img}}" />
|
||||
<div class="granted-item">
|
||||
{{#if itemImage}}
|
||||
<img src="{{itemImage}}" />
|
||||
{{else}}
|
||||
<i inert class="currency-icon {{currencyIcon}}"></i>
|
||||
{{/if}}
|
||||
<i inert class="fa-solid fa-hand-holding"></i>
|
||||
</div>
|
||||
<img class="actor-img" src="{{targetActor.img}}" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>{{localize "DAGGERHEART.GENERAL.quantity"}}</label>
|
||||
<div class="form-fields">
|
||||
<range-picker step="1" min="1" max="{{max}}" name="quantity" value="{{max}}"></range-picker>
|
||||
</div>
|
||||
</div>
|
||||
<img class="actor-img" src="{{targetActor.img}}" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>{{localize "DAGGERHEART.GENERAL.quantity"}}</label>
|
||||
<div class="form-fields">
|
||||
<range-picker step="1" min="1" max="{{max}}" name="quantity" value="{{max}}"></range-picker>
|
||||
</div>
|
||||
<div class="dialog-buttons">
|
||||
<button type="button" data-action="finish">
|
||||
<i inert class="fa-solid fa-gift"></i>
|
||||
{{localize "DAGGERHEART.APPLICATIONS.ItemTransfer.transfer"}}
|
||||
</button>
|
||||
</div>
|
||||
Loading…
Add table
Add a link
Reference in a new issue