mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 03:31:07 +01:00
Add multiple conditions handler + update Bare Bones domain card
This commit is contained in:
parent
af3a415e56
commit
4a63836c0d
8 changed files with 213 additions and 38 deletions
|
|
@ -20,7 +20,12 @@ export default class DhActiveEffectConfig extends foundry.applications.sheets.Ac
|
|||
}
|
||||
|
||||
static DEFAULT_OPTIONS = {
|
||||
classes: ['daggerheart', 'sheet', 'dh-style']
|
||||
classes: ['daggerheart', 'sheet', 'dh-style'],
|
||||
actions: {
|
||||
addCondition: DhActiveEffectConfig.#onAddCondition,
|
||||
deleteCondition: DhActiveEffectConfig.#onDeleteCondition,
|
||||
setAndOr: DhActiveEffectConfig.#setAndOr
|
||||
}
|
||||
};
|
||||
|
||||
static PARTS = {
|
||||
|
|
@ -115,4 +120,46 @@ export default class DhActiveEffectConfig extends foundry.applications.sheets.Ac
|
|||
|
||||
return partContext;
|
||||
}
|
||||
|
||||
/* ----------------------------------------- */
|
||||
|
||||
/**
|
||||
* Add a new condition to the effect's conditions array.
|
||||
* @this {DhActiveEffectConfig}
|
||||
* @type {ApplicationClickAction}
|
||||
*/
|
||||
static async #onAddCondition() {
|
||||
const submitData = this._processFormData(null, this.form, new foundry.applications.ux.FormDataExtended(this.form));
|
||||
const conditions = Object.values(submitData.system.conditional?.condition ?? {});
|
||||
conditions.push({});
|
||||
return this.submit({updateData: {'system.conditional.condition': conditions}});
|
||||
}
|
||||
|
||||
/* ----------------------------------------- */
|
||||
|
||||
/**
|
||||
* Add a new condition to the effect's conditions array.
|
||||
* @this {DhActiveEffectConfig}
|
||||
* @type {ApplicationClickAction}
|
||||
*/
|
||||
static async #onDeleteCondition(event) {
|
||||
const submitData = this._processFormData(null, this.form, new FormDataExtended(this.form));
|
||||
const conditions = Object.values(submitData.system.conditional.condition ?? {});
|
||||
const row = event.target.closest("li");
|
||||
const index = Number(row.dataset.index) || 0;
|
||||
conditions.splice(index, 1);
|
||||
return this.submit({updateData: {'system.conditional.condition': conditions}});
|
||||
}
|
||||
|
||||
/* ----------------------------------------- */
|
||||
|
||||
/**
|
||||
* Add a new condition to the effect's conditions array.
|
||||
* @this {DhActiveEffectConfig}
|
||||
* @type {ApplicationClickAction}
|
||||
*/
|
||||
static async #setAndOr(event) {
|
||||
const value = event.target.dataset.value;
|
||||
return this.submit({updateData: {'system.conditional.andOr': value === 'true'}});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,15 @@ export default class BaseEffect extends foundry.abstract.TypeDataModel {
|
|||
|
||||
return {
|
||||
conditional: new fields.SchemaField({
|
||||
field: new fields.StringField({required: true, nullable: true}),
|
||||
operator: new fields.StringField({required: true, choices: CONFIG.DH.EFFECTS.conditionalTypes(), initial: 'equals'}),
|
||||
value: new fields.StringField({required: true}),
|
||||
negate: new fields.BooleanField({initial: false})
|
||||
andOr: new fields.BooleanField({ initial: true }),
|
||||
condition: new fields.ArrayField(
|
||||
new fields.SchemaField({
|
||||
field: new fields.StringField({required: true, nullable: true}),
|
||||
operator: new fields.StringField({required: true, choices: CONFIG.DH.EFFECTS.conditionalTypes(), initial: 'equals'}),
|
||||
value: new fields.StringField({required: true}),
|
||||
negate: new fields.BooleanField({initial: false})
|
||||
})
|
||||
)
|
||||
}),
|
||||
rangeDependence: new fields.SchemaField({
|
||||
enabled: new fields.BooleanField({
|
||||
|
|
|
|||
|
|
@ -112,8 +112,12 @@ export default class DhActiveEffect extends foundry.documents.ActiveEffect {
|
|||
}
|
||||
|
||||
verifyCondition(actor) {
|
||||
if(!this.system.conditional?.field) return true;
|
||||
return foundry.applications.ux.SearchFilter.evaluateFilter(actor, this.system.conditional);
|
||||
if(!this.system.conditional?.condition.length) return true;
|
||||
return this.system.conditional.condition.filter(c => c.field).map(c => {
|
||||
if(!isNaN(c.value))
|
||||
c.value = Number(c.value);
|
||||
return c;
|
||||
})[this.system.conditional.andOr ? 'every' : 'some'](c => foundry.applications.ux.SearchFilter.evaluateFilter(actor, c));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue