diff --git a/lang/en.json b/lang/en.json index 82ffac7a..5bccde46 100755 --- a/lang/en.json +++ b/lang/en.json @@ -33,7 +33,9 @@ } } }, - + "EFFECT": { + "ChangeFilter": "Filter" + }, "DAGGERHEART": { "ACTIONS": { "TYPES": { diff --git a/module/data/activeEffect/baseEffect.mjs b/module/data/activeEffect/baseEffect.mjs index 0ac87de0..a98fb5de 100644 --- a/module/data/activeEffect/baseEffect.mjs +++ b/module/data/activeEffect/baseEffect.mjs @@ -3,6 +3,11 @@ export default class BaseEffect extends foundry.abstract.TypeDataModel { const fields = foundry.data.fields; return { + conditional: new fields.SchemaField({ + field: new fields.StringField({required: true, nullable: true}), + operator: new fields.StringField({required: true, choices: foundry.applications.ux.SearchFilter.OPERATORS, initial: 'EQUALS'}), + value: new fields.StringField({required: true}) + }), rangeDependence: new fields.SchemaField({ enabled: new fields.BooleanField({ required: true, diff --git a/module/documents/activeEffect.mjs b/module/documents/activeEffect.mjs index b2896513..4f8c0438 100644 --- a/module/documents/activeEffect.mjs +++ b/module/documents/activeEffect.mjs @@ -1,6 +1,19 @@ import { itemAbleRollParse } from '../helpers/utils.mjs'; export default class DhActiveEffect extends foundry.documents.ActiveEffect { + + /* -------------------------------------------- */ + + /** @inheritdoc */ + // static defineSchema() { + // const fields = foundry.data.fields; + + // return { + // ...super.defineSchema(), + // test: new fields.StringField() + // } + // } + /* -------------------------------------------- */ /* Properties */ /* -------------------------------------------- */ @@ -85,6 +98,14 @@ export default class DhActiveEffect extends foundry.documents.ActiveEffect { change.value = evalValue ?? change.value; super.applyField(model, change, field); } + + /**@inheritdoc*/ + apply(actor, change) { + if(!this.verifyConditional(actor)) return {}; + // const changes = super.apply(actor, change); + // console.log(actor, change, changes); + return super.apply(actor, change); + } /** * Altered Foundry safeEval to allow non-numeric return @@ -104,6 +125,13 @@ export default class DhActiveEffect extends foundry.documents.ActiveEffect { return result; } + verifyConditional(actor) { + if(!this.system.conditional.key) return true; + // const prop = foundry.utils.getProperty(actor, this.system.conditional.key); + // if(prop === undefined) return false; + return foundry.applications.ux.SearchFilter.evaluateFilter(actor, this.system.conditional); + } + /** * Generates a list of localized tags based on this item's type-specific properties. * @returns {string[]} An array of localized tag strings. diff --git a/templates/sheets/activeEffect/changes.hbs b/templates/sheets/activeEffect/changes.hbs index 9cf137f0..6a770f57 100644 --- a/templates/sheets/activeEffect/changes.hbs +++ b/templates/sheets/activeEffect/changes.hbs @@ -1,31 +1,55 @@
-
-
{{localize "EFFECT.ChangeKey"}}
-
{{localize "EFFECT.ChangeMode"}}
-
{{localize "EFFECT.ChangeValue"}}
-
{{localize "EFFECT.ChangePriority"}}
-
-
-
    - {{#each source.changes as |change i|}} - {{#with ../fields.changes.element.fields as |changeFields|}} -
  1. + {{!--
    + Conditional +
    +
    {{localize "EFFECT.ChangeKey"}}
    +
    {{localize "EFFECT.ChangeFilter"}}
    +
    {{localize "EFFECT.ChangeValue"}}
    +
    +
      {{log @root}}{{log this}} +
    1. - + {{formInput document.system.schema.fields.conditional.fields.key value=source.system.conditional.key localize=true }}
      -
      - {{formInput changeFields.mode name=(concat "changes." i ".mode") value=change.mode choices=@root.modes}} +
      + {{formInput document.system.schema.fields.conditional.fields.filter value=source.system.conditional.filter localize=true }}
      - {{formInput changeFields.value name=(concat "changes." i ".value") value=change.value}} + {{formInput document.system.schema.fields.conditional.fields.value value=source.system.conditional.value localize=true }}
      -
      - {{formInput changeFields.priority name=(concat "changes." i ".priority") value=change.priority - placeholder=(lookup ../../priorities change.mode)}} -
      -
    2. - {{/with}} - {{/each}} -
    +
+ +
+ Effects --}} +
+
{{localize "EFFECT.ChangeKey"}}
+
{{localize "EFFECT.ChangeMode"}}
+
{{localize "EFFECT.ChangeValue"}}
+
{{localize "EFFECT.ChangePriority"}}
+
+
+
    + {{#each source.changes as |change i|}} + {{#with ../fields.changes.element.fields as |changeFields|}} +
  1. +
    + +
    +
    + {{formInput changeFields.mode name=(concat "changes." i ".mode") value=change.mode choices=@root.modes}} +
    +
    + {{formInput changeFields.value name=(concat "changes." i ".value") value=change.value}} +
    +
    + {{formInput changeFields.priority name=(concat "changes." i ".priority") value=change.priority + placeholder=(lookup ../../priorities change.mode)}} +
    +
    +
  2. + {{/with}} + {{/each}} +
+ {{!--
--}}
\ No newline at end of file