Run lint fix on action areas PR (#1820)

This commit is contained in:
Carlos Fernandez 2026-04-21 00:13:18 -04:00 committed by GitHub
parent f348b64aae
commit c57266e596
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 72 additions and 66 deletions

View file

@ -28,10 +28,8 @@ export default class DHActionConfig extends DHActionBaseConfig {
game.system.api.data.activeEffects.BaseEffect.getDefaultObject({ transfer: false }) game.system.api.data.activeEffects.BaseEffect.getDefaultObject({ transfer: false })
]); ]);
if (areaIndex !== undefined) if (areaIndex !== undefined) data.area[areaIndex].effects.push(created[0]._id);
data.area[areaIndex].effects.push(created[0]._id); else data.effects.push({ _id: created[0]._id });
else
data.effects.push({ _id: created[0]._id });
this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) }); this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) });
this.action.item.effects.get(created[0]._id).sheet.render(true); this.action.item.effects.get(created[0]._id).sheet.render(true);
} }
@ -57,14 +55,14 @@ export default class DHActionConfig extends DHActionBaseConfig {
static removeEffect(event, button) { static removeEffect(event, button) {
if (!this.action.effects) return; if (!this.action.effects) return;
const { areaIndex, index } = button.dataset; const { areaIndex, index } = button.dataset;
let effectId = null; let effectId = null;
if (areaIndex !== undefined) { if (areaIndex !== undefined) {
effectId = this.action.area[areaIndex].effects[index]; effectId = this.action.area[areaIndex].effects[index];
const data = this.action.toObject(); const data = this.action.toObject();
data.area[areaIndex].effects.splice(index, 1); data.area[areaIndex].effects.splice(index, 1);
this.constructor.updateForm.call(this, null, null, { object: foundry.utils.flattenObject(data) }); this.constructor.updateForm.call(this, null, null, { object: foundry.utils.flattenObject(data) });
} else { } else {
effectId = this.action.effects[index]._id; effectId = this.action.effects[index]._id;
this.constructor.removeElement.call(this, event, button); this.constructor.removeElement.call(this, event, button);
} }

View file

@ -40,10 +40,8 @@ export default class DHActionSettingsConfig extends DHActionBaseConfig {
this.sheetUpdate(data, effectData); this.sheetUpdate(data, effectData);
this.effects = [...this.effects, effectData]; this.effects = [...this.effects, effectData];
if(areaIndex !== undefined) if (areaIndex !== undefined) data.area[areaIndex].effects.push(effectData.id);
data.area[areaIndex].effects.push(effectData.id); else data.effects.push({ _id: effectData.id });
else
data.effects.push({ _id: effectData.id });
this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) }); this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) });
} }
@ -62,7 +60,6 @@ export default class DHActionSettingsConfig extends DHActionBaseConfig {
this.constructor.removeElement.call(this, event, button); this.constructor.removeElement.call(this, event, button);
} }
this.sheetUpdate( this.sheetUpdate(
this.action.toObject(), this.action.toObject(),
this.effects.find(x => x.id === effectId), this.effects.find(x => x.id === effectId),

View file

@ -100,7 +100,11 @@ export default class DhRegionLayer extends foundry.canvas.layers.RegionLayer {
const { line, rectangle, inFront, cone } = CONFIG.DH.GENERAL.templateTypes; const { line, rectangle, inFront, cone } = CONFIG.DH.GENERAL.templateTypes;
const usedAngle = const usedAngle =
type === cone.id ? (angle ?? CONFIG.MeasuredTemplate.defaults.angle) : type === inFront.id ? '180' : undefined; type === cone.id
? (angle ?? CONFIG.MeasuredTemplate.defaults.angle)
: type === inFront.id
? '180'
: undefined;
const { grid, distance } = CONFIG.Scene.documentClass.schema.fields.grid.fields; const { grid, distance } = CONFIG.Scene.documentClass.schema.fields.grid.fields;
const sceneGridSize = canvas.scene?.grid.size ?? grid.size.initial; const sceneGridSize = canvas.scene?.grid.size ?? grid.size.initial;
@ -109,7 +113,8 @@ export default class DhRegionLayer extends foundry.canvas.layers.RegionLayer {
const rangeNumber = Number(range); const rangeNumber = Number(range);
const settings = canvas.scene?.rangeSettings; const settings = canvas.scene?.rangeSettings;
const baseDistance = (!Number.isNaN(rangeNumber) ? rangeNumber : (settings ? settings[range] : 0)) * dimensionConstant; const baseDistance =
(!Number.isNaN(rangeNumber) ? rangeNumber : settings ? settings[range] : 0) * dimensionConstant;
const length = baseDistance; const length = baseDistance;
const radius = length; const radius = length;

View file

@ -121,4 +121,4 @@ export const areaTypes = {
id: 'placed', id: 'placed',
label: 'Placed Area' label: 'Placed Area'
} }
}; };

View file

@ -1124,4 +1124,4 @@ export const simpleDispositions = {
id: 1, id: 1,
label: 'TOKEN.DISPOSITION.FRIENDLY' label: 'TOKEN.DISPOSITION.FRIENDLY'
} }
}; };

