This commit is contained in:
Dapoolp 2025-09-02 00:02:10 +02:00
parent c6741b1c7a
commit 7cbe4b7580
4 changed files with 83 additions and 24 deletions

View file

@ -33,7 +33,9 @@
}
}
},
"EFFECT": {
"ChangeFilter": "Filter"
},
"DAGGERHEART": {
"ACTIONS": {
"TYPES": {

View file

@ -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,

View file

@ -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 */
/* -------------------------------------------- */
@ -86,6 +99,14 @@ export default class DhActiveEffect extends foundry.documents.ActiveEffect {
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
* @param {string} expression
@ -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.

View file

@ -1,4 +1,27 @@
<section class="tab changes{{#if tab.active}} active{{/if}}" data-group="{{tab.group}}" data-tab="{{tab.id}}">
{{!-- <fieldset>
<legend>Conditional</legend>
<header>
<div class="key">{{localize "EFFECT.ChangeKey"}}</div>
<div class="filter">{{localize "EFFECT.ChangeFilter"}}</div>
<div class="value">{{localize "EFFECT.ChangeValue"}}</div>
</header>
<ol>{{log @root}}{{log this}}
<li>
<div class="key">
{{formInput document.system.schema.fields.conditional.fields.key value=source.system.conditional.key localize=true }}
</div>
<div class="filter">
{{formInput document.system.schema.fields.conditional.fields.filter value=source.system.conditional.filter localize=true }}
</div>
<div class="value">
{{formInput document.system.schema.fields.conditional.fields.value value=source.system.conditional.value localize=true }}
</div>
</li>
</ol>
</fieldset>
<fieldset>
<legend>Effects</legend> --}}
<header>
<div class="key">{{localize "EFFECT.ChangeKey"}}</div>
<div class="mode">{{localize "EFFECT.ChangeMode"}}</div>
@ -28,4 +51,5 @@
{{/with}}
{{/each}}
</ol>
{{!-- </fieldset> --}}
</section>