Skip to content

Commit e6a6b4a

Browse files
committed
More render check hook refactor fixes
1 parent 95fdac7 commit e6a6b4a

23 files changed

+107
-95
lines changed

module/checks/attribute-check.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { CheckHooks } from './check-hooks.mjs';
22
import { CHECK_ROLL } from './default-section-order.mjs';
33
import { CheckConfiguration } from './check-configuration.mjs';
44
import { SYSTEM } from '../helpers/config.mjs';
5+
import { CommonSections } from './common-sections.mjs';
56

67
const critThresholdFlag = 'critThreshold.attributeCheck';
78

@@ -21,7 +22,7 @@ const onPrepareCheck = (check, actor) => {
2122
};
2223

2324
/** @type RenderCheckHook */
24-
const onRenderCheck = (data, checkResult, actor, item) => {
25+
const onRenderCheck = (data, checkResult, actor, item, flags) => {
2526
const { type, primary, modifierTotal, secondary, result, critical, fumble } = checkResult;
2627
if (type === 'attribute') {
2728
const inspector = CheckConfiguration.inspect(checkResult);
@@ -52,6 +53,9 @@ const onRenderCheck = (data, checkResult, actor, item) => {
5253
modifiers: checkResult.modifiers,
5354
},
5455
});
56+
57+
const targets = inspector.getTargetsOrDefault();
58+
CommonSections.actions(data, actor, item, targets, flags, inspector);
5559
}
5660
};
5761

module/documents/items/accessory/accessory-data-model.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import { CommonSections } from '../../../checks/common-sections.mjs';
44
import { FUStandardItemDataModel } from '../item-data-model.mjs';
55
import { ItemPartialTemplates } from '../item-partial-templates.mjs';
66

