overcomplicated it

This commit is contained in:
Nikhil Nagarajan 2026-01-16 10:40:54 -05:00
parent 209963405f
commit 1c3e2f019c
2 changed files with 30 additions and 23 deletions

View file

@ -37,10 +37,10 @@ export default class DhRollTableSheet extends foundry.applications.sheets.RollTa
}); });
this.daggerheartFlag.altFormula.forEach((alt,i) =>{ this.daggerheartFlag.altFormula.forEach((alt,i) =>{
formulas.push({ formulas.push({
index: i+1, index: i+1, //Logic stores not from 0 but from 1 onwards
key: alt.key, key: alt.key,
formula: alt.formula, formula: alt.formula,
formulaInputName:`flags.daggerheart.altFormula.${i}.formula`, formulaInputName:`flags.daggerheart.altFormula.${i}.formula`, //for .hbs
keyInputName: `flags.daggerheart.altFormula.${i}.key` keyInputName: `flags.daggerheart.altFormula.${i}.key`
}); });
}); });
@ -76,26 +76,33 @@ export default class DhRollTableSheet extends foundry.applications.sheets.RollTa
static async #onRemoveAltFormula(_event, target) { static async #onRemoveAltFormula(_event, target) {
const visualIndex = parseInt(target.dataset.index); const visualIndex = parseInt(target.dataset.index);
const currentAltFormula=this.daggerheartFlag.altFormula; // const currentAltFormula=this.daggerheartFlag.altFormula;
if(visualIndex===0) {//If deleting formula at [0] index // if(visualIndex===0) {//If deleting formula at [0] index
if(currentAltFormula.length>0) { // if(currentAltFormula.length>0) { //atleast 2 or more entries in altFormula
const newCore = currentAltFormula[0]; // const newCore = currentAltFormula[0];
const newAlt = currentAltFormula.slice(1); // const newAlt = currentAltFormula.slice(1);
await this.document.update({formula: newCore.formula}); // // await this.document.update({formula: newCore.formula});
await this.daggerheartFlag.updateSource({ // await this.daggerheartFlag.updateSource({
formulaName:newCore.key, // formulaName:newCore.key,
altFormula:newAlt // altFormula:newAlt
}); // });
} else { // }
await this.document.update({ formula: "" }); // // } else { //I feel this logic is flawed for what I intended for exactly 2 entries (if one it prepares differently)
await this.daggerheartFlag.updateSource({ formulaName: "" }); // // const newCore = currentAltFormula[0];
} // // // await this.document.update({ formula: newCore.formula });
} else { // // await this.daggerheartFlag.updateSource({
const arrayIndex = visualIndex - 1; // // formulaName: "",
await this.daggerheartFlag.updateSource({ // // altFormula: {key:"", formula: newCore.formula} });
altFormula: currentAltFormula.filter((_, i) => i !== arrayIndex) // // }
}); // } else { //normal delete that is not [0] index (1st entry)
} // const arrayIndex = visualIndex - 1;
// await this.daggerheartFlag.updateSource({
// altFormula: currentAltFormula.filter((_, i) => i !== arrayIndex)
// });
// }
await this.daggerheartFlag.updateSource({
altFormula: this.daggerheartFlag.altFormula.filter((_, index) => index !== visualIndex)
});
this.render({ internalRefresh: true }); this.render({ internalRefresh: true });
} }
} }

View file

@ -29,7 +29,7 @@
{{/each}} {{/each}}
{{else}} {{else}}
<div class="nest-inputs"> <div class="nest-inputs">
<input type="hidden" name="flags.daggerheart.formulaName" value="{{flagData.formulaName}}"> {{!-- <input type="hidden" name="flags.daggerheart.formulaName" value="{{flagData.formulaName}}"> --}}
{{formGroup fields.formula {{formGroup fields.formula
value=source.formula value=source.formula
placeholder=formulaPlaceholder placeholder=formulaPlaceholder