mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-03-07 14:36:13 +01:00
implementation initial
This commit is contained in:
parent
89f350a013
commit
4ef213d8ef
2 changed files with 91 additions and 4 deletions
|
|
@ -1,6 +1,7 @@
|
|||
export default class DhRollTableSheet extends foundry.applications.sheets.RollTableSheet {
|
||||
static DEFAULT_OPTIONS = {
|
||||
...super.DEFAULT_OPTIONS,
|
||||
classes:['daggerheart', 'sheet', 'dh-style'],
|
||||
actions: {
|
||||
addAltFormula: DhRollTableSheet.#onAddAltFormula,
|
||||
removeAltFormula: DhRollTableSheet.#onRemoveAltFormula
|
||||
|
|
@ -24,7 +25,27 @@ export default class DhRollTableSheet extends foundry.applications.sheets.RollTa
|
|||
|
||||
switch (partId) {
|
||||
case 'summary':
|
||||
context.flagFields = this.daggerheartFlag.schema.fields;
|
||||
context.flagData = this.daggerheartFlag;
|
||||
const formulas =[];
|
||||
formulas.push({
|
||||
index: 0,
|
||||
key: this.daggerheartFlag.formulaName, //Stored in flags as discussed
|
||||
formula: context.source.formula, //Settinng default formula as part of first element
|
||||
formulaInputName: "formula",
|
||||
keyInputName: "flags.daggerheart.formulaName"
|
||||
});
|
||||
this.daggerheartFlag.altFormula.forEach((alt,i) =>{
|
||||
formulas.push({
|
||||
index: i+1,
|
||||
key: alt.key,
|
||||
formula: alt.formula,
|
||||
formulaInputName:`flags.daggerheart.altFormula.${i}.formula`,
|
||||
keyInputName: `flags.daggerheart.altFormula.${i}.key`
|
||||
});
|
||||
});
|
||||
context.formulaList=formulas;
|
||||
context.isListView=formulas.length>1; //Condition to show list view only if more than one entry
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -40,12 +61,41 @@ export default class DhRollTableSheet extends foundry.applications.sheets.RollTa
|
|||
|
||||
/** @override */
|
||||
async _processSubmitData(event, form, submitData, options) {
|
||||
submitData.flags.daggerheart = this.daggerheartFlag.toObject();
|
||||
//submitData.flags.daggerheart = this.daggerheartFlag.toObject();
|
||||
|
||||
super._processSubmitData(event, form, submitData, options);
|
||||
}
|
||||
|
||||
static async #onAddAltFormula(_event, target) {}
|
||||
static async #onAddAltFormula(_event, target) {
|
||||
const currentAltFormula=this.daggerheartFlag.altFormula;
|
||||
await this.daggerheartFlag.updateSource({
|
||||
altFormula:[...currentAltFormula,{key:"",formula:""}]
|
||||
});
|
||||
this.render({ internalRefresh: true });
|
||||
}
|
||||
|
||||
static async #onRemoveAltFormula(_event, target) {}
|
||||
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});
|
||||
await this.daggerheartFlag.updateSource({
|
||||
formulaName:newCore.key,
|
||||
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 });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue