Amélioration robustess et vérification sur import des modules
This commit is contained in:
@@ -30,6 +30,20 @@ const __SELECT_BONUS_PREFIX_D = {
|
||||
"agilité": 1
|
||||
}
|
||||
|
||||
// Map English characteristic names (as they appear in spell formulas) to WFRP4e abbreviations
|
||||
const __CHAR_EN_TO_ABBR = {
|
||||
"weapon skill": "ws",
|
||||
"ballistic skill": "bs",
|
||||
"strength": "s",
|
||||
"toughness": "t",
|
||||
"initiative": "i",
|
||||
"agility": "ag",
|
||||
"dexterity": "dex",
|
||||
"intelligence": "int",
|
||||
"willpower": "wp",
|
||||
"fellowship": "fel"
|
||||
}
|
||||
|
||||
/************************************************************************************/
|
||||
export class WFRP4FrTranslation {
|
||||
|
||||
@@ -57,16 +71,23 @@ export class WFRP4FrTranslation {
|
||||
if (value == "You") return "Vous"; // Hop !
|
||||
if (value == "Instant") return "Instantané"; // Hop !
|
||||
let translw = value;
|
||||
let re = /(.*)\s+[Bb]onus\s*(\w*)/i;
|
||||
let re = /(.*)\s+[Bb]onus\s*(.*)/i; // (.*) at end captures modifiers like "+4"
|
||||
let res = re.exec(value);
|
||||
let unit = "";
|
||||
if (res) { // Test "<charac> Bonus <unit>" pattern
|
||||
if (res) { // Test "<charac> Bonus <modifier>" pattern
|
||||
if (res[1]) { // We have char name, then convert it
|
||||
translw = game.i18n.localize(res[1].trim());
|
||||
let bonusPrefix = (translw.toLowerCase() in __SELECT_BONUS_PREFIX_D) ? "Bonus d'" : "Bonus de ";
|
||||
translw = bonusPrefix + translw
|
||||
const charEN = res[1].trim().toLowerCase();
|
||||
const abbr = __CHAR_EN_TO_ABBR[charEN];
|
||||
if (abbr && game.wfrp4e?.config?.characteristicsBonus?.[abbr]) {
|
||||
// Use the localized French bonus name from config (already resolved by localizeConfig at i18nInit)
|
||||
translw = game.wfrp4e.config.characteristicsBonus[abbr];
|
||||
} else {
|
||||
translw = game.i18n.localize(res[1].trim());
|
||||
let bonusPrefix = (translw.toLowerCase() in __SELECT_BONUS_PREFIX_D) ? "Bonus d'" : "Bonus de ";
|
||||
translw = bonusPrefix + translw;
|
||||
}
|
||||
}
|
||||
unit = res[2];
|
||||
unit = res[2]; // may be "+4", "-2", "2", "yards", etc.
|
||||
} else {
|
||||
re = /(\d+) (\w+)/i;
|
||||
res = re.exec(value);
|
||||
@@ -90,6 +111,8 @@ export class WFRP4FrTranslation {
|
||||
if (unit == "Bonus") { // Another weird management
|
||||
console.log("Translating bonus", unit);
|
||||
translw = "Bonus de " + translw;
|
||||
} else if (unit && /^[+\-*\/]/.test(unit)) {
|
||||
translw += unit; // No space before operators like "+4"
|
||||
} else {
|
||||
translw += " " + unit;
|
||||
}
|
||||
@@ -278,6 +301,8 @@ Hooks.once('init', () => {
|
||||
"process_effects": (effectsData, translations, data, tc, tc_translations) => {
|
||||
//console.log("Effects :", effectsData, translations, data, tc, tc_translations)
|
||||
for (let e of effectsData) {
|
||||
// Foundry v13 requires name; migrate legacy data where only label was stored
|
||||
if (e.name == null) e.name = e.label || "";
|
||||
let origName = e.name
|
||||
// Symptom effects have their own name (Fever, Malaise, etc.) — don't overwrite with the parent item name
|
||||
if (e.flags?.wfrp4e?.symptom) {
|
||||
@@ -293,7 +318,7 @@ Hooks.once('init', () => {
|
||||
}
|
||||
e.name = game.i18n.localize(symName) + gravity;
|
||||
} else {
|
||||
e.name = tc_translations.name || game.i18n.localize(e.name)
|
||||
e.name = tc_translations.name || game.i18n.localize(e.name) || e.label || ""
|
||||
}
|
||||
if ( e.flags?.wfrp4e?.scriptData) {
|
||||
for (let script of e.flags.wfrp4e.scriptData) {
|
||||
@@ -411,10 +436,18 @@ Hooks.once('init', () => {
|
||||
return beast_traits
|
||||
}
|
||||
//console.log("TRANS:", beast_traits)
|
||||
// Normalize: Foundry v13 requires ActiveEffect.name; migrate legacy v12 data
|
||||
for (let trait_en of beast_traits) {
|
||||
if (trait_en.effects) {
|
||||
for (let eff of trait_en.effects) {
|
||||
if (eff.name == null) eff.name = eff.label || "";
|
||||
}
|
||||
}
|
||||
}
|
||||
for (let trait_en of beast_traits) {
|
||||
let special = "";
|
||||
let nbt = "";
|
||||
let name_en = trait_en.name.trim(); // strip \r in some traits name
|
||||
let name_en = trait_en.name.replace(/\r/g, '').trim(); // strip \r (including internal) in some traits name
|
||||
if (!trait_en.name || trait_en.name.length == 0) {
|
||||
console.log("Wrong item name found!!!!")
|
||||
continue
|
||||
@@ -430,8 +463,11 @@ Hooks.once('init', () => {
|
||||
} else if (name_en.includes("(") && name_en.includes(")")) { // Then process specific traits name with (xxxx) inside
|
||||
let re = /(.*) \((.*)\)/i;
|
||||
let res = re.exec(name_en);
|
||||
name_en = res[1]; // Get the root traits name
|
||||
special = " (" + game.i18n.localize(res[2].trim()) + ")"; // And the special keyword
|
||||
if (!res) { console.warn("WFRP4E-FR | bestiary_traits: regex failed for trait:", name_en); }
|
||||
else {
|
||||
name_en = res[1]; // Get the root traits name
|
||||
special = " (" + game.i18n.localize(res[2].trim()) + ")"; // And the special keyword
|
||||
}
|
||||
}
|
||||
let validCompendiums = game.wfrp4e.tags.getPacksWithTag("trait")
|
||||
for (let compData of validCompendiums) {
|
||||
@@ -453,8 +489,11 @@ Hooks.once('init', () => {
|
||||
if (name_en.includes("(") && name_en.includes(")")) { // Then process specific skills name with (xxxx) inside
|
||||
let re = /(.*) +\((.*)\)/i;
|
||||
let res = re.exec(name_en);
|
||||
name_en = res[1].trim(); // Get the root skill name
|
||||
special = " (" + game.i18n.localize(res[2].trim()) + ")"; // And the special keyword
|
||||
if (!res) { console.warn("WFRP4E-FR | bestiary_traits: regex failed for skill:", name_en); }
|
||||
else {
|
||||
name_en = res[1].trim(); // Get the root skill name
|
||||
special = " (" + game.i18n.localize(res[2].trim()) + ")"; // And the special keyword
|
||||
}
|
||||
}
|
||||
let validCompendiums = game.wfrp4e.tags.getPacksWithTag("skill")
|
||||
for (let compData of validCompendiums) {
|
||||
@@ -499,8 +538,11 @@ Hooks.once('init', () => {
|
||||
if (name_en.includes("(") && name_en.includes(")")) { // Then process specific skills name with (xxxx) inside
|
||||
let re = /(.*) +\((.*)\)/i;
|
||||
let res = re.exec(name_en);
|
||||
name_en = res[1].trim(); // Get the root talent name, no parenthesis this time...
|
||||
special = " (" + game.i18n.localize(res[2].trim()) + ")"; // And the special keyword
|
||||
if (!res) { console.warn("WFRP4E-FR | bestiary_traits: regex failed for talent:", name_en); }
|
||||
else {
|
||||
name_en = res[1].trim(); // Get the root talent name, no parenthesis this time...
|
||||
special = " (" + game.i18n.localize(res[2].trim()) + ")"; // And the special keyword
|
||||
}
|
||||
}
|
||||
let validCompendiums = game.wfrp4e.tags.getPacksWithTag("talent")
|
||||
for (let compData of validCompendiums) {
|
||||
|
||||
Reference in New Issue
Block a user