From 4bdafeff6deaaefbcb7a18b61f9bd00166510d07 Mon Sep 17 00:00:00 2001 From: Dapoolp Date: Tue, 2 Sep 2025 11:54:31 +0200 Subject: [PATCH] j --- lang/en.json | 8 +++++- module/canvas/placeables/token.mjs | 2 +- module/config/effectConfig.mjs | 7 +++++ module/data/activeEffect/baseEffect.mjs | 5 ++-- module/documents/activeEffect.mjs | 25 +++++------------ styles/less/global/inventory-item.less | 6 +++++ styles/less/global/sheet.less | 25 +++++++++++++++++ templates/sheets/activeEffect/changes.hbs | 27 +++++++++++-------- templates/sheets/actors/character/sidebar.hbs | 18 ++++++++++++- .../global/partials/inventory-item-V2.hbs | 2 +- 10 files changed, 89 insertions(+), 36 deletions(-) diff --git a/lang/en.json b/lang/en.json index 5bccde46..40868a6e 100755 --- a/lang/en.json +++ b/lang/en.json @@ -34,7 +34,8 @@ } }, "EFFECT": { - "ChangeFilter": "Filter" + "ChangeFilter": "Filter", + "ChangeNegate": "Negate" }, "DAGGERHEART": { "ACTIONS": { @@ -1945,6 +1946,11 @@ "basics": "Basics", "bonus": "Bonus", "burden": "Burden", + "conditional": { + "label": "Condition", + "hint": "(Optionnal) Set a condition that need to be verified to apply effects below.", + "notMet": "Condition Not Met" + }, "continue": "Continue", "criticalSuccess": "Critical Success", "criticalShort": "Critical", diff --git a/module/canvas/placeables/token.mjs b/module/canvas/placeables/token.mjs index 09b3b192..b7933c5e 100644 --- a/module/canvas/placeables/token.mjs +++ b/module/canvas/placeables/token.mjs @@ -11,7 +11,7 @@ export default class DhTokenPlaceable extends foundry.canvas.placeables.Token { // Categorize effects const statusMap = new Map(foundry.CONFIG.statusEffects.map(status => [status.id, status])); - const activeEffects = (this.actor ? this.actor.effects.filter(x => !x.disabled) : []).reduce((acc, effect) => { + const activeEffects = (this.actor ? this.actor.effects.filter(x => !x.disabled && x.verifyCondition(this.actor)) : []).reduce((acc, effect) => { acc.push(effect); const currentStatusActiveEffects = acc.filter( diff --git a/module/config/effectConfig.mjs b/module/config/effectConfig.mjs index 97a03fad..15c12440 100644 --- a/module/config/effectConfig.mjs +++ b/module/config/effectConfig.mjs @@ -1,4 +1,5 @@ import { range } from '../config/generalConfig.mjs'; +import { capitalize } from '../helpers/utils.mjs'; export const valueTypes = { numberString: { @@ -62,3 +63,9 @@ export const effectTypes = { } } }; + +export const conditionalTypes = () => { + const operators = {}; + Object.entries(foundry.applications.ux.SearchFilter.OPERATORS).forEach(([key, value]) => operators[value] = key.replaceAll('_', ' ').toLowerCase().capitalize()); + return operators; +} \ No newline at end of file diff --git a/module/data/activeEffect/baseEffect.mjs b/module/data/activeEffect/baseEffect.mjs index a98fb5de..88a1e515 100644 --- a/module/data/activeEffect/baseEffect.mjs +++ b/module/data/activeEffect/baseEffect.mjs @@ -5,8 +5,9 @@ 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: foundry.applications.ux.SearchFilter.OPERATORS, initial: 'EQUALS'}), - value: new fields.StringField({required: 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({ diff --git a/module/documents/activeEffect.mjs b/module/documents/activeEffect.mjs index 4f8c0438..ab206d4d 100644 --- a/module/documents/activeEffect.mjs +++ b/module/documents/activeEffect.mjs @@ -2,18 +2,6 @@ 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 */ /* -------------------------------------------- */ @@ -101,9 +89,7 @@ export default class DhActiveEffect extends foundry.documents.ActiveEffect { /**@inheritdoc*/ apply(actor, change) { - if(!this.verifyConditional(actor)) return {}; - // const changes = super.apply(actor, change); - // console.log(actor, change, changes); + if(!this.verifyCondition(actor)) return {}; return super.apply(actor, change); } @@ -125,10 +111,8 @@ 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; + verifyCondition(actor) { + if(!this.system.conditional?.field) return true; return foundry.applications.ux.SearchFilter.evaluateFilter(actor, this.system.conditional); } @@ -143,6 +127,9 @@ export default class DhActiveEffect extends foundry.documents.ActiveEffect { this.isTemporary ? 'DAGGERHEART.EFFECTS.Duration.temporary' : 'DAGGERHEART.EFFECTS.Duration.passive' ) ]; + + if(this.target instanceof CONFIG.Actor.documentClass && !this.verifyCondition(this.target)) + tags.push(`${game.i18n.localize('DAGGERHEART.GENERAL.conditional.notMet')}`); for (const statusId of this.statuses) { const status = CONFIG.statusEffects.find(s => s.id === statusId); diff --git a/styles/less/global/inventory-item.less b/styles/less/global/inventory-item.less index e221f4e7..a272556b 100644 --- a/styles/less/global/inventory-item.less +++ b/styles/less/global/inventory-item.less @@ -132,6 +132,12 @@ background: light-dark(@dark-15, @beige-15); border: 1px solid light-dark(@dark, @beige); border-radius: 3px; + + &:has(i) { + color: @red; + border-color: @red; + background-color: @medium-red-10; + } } .label { diff --git a/styles/less/global/sheet.less b/styles/less/global/sheet.less index 08e2668f..5ec5efb1 100755 --- a/styles/less/global/sheet.less +++ b/styles/less/global/sheet.less @@ -58,6 +58,31 @@ body.game:is(.performance-low, .noblur) { .tab { padding: 0 10px; + + &.changes { + fieldset { + gap: 0; + padding-top: .5rem; + + header { + width: 100%; + scrollbar-gutter: stable; + overflow: hidden auto; + } + + header, ol { + grid-template-columns: 12fr 7fr 7fr 4fr 1fr; + } + + &.conditional { + header, ol { + grid-template-columns: 12fr 7fr 10fr 3fr; + scrollbar-gutter: unset; + overflow: unset; + } + } + } + } } } diff --git a/templates/sheets/activeEffect/changes.hbs b/templates/sheets/activeEffect/changes.hbs index 6a770f57..3ff28faf 100644 --- a/templates/sheets/activeEffect/changes.hbs +++ b/templates/sheets/activeEffect/changes.hbs @@ -1,27 +1,32 @@
- {{!--
- Conditional +
+ {{localize "DAGGERHEART.GENERAL.conditional.label"}} +

{{localize "DAGGERHEART.GENERAL.conditional.hint"}}

-
{{localize "EFFECT.ChangeKey"}}
-
{{localize "EFFECT.ChangeFilter"}}
+
{{localize "EFFECT.ChangeKey"}}
+
{{localize "EFFECT.ChangeFilter"}}
{{localize "EFFECT.ChangeValue"}}
+
{{localize "EFFECT.ChangeNegate"}}
-
    {{log @root}}{{log this}} +
    1. -
      - {{formInput document.system.schema.fields.conditional.fields.key value=source.system.conditional.key localize=true }} +
      + {{formInput document.system.schema.fields.conditional.fields.field value=source.system.conditional.field localize=true }}
      -
      - {{formInput document.system.schema.fields.conditional.fields.filter value=source.system.conditional.filter localize=true }} +
      + {{formInput document.system.schema.fields.conditional.fields.operator value=source.system.conditional.operator localize=true }}
      {{formInput document.system.schema.fields.conditional.fields.value value=source.system.conditional.value localize=true }}
      +
      + {{formInput document.system.schema.fields.conditional.fields.negate value=source.system.conditional.negate localize=true }} +
- Effects --}} + {{localize "DAGGERHEART.GENERAL.Effect.plural"}}
{{localize "EFFECT.ChangeKey"}}
{{localize "EFFECT.ChangeMode"}}
@@ -51,5 +56,5 @@ {{/with}} {{/each}} - {{!--
--}} +
\ No newline at end of file diff --git a/templates/sheets/actors/character/sidebar.hbs b/templates/sheets/actors/character/sidebar.hbs index 6131104d..e2a4da80 100644 --- a/templates/sheets/actors/character/sidebar.hbs +++ b/templates/sheets/actors/character/sidebar.hbs @@ -62,7 +62,7 @@ - {{#if document.system.armor.system.marks}} + {{!-- {{#if document.system.armor.system.marks}}

@@ -77,6 +77,22 @@

{{localize "DAGGERHEART.GENERAL.armorSlots"}}

+
--}} + {{#if document.system.resources.armor.max}} +
+
+

+

/

+

{{document.system.resources.armor.max}}

+
+ +
+

{{localize "DAGGERHEART.GENERAL.armorSlots"}}

+
{{else}}
diff --git a/templates/sheets/global/partials/inventory-item-V2.hbs b/templates/sheets/global/partials/inventory-item-V2.hbs index a4ecec3a..32b3a782 100644 --- a/templates/sheets/global/partials/inventory-item-V2.hbs +++ b/templates/sheets/global/partials/inventory-item-V2.hbs @@ -38,7 +38,7 @@ Parameters:
{{#each this._getTags as |tag|}}
- {{tag}} + {{{tag}}}
{{/each}}