7-
Hooks.on(CheckHooks.renderCheck, (sections, check, actor, item) => {
7+
Hooks.on(CheckHooks.renderCheck, (data, check, actor, item) => {
88
if (item?.system instanceof AccessoryDataModel) {
9-
CommonSections.tags(sections, item.system.getTags());
9+
CommonSections.tags(data.sections, item.system.getTags());
1010

11-
CommonSections.quality(sections, item.system.quality.value);
12-
CommonSections.description(sections, item.system.description, item.system.summary.value);
11+
CommonSections.quality(data.sections, item.system.quality.value);
12+
CommonSections.description(data.sections, item.system.description, item.system.summary.value);
1313
}
1414
});
1515

module/documents/items/armor/armor-data-model.mjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import { PseudoItem } from '../pseudo-item.mjs';
1010
import { SETTINGS } from '../../../settings.js';
1111
import { PseudoDocumentEnabledTypeDataModel } from '../../pseudo/pseudo-document-enabled-type-data-model.mjs';
1212

13-
Hooks.on(CheckHooks.renderCheck, (sections, check, actor, item) => {
13+
Hooks.on(CheckHooks.renderCheck, (data, check, actor, item) => {
1414
if (item?.system instanceof ArmorDataModel) {
15-
CommonSections.tags(sections, [
15+
CommonSections.tags(data.sections, [
1616
{
1717
tag: 'FU.Martial',
1818
show: item.system.isMartial.value,
@@ -31,12 +31,12 @@ Hooks.on(CheckHooks.renderCheck, (sections, check, actor, item) => {
3131
},
3232
]);
3333

34-
CommonSections.quality(sections, item.system.quality.value);
34+
CommonSections.quality(data.sections, item.system.quality.value);
3535

3636
if (game.settings.get(SYSTEM, SETTINGS.technospheres)) {
37-
CommonSections.slottedTechnospheres(sections, item.system.slotted);
37+
CommonSections.slottedTechnospheres(data.sections, item.system.slotted);
3838
} else {
39-
CommonSections.description(sections, item.system.description, item.system.summary.value);
39+
CommonSections.description(data.sections, item.system.description, item.system.summary.value);
4040
}
4141
}
4242
});

module/documents/items/behavior/behavior-data-model.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { CommonSections } from '../../../checks/common-sections.mjs';
33
import { FUStandardItemDataModel } from '../item-data-model.mjs';
44
import { ItemPartialTemplates } from '../item-partial-templates.mjs';
55

6-
Hooks.on(CheckHooks.renderCheck, (sections, check, actor, item) => {
6+
Hooks.on(CheckHooks.renderCheck, (data, check, actor, item) => {
77
if (item?.system instanceof BehaviorDataModel) {
8-
CommonSections.description(sections, item.system.description, item.system.summary.value);
8+
CommonSections.description(data.sections, item.system.description, item.system.summary.value);
99
}
1010
});
1111

module/documents/items/class/class-data-model.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ const tagProperties = {
2020
'benefits.rituals.spiritism.value': 'FU.Spiritism',
2121
};
2222

23-
Hooks.on(CheckHooks.renderCheck, (sections, check, actor, item) => {
23+
Hooks.on(CheckHooks.renderCheck, (data, check, actor, item) => {
2424
if (item?.system instanceof ClassDataModel) {
2525
const tags = item.system.getTags();
26-
CommonSections.tags(sections, tags);
26+
CommonSections.tags(data.sections, tags);
2727

28-
CommonSections.description(sections, item.system.description, item.system.summary.value);
28+
CommonSections.description(data.sections, item.system.description, item.system.summary.value);
2929
}
3030
});
3131

module/documents/items/classFeature/class-feature-type-data-model.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import { RegistryDataField } from '../../../fields/registry-data-field.mjs';
66
import { ClassFeatureRegistry } from './class-feature-registry.mjs';
77
import { EmbeddedFeatureDataModel } from '../embedded-feature-data-model.mjs';
88

9-
Hooks.on(CheckHooks.renderCheck, (sections, check, actor, item) => {
9+
Hooks.on(CheckHooks.renderCheck, (data, check, actor, item) => {
1010
if (item?.system instanceof ClassFeatureTypeDataModel && !(item.system.data instanceof RollableClassFeatureDataModel)) {
11-
CommonSections.description(sections, item.system.description, item.system.summary.value);
11+
CommonSections.description(data.sections, item.system.description, item.system.summary.value);
1212
}
1313
});
1414

module/documents/items/classFeature/gourmet/ingredient-data-model.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import { CommonSections } from '../../../../checks/common-sections.mjs';
55
import { TextEditor } from '../../../../helpers/text-editor.mjs';
66

77
/** @type RenderCheckHook */
8-
const onRenderCheck = (sections, check, actor, item, additionalFlags, targets) => {
8+
const onRenderCheck = (data, check, actor, item, additionalFlags, targets) => {
99
if (check.type === 'display' && item?.system?.data instanceof IngredientDataModel) {
1010
CommonSections.tags(
11-
sections,
11+
data.sections,
1212
[
1313
{
1414
tag: 'FU.ClassFeatureIngredientTaste',

module/documents/items/classFeature/tinkerer/alchemy-data-model.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ const alchemyRanks = {
1818
/**
1919
* @type {RenderCheckHook}
2020
*/
21-
const onRenderCheck = (sections, check, actor, item) => {
21+
const onRenderCheck = (data, check, actor, item) => {
2222
if (check.type === 'display' && item?.system?.data instanceof AlchemyDataModel) {
23-
CommonSections.description(sections, item.system.data.description, item.system.summary.value);
23+
CommonSections.description(data.sections, item.system.data.description, item.system.summary.value);
2424
}
2525
};
2626
Hooks.on(CheckHooks.renderCheck, onRenderCheck);

module/documents/items/hoplosphere/hoplosphere-data-model.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,10 +561,10 @@ export class HoplosphereDataModel extends foundry.abstract.TypeDataModel {
561561
}
562562

563563
/** @type {RenderCheckHook} */
564-
const onRenderDisplay = (sections, check, actor, item, additionalFlags) => {
564+
const onRenderDisplay = (data, check, actor, item, additionalFlags) => {
565565
if (check.type === 'display' && item?.type === 'hoplosphere') {
566566
CommonSections.genericText(
567-
sections,
567+
data.sections,
568568
foundry.applications.handlebars.renderTemplate('projectfu.hoplosphere.displayEffects', {
569569
effects: item.system.effects.map((effect) => ({
570570
name: effect.effectLabel,

module/documents/items/misc/misc-ability-data-model.mjs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { CommonSections } from '../../../checks/common-sections.mjs';
1010
import { ItemPartialTemplates } from '../item-partial-templates.mjs';
1111
import { TraitUtils } from '../../../pipelines/traits.mjs';
1212
import { BaseSkillDataModel } from '../skill/base-skill-data-model.mjs';
13-
import { ExpressionContext } from '../../../expressions/expressions.mjs';
1413
import { CommonEvents } from '../../../checks/common-events.mjs';
1514

1615
const skillForAttributeCheck = 'skillForAttributeCheck';
@@ -46,17 +45,17 @@ Hooks.on(CheckHooks.renderCheck, onRenderAccuracyCheck);
4645
/**
4746
* @type RenderCheckHook
4847
*/
49-
let onRenderAttributeCheck = async (sections, check, actor, item, flags) => {
48+
let onRenderAttributeCheck = async (data, check, actor, item, flags) => {
5049
if (check.type === 'attribute' && item?.system instanceof MiscAbilityDataModel && check.additionalData[skillForAttributeCheck]) {
5150
const inspector = CheckConfiguration.inspect(check);
5251
const ability = await fromUuid(inspector.getWeaponReference());
53-
CommonSections.itemFlavor(sections, ability);
52+
CommonSections.itemFlavor(data.sections, ability);
5453
if (check.critical) {
55-
CommonSections.opportunity(sections, ability.system.opportunity, CHECK_DETAILS);
54+
CommonSections.opportunity(data.sections, ability.system.opportunity, CHECK_DETAILS);
5655
}
57-
CommonSections.description(sections, ability.system.description, ability.system.summary.value, CHECK_DETAILS, true);
56+
CommonSections.description(data.sections, ability.system.description, ability.system.summary.value, CHECK_DETAILS, true);
5857
if (ability.system.hasClock.value) {
59-
CommonSections.clock(sections, item.system.progress, CHECK_DETAILS);
58+
CommonSections.clock(data.sections, item.system.progress, CHECK_DETAILS);
6059
}
6160
}
6261
};
@@ -157,7 +156,7 @@ export class MiscAbilityDataModel extends BaseSkillDataModel {
157156
secondary: this.attributes.secondary,
158157
},
159158
this.parent,
160-
this.#initializeAttributeCheck(),
159+
this.#initializeAttributeCheck(modifiers),
161160
);
162161
}
163162
}
@@ -179,11 +178,9 @@ export class MiscAbilityDataModel extends BaseSkillDataModel {
179178
/**
180179
* @return {CheckCallback}
181180
*/
182-
#initializeAttributeCheck() {
181+
#initializeAttributeCheck(modifiers) {
183182
return async (check, actor, item) => {
184-
const config = CheckConfiguration.configure(check);
185-
await this.configureAttributeCheck(config, actor, item);
186-
config.setWeaponReference(this.parent);
183+
await this.configureAttributeCheck(modifiers, check, actor, item);
187184
};
188185
}
189186

@@ -210,13 +207,7 @@ export class MiscAbilityDataModel extends BaseSkillDataModel {
210207
check.primary = weaponCheck.primary;
211208
check.secondary = weaponCheck.secondary;
212209

213-
const config = CheckConfiguration.configure(check);
214-
const targets = config.getTargets();
215-
const context = ExpressionContext.fromTargetData(actor, item, targets);
216-
config.setWeaponReference(weapon);
217-
await this.configureCheck(config);
218-
await this.addSkillAccuracy(config, actor, item, context);
219-
await this.addSkillDamage(config, item, context, weapon.system);
210+
return this.configureAccuracyCheck(modifiers, check, actor, item, weapon);
220211
};
221212
}
222213

0 commit comments

Comments
 (0)