Skip to content

Commit

Permalink
feat(item-sheet): added content class to scrollY, dropdowns, and arra…
Browse files Browse the repository at this point in the history
…y handler for techniques and equipments items
  • Loading branch information
SouOWendel committed Oct 3, 2024
1 parent 814aa7b commit e242d23
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
37 changes: 36 additions & 1 deletion module/sheets/item-sheet.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class ShinobiItemSheet extends ItemSheet {
initial: 'description',
},
],
scrollY: [".content"],
});
}

Expand All @@ -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();
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -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')) {
Expand All @@ -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});
}
}

/* -------------------------------------------- */

/* -------------------------------------------- */
Expand Down
7 changes: 5 additions & 2 deletions template.json
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,9 @@
"compartOcupa": null
},
"rarity": "common"
},
"areaTemplate": {
"areaTemplate": []
}
},
"armas": {
Expand Down Expand Up @@ -477,7 +480,7 @@
"dureza": 0
},
"geral": {
"templates": ["base", "fisico"],
"templates": ["base", "fisico", "areaTemplate"],
"tipo": ""
},
"aptidoes": {
Expand All @@ -495,7 +498,7 @@
"efeitosAdquiridos": []
},
"tecnicas": {
"templates": ["base"],
"templates": ["base", "areaTemplate"],
"combate": {
"dano": {
"value": null
Expand Down

0 comments on commit e242d23

Please sign in to comment.