From e242d236874f29208dc86608b844ccb0e471fb94 Mon Sep 17 00:00:00 2001 From: "Wendel Henrique (SouOWendel)" Date: Thu, 3 Oct 2024 14:38:01 -0300 Subject: [PATCH] feat(item-sheet): added content class to scrollY, dropdowns, and array handler for techniques and equipments items --- module/sheets/item-sheet.mjs | 37 +++++++++++++++++++++++++++++++++++- template.json | 7 +++++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/module/sheets/item-sheet.mjs b/module/sheets/item-sheet.mjs index 5f10807..2d1a943 100644 --- a/module/sheets/item-sheet.mjs +++ b/module/sheets/item-sheet.mjs @@ -22,6 +22,7 @@ export class ShinobiItemSheet extends ItemSheet { initial: 'description', }, ], + scrollY: [".content"], }); } @@ -45,6 +46,8 @@ export class ShinobiItemSheet extends ItemSheet { // Dropdown context.itemsDropdown = CONFIG.shinobiNoSho.ITEMS.dropdown; context.combatAbilities = CONFIG.shinobiNoSho.combatAbilities; + context.areas = CONFIG.shinobiNoSho.templateAreas; + context.regraArea = CONFIG.shinobiNoSho.areaRule; // Retrieve the roll data for TinyMCE editors. context.rollData = this.item.getRollData(); @@ -64,6 +67,7 @@ export class ShinobiItemSheet extends ItemSheet { const formData = foundry.utils.expandObject( super._getSubmitData(updateData), ); + const system = formData.system; // Handle Family array const arma = formData.system?.combate?.dano; @@ -73,11 +77,16 @@ export class ShinobiItemSheet extends ItemSheet { } // Handle Family array - const system = formData.system; if (system.efeitosAdquiridos) { system.efeitosAdquiridos = Object.values(system.efeitosAdquiridos || {}).map((d) => [ d[0] || '', d[1] || '']); } + + // Handle Area array + if (system.areaTemplate) { + system.areaTemplate = Object.values(system.areaTemplate || {}).map((d) => [ + d[0] || '', d[1] || '', d[2] || '', d[3] || '', d[4] || '']); + } // Return the flattened submission data return foundry.utils.flattenObject(formData); @@ -99,6 +108,9 @@ export class ShinobiItemSheet extends ItemSheet { // Effects Power html.find('.effectsPower-control').click(this._onEffectsPowerControl.bind(this)); + // Area Template Control + html.find('.areaTemplate-control').click(this._onAreaTemplateControl.bind(this)); + // Active Effect management html.on('click', '.effect-control', (ev) => onManageActiveEffect(ev, this.item) @@ -128,6 +140,7 @@ export class ShinobiItemSheet extends ItemSheet { async _onEffectsPowerControl(event){ event.preventDefault(); + event.stopPropagation(); const a = event.currentTarget; if (a.classList.contains('add-effectsPower')) { @@ -147,6 +160,28 @@ export class ShinobiItemSheet extends ItemSheet { } } + async _onAreaTemplateControl(event){ + event.preventDefault(); + event.stopPropagation(); + const a = event.currentTarget; + + if (a.classList.contains('add-areaTemplate')) { + await this._onSubmit(event); + const areas = this.item.system.areaTemplate; + return this.item.update({ + 'system.areaTemplate': areas.concat([['','','','','']]), + }); + } + + if (a.classList.contains('delete-areaTemplate')) { + await this._onSubmit(event); + const html = a.closest('.areaTemplate-part'); + const areas = foundry.utils.deepClone(this.item.system.areaTemplate); + areas.splice(Number(html.dataset.effectsPart), 1); + return this.item.update({'system.areaTemplate': areas}); + } + } + /* -------------------------------------------- */ /* -------------------------------------------- */ diff --git a/template.json b/template.json index 67291e5..b4aed13 100644 --- a/template.json +++ b/template.json @@ -432,6 +432,9 @@ "compartOcupa": null }, "rarity": "common" + }, + "areaTemplate": { + "areaTemplate": [] } }, "armas": { @@ -477,7 +480,7 @@ "dureza": 0 }, "geral": { - "templates": ["base", "fisico"], + "templates": ["base", "fisico", "areaTemplate"], "tipo": "" }, "aptidoes": { @@ -495,7 +498,7 @@ "efeitosAdquiridos": [] }, "tecnicas": { - "templates": ["base"], + "templates": ["base", "areaTemplate"], "combate": { "dano": { "value": null