Skip to content

Commit 9b99eee

Browse files
committed
FIX - descriptions & more things
1 parent 497f643 commit 9b99eee

42 files changed

Lines changed: 2558 additions & 121 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/module/actor/ABFActorSheet.js

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,8 @@ export default class ABFActorSheet extends ActorSheet {
151151
}
152152

153153
_setupDebouncedSheetUpdates(html) {
154-
// Keep a flat object with pending updates: { "system.foo.bar": 123, ... }
155154
this._pendingUpdate = this._pendingUpdate ?? {};
156155

157-
// Debounced flush (single update per burst)
158156
this._flushPendingUpdate =
159157
this._flushPendingUpdate ??
160158
foundry.utils.debounce(async () => {
@@ -165,31 +163,39 @@ export default class ABFActorSheet extends ActorSheet {
165163

166164
const [actorChanges, itemChanges] = splitAsActorAndItemChanges(flat);
167165

168-
// Update items first (if any)
169166
await this.updateItems(itemChanges);
170167

171-
// Then update actor (if any)
172168
if (actorChanges && Object.keys(actorChanges).length > 0) {
173169
await this.actor.update(actorChanges);
174170
}
175171
}, 150);
176172

177-
// Listen to changes on any form control
178173
html.on('change', 'input, select, textarea', ev => {
179174
const el = ev.currentTarget;
180175
if (!el?.name) return;
181176

182177
let value;
183-
if (el.type === 'checkbox') value = el.checked;
184-
else value = el.value;
185178

186-
// Convert numbers
187-
if (el.type === 'number') value = Number(value);
179+
if (el.type === 'checkbox') {
180+
value = el.checked;
181+
} else {
182+
value = el.value;
183+
}
188184

189-
// Accumulate changes using the input name as the update path
190-
// Example: "system.general.presence.base.value"
191-
this._pendingUpdate[el.name] = value;
185+
// Respect Foundry-style dtype (works for <select> too)
186+
const dtype = el.dataset?.dtype;
187+
188+
if (dtype === 'Number') {
189+
const n = Number(value);
190+
value = Number.isFinite(n) ? n : 0;
191+
} else if (dtype === 'Boolean') {
192+
value = value === 'true' || value === true;
193+
} else if (el.type === 'number') {
194+
const n = Number(value);
195+
value = Number.isFinite(n) ? n : 0;
196+
}
192197

198+
this._pendingUpdate[el.name] = value;
193199
this._flushPendingUpdate();
194200
});
195201
}
@@ -367,13 +373,6 @@ export default class ABFActorSheet extends ActorSheet {
367373
protected;
368374

369375
async _updateObject(event, formData) {
370-
// We have to parse all qualities in order to convert from it selectable to integers to make calculations
371-
Object.keys(formData).forEach(key => {
372-
if (key.includes('quality')) {
373-
formData[key] = parseInt(formData[key], 10);
374-
}
375-
});
376-
377376
const [actorChanges, itemChanges] = splitAsActorAndItemChanges(formData);
378377

379378
await this.updateItems(itemChanges);

src/module/actor/constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ export const INITIAL_ACTOR_DATA = {
939939
}
940940
},
941941
wearArmor: {
942-
value: 0
942+
__type: '{"type":"NumericalValue"}'
943943
},
944944
totalArmor: {
945945
at: {

src/module/actor/utils/parseExcelToActor.js

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -199,28 +199,44 @@ export const parseExcelToActor = async (excelData, actor) => {
199199
characteristics: {
200200
primaries: {
201201
agility: {
202-
value: excelData.AGI
202+
base: {
203+
value: excelData.AGI
204+
}
203205
},
204206
constitution: {
205-
value: excelData.CON
207+
base: {
208+
value: excelData.CON
209+
}
206210
},
207211
dexterity: {
208-
value: excelData.DES
212+
base: {
213+
value: excelData.DES
214+
}
209215
},
210216
strength: {
211-
value: excelData.FUE
217+
base: {
218+
value: excelData.FUE
219+
}
212220
},
213221
intelligence: {
214-
value: excelData.INT
222+
base: {
223+
value: excelData.INT
224+
}
215225
},
216226
power: {
217-
value: excelData.POD
227+
base: {
228+
value: excelData.POD
229+
}
218230
},
219231
perception: {
220-
value: excelData.PER
232+
base: {
233+
value: excelData.PER
234+
}
221235
},
222236
willPower: {
223-
value: excelData.VOL
237+
base: {
238+
value: excelData.VOL
239+
}
224240
}
225241
},
226242
secondaries: {
@@ -293,7 +309,9 @@ export const parseExcelToActor = async (excelData, actor) => {
293309
}
294310
},
295311
wearArmor: {
296-
value: excelData.LlevarArmadura_final
312+
base: {
313+
value: excelData.LlevarArmadura_final
314+
}
297315
},
298316
combatSpecialSkills: [],
299317
combatTables: []
@@ -306,7 +324,9 @@ export const parseExcelToActor = async (excelData, actor) => {
306324
},
307325
modifiers: {
308326
extraDamage: {
309-
value: extraDamage
327+
base: {
328+
value: extraDamage
329+
}
310330
}
311331
},
312332
settings: {

src/module/actor/utils/prepareActor/calculations/actor/general/mutateMovementType.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const calculateArmorsMovementTypeModifier = data => {
99
);
1010

1111
const totalWearRequirement = calculateEquippedArmorsRequirement(data);
12-
const wearArmor = data.combat.wearArmor.value;
12+
const wearArmor = data.combat.wearArmor.final.value;
1313

1414
const wearArmorModifier = Math.floor(
1515
Math.max(0, wearArmor - totalWearRequirement) / 50
@@ -44,7 +44,7 @@ mutateMovementType.abfFlow = {
4444
'system.general.modifiers.allActions.final.value',
4545

4646
// armor penalty (calculateArmorPhysicalPenalty)
47-
'system.combat.wearArmor.value',
47+
'system.combat.wearArmor.final.value',
4848
'system.combat.armors'
4949
],
5050
mods: [

src/module/actor/utils/prepareActor/calculations/actor/modifiers/calculations/calculateArmorPhysicalPenalty.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ export const calculateArmorPhysicalPenalty = data => {
2020

2121
if (getEquippedArmors(data).length === 0) return 0;
2222

23-
return Math.min(0, data.combat.wearArmor.value - totalWearRequirement);
23+
return Math.min(0, data.combat.wearArmor.final.value - totalWearRequirement);
2424
};

src/module/actor/utils/prepareActor/calculations/actor/modifiers/mutateNaturalPenalty.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { calculateEquippedArmorsRequirement } from './calculations/calculateArmo
66
* @param {import('../../../../../../types/Actor').ABFActorDataSourceData} data
77
*/
88
export const mutateNaturalPenalty = data => {
9-
let wearArmor = data.combat.wearArmor.value;
9+
let wearArmor = data.combat.wearArmor.final.value;
1010
let wearArmorRequirement = calculateEquippedArmorsRequirement(data);
1111
let armorsNaturalPenalty = calculateArmorsNaturalPenalty(data);
1212
let equippedArmorsPenalty = calculateEquippedArmorsNaturalPenalty(data);
@@ -29,7 +29,7 @@ export const mutateNaturalPenalty = data => {
2929

3030
mutateNaturalPenalty.abfFlow = {
3131
deps: [
32-
'system.combat.wearArmor.value',
32+
'system.combat.wearArmor.final.value',
3333
'system.combat.armors',
3434
'system.general.modifiers.naturalPenalty.base.value',
3535
'system.general.modifiers.naturalPenalty.special.value'

src/module/actor/utils/prepareActor/calculations/actor/modifiers/mutatePhysicalModifier.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ mutatePhysicalModifier.abfFlow = {
1717
'system.general.modifiers.physicalActions.base.value',
1818
'system.general.modifiers.physicalActions.special.value',
1919

20-
'system.combat.wearArmor.value',
20+
'system.combat.wearArmor.final.value',
2121
'system.combat.armors'
2222
],
2323
mods: ['system.general.modifiers.physicalActions.final.value']

src/module/actor/utils/prepareActor/prepareActor.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -53,40 +53,40 @@ export const prepareActor = async actor => {
5353
}
5454

5555
actor.__abfPreparePromise = (async () => {
56-
globalThis.__abfPrepareRunId = (globalThis.__abfPrepareRunId ?? 0) + 1;
57-
const runId = globalThis.__abfPrepareRunId;
56+
// DEBUG PATHS
57+
// const watchPaths = [
58+
// 'system.characteristics.secondaries.resistances.magic.special.value'
59+
// ];
5860

59-
// 🔍 DEBUG PATHS — pon aquí los que se estén acumulando
60-
const watchPaths = [
61-
'system.characteristics.secondaries.resistances.magic.special.value'
62-
];
61+
// dbgDump(actor, `RUN ${runId} BEFORE reset`, watchPaths);
6362

64-
dbgDump(actor, `RUN ${runId} BEFORE reset`, watchPaths);
65-
66-
// ✅ Baseline desde datos RAW del actor
63+
// 1) reset baseline
6764
const baselineSystem = foundry.utils.duplicate(actor._source.system);
68-
6965
foundry.utils.mergeObject(actor.system, baselineSystem, {
7066
overwrite: true,
7167
insertKeys: true,
7268
insertValues: true
7369
});
74-
7570
actor.system = inflateSystemFromTypeMarkers(actor.system);
7671

77-
dbgDump(actor, `RUN ${runId} AFTER reset`, watchPaths);
78-
72+
// 2) preparar items (si tus derivedFns dependen de items)
7973
await prepareItems(actor);
8074

81-
dbgDump(actor, `RUN ${runId} BEFORE flow`, watchPaths);
82-
83-
// ✅ Nuevo pipeline: build -> order -> apply
84-
await runEffectFlow(actor, {
85-
derivedFns: DERIVED_DATA_FUNCTIONS
86-
// debug: true
87-
});
88-
89-
dbgDump(actor, `RUN ${runId} AFTER flow`, watchPaths);
75+
// 3) flow (AE + derivedFns)
76+
await runEffectFlow(actor, { derivedFns: DERIVED_DATA_FUNCTIONS });
77+
78+
// 4) UI-only derived (AQUÍ VA “LO NUEVO”)
79+
actor.system.general.description.enriched = await TextEditor.enrichHTML(
80+
actor.system.general.description.value,
81+
{ async: true }
82+
);
83+
84+
for (const key of Object.keys(actor.system.ui.contractibleItems ?? {})) {
85+
if (typeof actor.system.ui.contractibleItems[key] === 'string') {
86+
actor.system.ui.contractibleItems[key] =
87+
actor.system.ui.contractibleItems[key] === 'true';
88+
}
89+
}
9090
})();
9191

9292
try {
@@ -105,8 +105,8 @@ function dbgGet(actor, path) {
105105
}
106106

107107
function dbgDump(actor, label, paths) {
108-
// const rows = paths.map(p => dbgGet(actor, p));
109-
// console.groupCollapsed(`[FLOW][DBG] ${label}`);
110-
// console.table(rows);
111-
// console.groupEnd();
108+
const rows = paths.map(p => dbgGet(actor, p));
109+
console.groupCollapsed(`[FLOW][DBG] ${label}`);
110+
console.table(rows);
111+
console.groupEnd();
112112
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { ALL_ITEM_CONFIGURATIONS } from './constants';
22

3-
export const prepareItems = actor => {
3+
export const prepareItems = async actor => {
44
for (const itemType in ALL_ITEM_CONFIGURATIONS) {
55
if (ALL_ITEM_CONFIGURATIONS.hasOwnProperty(itemType)) {
66
const config = ALL_ITEM_CONFIGURATIONS[itemType];
7-
config.resetFieldPath(actor);
7+
await config.resetFieldPath(actor);
88
}
99
}
1010
};

0 commit comments

Comments
 (0)