fix: Babele-2.9.1-Wörterbuch-Lookups repariert + Zauberformel-Timing-Fix

game.babele.translate(pack, {name: value}) liefert in der installierten
Babele-Version bei jedem Aufruf den unveraenderten Input zurueck, egal ob
eine Uebersetzung existiert. Betroffen waren career_careergroup_fn,
career_skills_fn, career_talents sowie alle Zweige von bestiary_traits
(Trait/Skill/Prayer/Spell/Talent/Career/VehicleRole/Trapping) in
babele-register.js - dadurch blieben Karrierenamen wie "Agitator"
unuebersetzt (mit Fehlermeldung im Chat) und NPC-Zauberformeln enthielten
noch rohen englischen Text.

Fix: eigene compendium/*.json-Woerterbuecher direkt per fetch() einlesen
und in __dictCaches cachen, statt sich auf Babeles translate() zu
verlassen. Cache-Aufbau in den 'ready'-Hook verschoben (game.wfrp4e
existiert waehrend 'babele.init' noch nicht garantiert).

parseSpellContent laeuft in bestiary_traits jetzt unabhaengig davon, ob
der Zauber/das Gebet einen Woerterbuchtreffer hat - vorher blieb die
Formel-Korrektur bei fehlendem Treffer komplett aus. Zusaetzlich
OvercastItemModel.prototype.computeSpellDamage in addon-register.js
gepatcht, damit auch rohe englische Bonus-Phrasen ("Toughness Bonus")
erkannt werden, unabhaengig vom Uebersetzungs-Timing (trat u.a. beim
Laden von Journal-Link-Vorschauen auf, wo unsere Konverter noch nicht
gelaufen waren).

Ausserdem die deaktivierte Chat-Abschlussmeldung ("Shallya"-Segen) in
addon-register.js wieder aktiviert und so verkabelt, dass sie auf den
tatsaechlichen Abschluss der __dictCaches-Ladevorgaenge wartet statt auf
einen festen Timeout.
This commit is contained in:
alzer
2026-09-28 20:19:12 +02:00
parent 9d6af8cc73
commit ba35a60e4a
3 changed files with 195 additions and 186 deletions
+47 -5
View File
@@ -232,11 +232,18 @@ const __check_fix_wrong_modules = (chatFlag, patchFinished) => {
});
}
} else {
if (false && game.user.isGM && patchFinished) {
ChatMessage.create({
content: "<div>Die WFRP4E-Module wurden <strong>erfolgreich</strong> übersetzt. Du kannst loslegen und <strong>möge Shallya dich behüten</strong></div>",
user: game.user.id,
whisper: ChatMessage.getWhisperRecipients("GM")
if (game.user.isGM && patchFinished) {
// Wait for babele-register.js's dictionary caches (career/skill/trait/prayer/
// spell/talent/vehicleRole/trapping - used by career_careergroup_fn and
// bestiary_traits) to actually finish loading before announcing completion,
// rather than relying on this function's fixed 20s setTimeout delay alone -
// that delay predates those caches and isn't guaranteed to outlast them.
Promise.resolve(game.wfrp4efr?.dictCachesReady).finally(() => {
ChatMessage.create({
content: "<div>Die WFRP4E-Module wurden <strong>erfolgreich</strong> übersetzt. Du kannst loslegen und <strong>möge Shallya dich behüten</strong></div>",
user: game.user.id,
whisper: ChatMessage.getWhisperRecipients("GM")
});
});
}
}
@@ -469,6 +476,41 @@ Hooks.on('ready', () => {
};
}
// Patch OvercastItemModel.prototype.computeSpellDamage (shared by SpellModel and
// PrayerModel, both `extends OvercastItemModel`) to also recognize raw English
// characteristic-bonus phrases in the damage formula, not just the current locale's.
// The system's own implementation does
// `formula.replace(game.wfrp4e.config.characteristicsBonus[ch].toLowerCase(), ...)`,
// which only ever tries the CURRENT (German) localized text - e.g. "widerstandsbonus"
// for Toughness. If a spell/prayer's damage.value formula is still raw English (e.g.
// "Toughness Bonus+4"), because the document was loaded through a path where Babele's
// translation converters run too late to matter for this field (observed via a journal
// page's link-preview priming, which constructs the full Item/Actor - and immediately
// evaluates derived data - before our custom converters get a chance to rewrite the
// formula text), the replace never matches and the leftover text throws a SyntaxError
// when eval()'d. This tries the English phrase too, as a fallback, so the formula
// evaluates correctly regardless of translation timing.
const overcastProto = Object.getPrototypeOf(CONFIG.Item.dataModels.spell?.prototype ?? {});
if (overcastProto?.computeSpellDamage) {
const originalComputeSpellDamage = overcastProto.computeSpellDamage;
const EN_CHARACTERISTICS_BONUS = {
"ws": "weapon skill bonus", "bs": "ballistic skill bonus", "s": "strength bonus",
"t": "toughness bonus", "i": "initiative bonus", "ag": "agility bonus",
"dex": "dexterity bonus", "int": "intelligence bonus", "wp": "willpower bonus", "fel": "fellowship bonus"
};
overcastProto.computeSpellDamage = function (formula, options) {
if (typeof formula === "string") {
const lower = formula.toLowerCase();
for (const [abbr, enPhrase] of Object.entries(EN_CHARACTERISTICS_BONUS)) {
if (!lower.includes(enPhrase)) continue;
const dePhrase = game.wfrp4e.config.characteristicsBonus?.[abbr]?.toLowerCase();
if (dePhrase) formula = formula.replace(new RegExp(enPhrase, "ig"), dePhrase);
}
}
return originalComputeSpellDamage.call(this, formula, options);
};
}
game.wfrp4e.warnDialog.render(true, { focus: true, left: 20, top: 20 });
//setTimeout( __check_fix_wrong_modules, 2000, true, false);
setTimeout(__check_fix_wrong_modules, 20000, true, true);