import { ViewData, MerchantData } from './data.mjs'; export class MerchantForm extends FormApplication { viewData = new ViewData(); static get defaultOptions() { return foundry.utils.mergeObject(super.defaultOptions, { object: {}, template: "./modules/test_tube_merchant/templates/merchant.hbs", popOut: true, resizable: true, title: game.i18n.localize("TTM.name"), }); } getData(options) { const data = super.getData(options); data.footer = `${game.i18n.localize("TTM.footer")} ${game.i18n.localize("TTM.boostSite")}`; data.itemsTypes = this.viewData.itemsTypes; data.categories = this.viewData.categories; return data; } async _render(force, options) { await super._render(force, options); this._bindEvents(); } _bindEvents() { const html = this.element; html.find('#setNewMerchant').on('click', async () => { const tokens = canvas.tokens.controlled; merchantData.newMerchant(tokens, this.merchantItemsTypes, this.categoriesTypes); }); html.find('#editMerchant').on('click', async () => { const tokens = canvas.tokens.controlled; merchantData.editMerchant(tokens, this.merchantItemsTypes, this.categoriesTypes); }); html.find('#randomCategories').on('click', async () => { const categories = await merchantData.randomLevelWithDice(); this.categoriesTypes.value = categories; }); html.find('#randomTypes').on('click', async () => { const types = await merchantData.randomTypesWithDice(this.viewData.itemsTypes); this.merchantItemsTypes.value = types; }); html.find('#randomMerchant').on('click', async () => { const tokens = canvas.tokens.controlled; const itemsTypes = this.viewData.itemsTypes; await merchantData.randomMerchant(tokens, this.merchantItemsTypes, this.categoriesTypes, itemsTypes); }); } async formLoading(html) { this.merchantItemsTypes = html.find('[id="MerchantItemsTypes"]')[0]; this.categoriesTypes = html.find('[id="CategoriesTypes"]')[0]; } activateListeners(html) { this.formLoading(html); } } export const merchantData = new MerchantData();