View file

@ -94,9 +94,12 @@ export default class BaseEffect extends foundry.data.ActiveEffectTypeDataModel {
}, },
{ nullable: true, initial: null } { nullable: true, initial: null }
), ),
targetDispositions: new fields.SetField(new fields.NumberField({ targetDispositions: new fields.SetField(
choices: CONFIG.DH.GENERAL.simpleDispositions, new fields.NumberField({
}), { label: 'Affected Dispositions' }), choices: CONFIG.DH.GENERAL.simpleDispositions
}),
{ label: 'Affected Dispositions' }
)
}; };
} }

View file

@ -11,7 +11,7 @@ export default class DHAbilityUse extends foundry.abstract.TypeDataModel {
actor: new fields.StringField(), actor: new fields.StringField(),
item: new fields.StringField(), item: new fields.StringField(),
action: new fields.StringField() action: new fields.StringField()
}), })
}; };
} }

View file

@ -33,8 +33,8 @@ export default class AreaField extends fields.ArrayField {
initial: CONFIG.DH.GENERAL.range.veryClose.id, initial: CONFIG.DH.GENERAL.range.veryClose.id,
label: 'DAGGERHEART.ACTIONS.Config.area.size' label: 'DAGGERHEART.ACTIONS.Config.area.size'
}), }),
effects: new fields.ArrayField(new fields.DocumentIdField()), effects: new fields.ArrayField(new fields.DocumentIdField())
}); });
super(element, options, context); super(element, options, context);
} }
} }

View file

@ -287,7 +287,7 @@ export function ActionMixin(Base) {
source: { source: {
actor: this.actor.uuid, actor: this.actor.uuid,
item: this.item.id, item: this.item.id,
action: this.id, action: this.id
}, },
itemOrigin: this.item, itemOrigin: this.item,
description: this.description || (this.item instanceof Item ? this.item.system.description : '') description: this.description || (this.item instanceof Item ? this.item.system.description : '')

View file

@ -1 +1 @@
export { default as applyActiveEffect } from './applyActiveEffect.mjs'; export { default as applyActiveEffect } from './applyActiveEffect.mjs';

View file

@ -1,38 +1,40 @@
export default class DhApplyActiveEffect extends CONFIG.RegionBehavior.dataModels.applyActiveEffect { export default class DhApplyActiveEffect extends CONFIG.RegionBehavior.dataModels.applyActiveEffect {
static async #getApplicableEffects(token) { static async #getApplicableEffects(token) {
const effects = await Promise.all(this.effects.map(foundry.utils.fromUuid)); const effects = await Promise.all(this.effects.map(foundry.utils.fromUuid));
return effects.filter(effect => !effect.system.targetDispositions.size || effect.system.targetDispositions.has(token.disposition)); return effects.filter(
effect => !effect.system.targetDispositions.size || effect.system.targetDispositions.has(token.disposition)
);
} }
static async #onTokenEnter(event) { static async #onTokenEnter(event) {
if ( !event.user.isSelf ) return; if (!event.user.isSelf) return;
const {token, movement} = event.data; const { token, movement } = event.data;
const actor = token.actor; const actor = token.actor;
if ( !actor ) return; if (!actor) return;
const resumeMovement = movement ? token.pauseMovement() : undefined; const resumeMovement = movement ? token.pauseMovement() : undefined;
const effects = await DhApplyActiveEffect.#getApplicableEffects.bind(this)(event.data.token); const effects = await DhApplyActiveEffect.#getApplicableEffects.bind(this)(event.data.token);
const toCreate = []; const toCreate = [];
for ( const effect of effects ) { for (const effect of effects) {
const data = effect.toObject(); const data = effect.toObject();
delete data._id; delete data._id;
if ( effect.compendium ) { if (effect.compendium) {
data._stats.duplicateSource = null; data._stats.duplicateSource = null;
data._stats.compendiumSource = effect.uuid; data._stats.compendiumSource = effect.uuid;
} else { } else {
data._stats.duplicateSource = effect.uuid; data._stats.duplicateSource = effect.uuid;
data._stats.compendiumSource = null; data._stats.compendiumSource = null;
}
data._stats.exportSource = null;
data.origin = this.parent.uuid;
toCreate.push(data);
} }
data._stats.exportSource = null; if (toCreate.length) await actor.createEmbeddedDocuments('ActiveEffect', toCreate);
data.origin = this.parent.uuid;
toCreate.push(data);
}
if ( toCreate.length ) await actor.createEmbeddedDocuments("ActiveEffect", toCreate);
await resumeMovement?.(); await resumeMovement?.();
} }
/** @override */ /** @override */
static events = { static events = {
...CONFIG.RegionBehavior.dataModels.applyActiveEffect.events, ...CONFIG.RegionBehavior.dataModels.applyActiveEffect.events,
[CONST.REGION_EVENTS.TOKEN_ENTER]: this.#onTokenEnter, [CONST.REGION_EVENTS.TOKEN_ENTER]: this.#onTokenEnter
}; };
} }

