Filter types choices

This commit is contained in:
Dapoolp 2025-07-29 13:16:17 +02:00
parent 0512e4cad0
commit 18aed3a9f0
5 changed files with 44 additions and 21 deletions

View file

@ -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 => {

View file

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

View file

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

View file

@ -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)
}
}

View file

@ -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}}
</legend>
{{formField fields.type label="Type" name="roll.type" value=source.type localize=true choices=@root.getRollTypeOptions}}
{{#if (eq source.type "diceSet")}}
<div class="nest-inputs">
{{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}}
</div>
{{else}}
<div class="nest-inputs">
{{#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)}}
</div>
{{/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 @@
</div>
{{else}}
<div class="nest-inputs">
{{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}}
</div>
{{/if}}
{{/if}}
{{/if}} --}}
</fieldset>