mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-03-07 14:36:13 +01:00
overcomplicated it
This commit is contained in:
parent
209963405f
commit
1c3e2f019c
2 changed files with 30 additions and 23 deletions
|
|
@ -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({
|
||||||
|
// 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({
|
await this.daggerheartFlag.updateSource({
|
||||||
formulaName:newCore.key,
|
altFormula: this.daggerheartFlag.altFormula.filter((_, index) => index !== visualIndex)
|
||||||
altFormula:newAlt
|
|
||||||
});
|
});
|
||||||
} 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 });
|
this.render({ internalRefresh: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue