From 18aed3a9f0c283adb1fba34099d77787e7f64593 Mon Sep 17 00:00:00 2001 From: Dapoolp Date: Tue, 29 Jul 2025 13:16:17 +0200 Subject: [PATCH] Filter types choices --- .../sheets-configs/action-config.mjs | 11 +++++++ module/config/generalConfig.mjs | 6 ++-- module/data/action/baseAction.mjs | 6 +--- module/data/fields/action/rollField.mjs | 12 +------- templates/actionTypes/roll.hbs | 30 +++++++++++++++++-- 5 files changed, 44 insertions(+), 21 deletions(-) diff --git a/module/applications/sheets-configs/action-config.mjs b/module/applications/sheets-configs/action-config.mjs index 7d50c0c6..a569e66f 100644 --- a/module/applications/sheets-configs/action-config.mjs +++ b/module/applications/sheets-configs/action-config.mjs @@ -108,9 +108,11 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) { context.hasBaseDamage = !!this.action.parent.attack; context.getEffectDetails = this.getEffectDetails.bind(this); context.costOptions = this.getCostOptions(); + context.getRollTypeOptions = this.getRollTypeOptions(); context.disableOption = this.disableOption.bind(this); context.isNPC = this.action.actor?.isNPC; context.baseSaveDifficulty = this.action.actor?.baseSaveDifficulty; + context.baseAttackBonus = this.action.actor?.system.attack?.damage.parts[0].value.bonus; context.hasRoll = this.action.hasRoll; const settingsTiers = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.LevelTiers).tiers; @@ -139,6 +141,15 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) { return options; } + getRollTypeOptions() { + const types = foundry.utils.deepClone(CONFIG.DH.GENERAL.rollTypes); + if(!this.action.actor) return types; + Object.values(types).forEach(t => { + if(this.action.actor.type !== 'character' && t.playerOnly) delete types[t.id]; + }) + return types; + } + disableOption(index, costOptions, choices) { const filtered = foundry.utils.deepClone(costOptions); Object.keys(filtered).forEach(o => { diff --git a/module/config/generalConfig.mjs b/module/config/generalConfig.mjs index 7e44cad7..78e99eae 100644 --- a/module/config/generalConfig.mjs +++ b/module/config/generalConfig.mjs @@ -473,11 +473,13 @@ export const rollTypes = { }, spellcast: { id: 'spellcast', - label: 'DAGGERHEART.CONFIG.RollTypes.spellcast.name' + label: 'DAGGERHEART.CONFIG.RollTypes.spellcast.name', + playerOnly: true }, trait: { id: 'trait', - label: 'DAGGERHEART.CONFIG.RollTypes.trait.name' + label: 'DAGGERHEART.CONFIG.RollTypes.trait.name', + playerOnly: true }, diceSet: { id: 'diceSet', diff --git a/module/data/action/baseAction.mjs b/module/data/action/baseAction.mjs index 1e955e5c..8f0e0682 100644 --- a/module/data/action/baseAction.mjs +++ b/module/data/action/baseAction.mjs @@ -37,11 +37,7 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel this.extraSchemas.forEach(s => { let clsField; - if ((clsField = this.getActionField(s))) schemaFields[s] = new clsField( - { - type: this - } - ); + if ((clsField = this.getActionField(s))) schemaFields[s] = new clsField(); }); return schemaFields; diff --git a/module/data/fields/action/rollField.mjs b/module/data/fields/action/rollField.mjs index d6e41937..511e0660 100644 --- a/module/data/fields/action/rollField.mjs +++ b/module/data/fields/action/rollField.mjs @@ -4,7 +4,7 @@ export class DHActionRollData extends foundry.abstract.DataModel { /** @override */ static defineSchema() { return { - type: new fields.StringField({ nullable: true, initial: null, choices: this.getRollTypes() }), + type: new fields.StringField({ nullable: true, initial: null, choices: CONFIG.DH.GENERAL.rollTypes }), trait: new fields.StringField({ nullable: true, initial: null, choices: CONFIG.DH.ACTOR.abilities }), difficulty: new fields.NumberField({ nullable: true, initial: null, integer: true, min: 0 }), bonus: new fields.NumberField({ nullable: true, initial: null, integer: true }), @@ -45,15 +45,6 @@ export class DHActionRollData extends foundry.abstract.DataModel { }; } - static getRollTypes() { - console.log(this.parent, this._source) - return CONFIG.DH.GENERAL.rollTypes; - } - - _configure() { - console.log(this) - } - getFormula() { if (!this.type) return; let formula = ''; @@ -80,6 +71,5 @@ export class DHActionRollData extends foundry.abstract.DataModel { export default class RollField extends fields.EmbeddedDataField { constructor(options, context = {}) { super(DHActionRollData, options, context); - console.log(this) } } diff --git a/templates/actionTypes/roll.hbs b/templates/actionTypes/roll.hbs index 2d2dab3c..2d78033a 100644 --- a/templates/actionTypes/roll.hbs +++ b/templates/actionTypes/roll.hbs @@ -3,7 +3,31 @@ Roll {{#if @root.hasBaseDamage}}{{formInput fields.useDefault name="roll.useDefault" value=source.useDefault dataset=(object tooltip="Use default Item values" tooltipDirection="UP")}}{{/if}} - {{#if @root.isNPC}} + + {{formField fields.type label="Type" name="roll.type" value=source.type localize=true choices=@root.getRollTypeOptions}} + {{#if (eq source.type "diceSet")}} +
+ {{formField fields.diceRolling.fields.multiplier name="roll.diceRolling.multiplier" value=source.diceRolling.multiplier localize=true}} + {{#if (eq source.diceRolling.multiplier 'flat')}}{{formField fields.diceRolling.fields.flatMultiplier value=source.diceRolling.flatMultiplier name="roll.diceRolling.flatMultiplier" localize=true }}{{/if}} + {{formField fields.diceRolling.fields.dice name="roll.diceRolling.dice" value=source.diceRolling.dice localize=true}} + {{formField fields.diceRolling.fields.compare name="roll.diceRolling.compare" value=source.diceRolling.compare localize=true blank=""}} + {{formField fields.diceRolling.fields.treshold name="roll.diceRolling.treshold" value=source.diceRolling.treshold localize=true}} +
+ {{else}} +
+ {{#unless (eq source.type 'spellcast')}} + {{#if @root.isNPC}} + {{formField fields.bonus label="Bonus" name="roll.bonus" value=source.bonus placeholder=@root.baseAttackBonus disabled=(not source.type)}} + {{else}} + {{formField fields.trait label="Trait" name="roll.trait" value=source.trait localize=true disabled=(not source.type)}} + {{/if}} + {{/unless}} + {{formField fields.difficulty label="Difficulty" name="roll.difficulty" value=source.difficulty disabled=(not source.type)}} + {{formField fields.advState label= "Advantage State" name="roll.advState" value=source.advState localize=true disabled=(not source.type)}} +
+ {{/if}} + + {{!-- {{#if @root.isNPC}} {{formField fields.bonus label="Bonus" name="roll.bonus" value=source.bonus}} {{formField fields.advState label= "Advantage State" name="roll.advState" value=source.advState localize=true}} {{else}} @@ -18,10 +42,10 @@ {{else}}
- {{formField fields.trait label="Trait" name="roll.trait" value=source.trait localize=true disabled=(not source.type)}} + {{#unless (eq source.type 'spellcast')}}{{formField fields.trait label="Trait" name="roll.trait" value=source.trait localize=true disabled=(not source.type)}}{{/unless}} {{formField fields.difficulty label="Difficulty" name="roll.difficulty" value=source.difficulty disabled=(not source.type)}} {{formField fields.advState label= "Advantage State" name="roll.advState" value=source.advState localize=true}}
{{/if}} - {{/if}} + {{/if}} --}} \ No newline at end of file