import {Equipment} from "../documents/equipment.mjs"; const { ApplicationV2, HandlebarsApplicationMixin } = foundry.applications.api export class ItemBrowserDialog extends HandlebarsApplicationMixin(ApplicationV2) { static DEFAULT_OPTIONS = { classes: ['dsa41', 'dialog', 'item-browser'], tag: "form", position: { width: 640, height: 480 }, window: { resizable: true, }, actions: { buy: ItemBrowserDialog.#buy } } static PARTS = { form: { template: 'systems/DSA_4-1/templates/dialog/item-browser-dialog.hbs', } } /** * @type {Actor} * @private */ _actor = null /** * * @type {[Equipment]} * @private */ _items = [] constructor(actor) { super(); this._actor = actor // load compendium data this._items = [] } static async #buy(event, target) { } _canDragDrop(event, options) { return game.user.isGM } _canDrag(event, options) { return true } /** * An event that occurs when a drag workflow begins for a draggable item on the sheet. * @param {DragEvent} event The initiating drag start event * @returns {Promise} * @protected */ async _onDragStart(event) { const target = event.currentTarget; let dragData; if (target.dataset.itemId) { dragData = { type: "Item", uuid: target.dataset.itemId } } // Set data transfer if (!dragData) return; event.dataTransfer.setData("text/plain", JSON.stringify(dragData)); } async _prepareContext(options) { const context = await super._prepareContext(options) context.items = this._items return context } async _onRender(context, options) { if (this._items.length === 0) { const compendia = [ game.packs.get('DSA_4-1.Armor'), game.packs.get('DSA_4-1.Weapons'), game.packs.get('DSA_4-1.Ammunition'), game.packs.get('DSA_4-1.Items') ] for (const c of compendia) { const it = await c.getDocuments() it.forEach((item) => { const uuid = item.uuid const e = new Equipment(item) this._items.push({ img: item.img, uuid, type: item.type, name: item.name, price: e.system.price, weight: e.system.weight, category: e.system.category.join(", ") }) console.log("importing ", item.name) }) console.log("done importing from ", c) } this.render({parts: ["form"]}) } new foundry.applications.ux.DragDrop.implementation({ dropSelector: ".window-content", dragSelector: ".item", permissions: { drag: this._canDrag.bind(this) }, callbacks: { dragstart: this._onDragStart.bind(this), } }).bind(this.element) } }