View file

@ -137,7 +137,7 @@ export default class DhpChatMessage extends foundry.documents.ChatMessage {
element.addEventListener('click', this.onApplyEffect.bind(this)) element.addEventListener('click', this.onApplyEffect.bind(this))
); );
html.querySelectorAll('.action-areas').forEach(element => html.querySelectorAll('.action-areas').forEach(element =>
element.addEventListener('click', this.onCreateAreas.bind(this)) element.addEventListener('click', this.onCreateAreas.bind(this))
); );
@ -254,9 +254,9 @@ export default class DhpChatMessage extends foundry.documents.ChatMessage {
} }
async onCreateAreas(event) { async onCreateAreas(event) {
const createArea = async (selectedArea) => { const createArea = async selectedArea => {
const effects = selectedArea.effects.map(effect => this.system.action.item.effects.get(effect).uuid); const effects = selectedArea.effects.map(effect => this.system.action.item.effects.get(effect).uuid);
const { shape: type, size: range } = selectedArea; const { shape: type, size: range } = selectedArea;
const shapeData = CONFIG.Canvas.layers.regions.layerClass.getTemplateShape({ type, range }); const shapeData = CONFIG.Canvas.layers.regions.layerClass.getTemplateShape({ type, range });
await canvas.regions.placeRegion( await canvas.regions.placeRegion(
@ -264,13 +264,15 @@ export default class DhpChatMessage extends foundry.documents.ChatMessage {
name: selectedArea.name, name: selectedArea.name,
shapes: [shapeData], shapes: [shapeData],
restriction: { enabled: false, type: 'move', priority: 0 }, restriction: { enabled: false, type: 'move', priority: 0 },
behaviors: [{ behaviors: [
name: game.i18n.localize('TYPES.RegionBehavior.applyActiveEffect'), {
type: 'applyActiveEffect', name: game.i18n.localize('TYPES.RegionBehavior.applyActiveEffect'),
system: { type: 'applyActiveEffect',
effects: effects system: {
effects: effects
}
} }
}], ],
displayMeasurements: true, displayMeasurements: true,
locked: false, locked: false,
ownership: { default: CONST.DOCUMENT_OWNERSHIP_LEVELS.NONE }, ownership: { default: CONST.DOCUMENT_OWNERSHIP_LEVELS.NONE },
@ -278,18 +280,17 @@ export default class DhpChatMessage extends foundry.documents.ChatMessage {
}, },
{ create: true } { create: true }
); );
} };
if (this.system.action.area.length === 1) if (this.system.action.area.length === 1) createArea(this.system.action.area[0]);
createArea(this.system.action.area[0]); else if (this.system.action.area.length > 1) {
else if(this.system.action.area.length > 1) { /* Pop a selection. Possibly a context menu? */
/* Pop a selection. Possibly a context menu? */
new foundry.applications.ux.ContextMenu.implementation( new foundry.applications.ux.ContextMenu.implementation(
event.target, event.target,
'.action-areas', '.action-areas',
this.system.action.area.map((area, index) => ({ this.system.action.area.map((area, index) => ({
name: area.name, name: area.name,
callback: () => createArea(this.system.action.area[index]), callback: () => createArea(this.system.action.area[index])
})), })),
{ {
jQuery: false, jQuery: false,

View file

@ -61,7 +61,7 @@ export const renderMeasuredTemplate = async event => {
type, type,
angle, angle,
range, range,
direction, direction
}); });
await canvas.regions.placeRegion( await canvas.regions.placeRegion(
@ -77,4 +77,4 @@ export const renderMeasuredTemplate = async event => {
}, },
{ create: true } { create: true }
); );
}; };

View file

@ -16,7 +16,7 @@ export default class RegisterHandlebarsHelpers {
empty: this.empty, empty: this.empty,
pluralize: this.pluralize, pluralize: this.pluralize,
positive: this.positive, positive: this.positive,
isNullish: this.isNullish, isNullish: this.isNullish
}); });
} }
static add(a, b) { static add(a, b) {