Add some jsdoc

This commit is contained in:
Dapoolp 2025-08-21 23:12:01 +02:00
parent a54efaeb48
commit 5c73b45193
23 changed files with 501 additions and 555 deletions

View file

@ -1,8 +1,12 @@
const fields = foundry.data.fields;
export default class EffectsField extends fields.ArrayField {
/**
* Action Workflow order
*/
order = 100;
/** @inheritDoc */
constructor(options = {}, context = {}) {
const element = new fields.SchemaField({
_id: new fields.DocumentIdField(),
@ -11,27 +15,39 @@ export default class EffectsField extends fields.ArrayField {
super(element, options, context);
}
async execute(config) {
if(!this.hasEffect) return;
if(!config.message) {
/**
* Apply Effects Action Workflow part.
* Must be called within Action context.
* @param {object} config Object that contains workflow datas. Usually made from Action Fields prepareConfig methods.
* @param {object[]} [targets=null] Array of targets to override pre-selected ones.
* @param {boolean} [force=false] If the method should be executed outside of Action workflow, for ChatMessage button for example.
*/
async execute(config, targets = null, force = false) {
if(!config.hasEffect) return;
let message = config.message ?? ui.chat.collection.get(config.parent?._id);
if(!message) {
const roll = new CONFIG.Dice.daggerheart.DHRoll('');
roll._evaluated = true;
config.message = await CONFIG.Dice.daggerheart.DHRoll.toMessage(roll, config);
message = config.message = await CONFIG.Dice.daggerheart.DHRoll.toMessage(roll, config);
}
if(EffectsField.getAutomation()) {
EffectsField.applyEffects.call(this, config.targets);
if(EffectsField.getAutomation() || force) {
targets ??= config.targets.filter(t => !config.hasRoll || t.hit);
EffectsField.applyEffects.call(this, config.targets.filter(t => !config.hasRoll || t.hit));
}
}
/**
*
* Must be called within Action context.
* @param {*} targets
* @returns
*/
static async applyEffects(targets) {
const force = true; /* Where should this come from? */
if (!this.effects?.length || !targets?.length) return;
let effects = this.effects;
targets.forEach(async token => {
if (!token.hit && !force) return;
if (this.hasSave && token.saved.success === true) {
if (this.hasSave && token.saved.success === true)
effects = this.effects.filter(e => e.onSave === true);
}
if (!effects.length) return;
effects.forEach(async e => {
const actor = canvas.tokens.get(token.id)?.actor,
@ -42,6 +58,12 @@ export default class EffectsField extends fields.ArrayField {
});
}
/**
*
* @param {*} effect
* @param {*} actor
* @returns
*/
static async applyEffect(effect, actor) {
const existingEffect = actor.effects.find(e => e.origin === effect.uuid);
if (existingEffect) {
@ -63,6 +85,10 @@ export default class EffectsField extends fields.ArrayField {
await ActiveEffect.implementation.create(effectData, { parent: actor });
}
/**
* Return the automation setting for execute method for current user role
* @returns {boolean} If execute should be triggered automatically
*/
static getAutomation() {
return (game.user.isGM && game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation).roll.effect.gm) || (!game.user.isGM && game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation).roll.effect.players)
}