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

View file

@ -29,7 +29,7 @@
{{/each}}
{{else}}
<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
value=source.formula
placeholder=formulaPlaceholder