forked from public/foundryvtt-wh4-lang-fr-fr
Align to 5.1.1 + FR stat parsing + fix sur prières + corrections typos
This commit is contained in:
@ -1,5 +1,22 @@
|
||||
/************************************************************************************/
|
||||
// Some internal test strings
|
||||
let strfr = `LA TERREUR DE LA TEUFEL, TROLL DE RIVIÈRE RUSÉ
|
||||
M
|
||||
CC CT
|
||||
F
|
||||
E
|
||||
I
|
||||
Ag Dex Int FM Soc B
|
||||
4
|
||||
40 15
|
||||
55
|
||||
45
|
||||
20
|
||||
15 15 30 20 5 38
|
||||
Traits : Amphibie, Arme +9, Armure (2), Dur à Cuire, Insensible
|
||||
à la douleur, Morsure +8, Régénération, Taille (Grande), Vision
|
||||
Nocturne, Vomissement`
|
||||
|
||||
let str1 = `JABBERSLYTHE
|
||||
M WS BS S T I Agi Dex
|
||||
Int WP Fel W
|
||||
@ -27,16 +44,22 @@ Talents: Briber, Criminal, Dealmaker,
|
||||
Etiquette (Criminals, Doktor, Guilder)
|
||||
Trappings: Dagger, Hand Weapon (Sword)
|
||||
`
|
||||
import ItemWfrp4e from "/systems/wfrp4e/modules/item/item-wfrp4e.js";
|
||||
import WFRP_Utility from "/systems/wfrp4e/modules/system/utility-wfrp4e.js";
|
||||
import ItemWfrp4e from "/systems/wfrp4e/modules/item/item-wfrp4e.js"
|
||||
|
||||
/************************************************************************************/
|
||||
import "./xregexp-all.js";
|
||||
const us_carac = 'm\\s+ws\\s+bs\\s+s\\s+t\\s+i\\s+agi?\\s+dex\\s+int\\s+\\wp\\s+fel\\s+w';
|
||||
const fr_carac = 'm\\s+ws\\s+bs\\s+s\\s+t\\s+i\\s+agi?\\s+dex\\s+int\\s+\\wp\\s+fel\\s+w';
|
||||
const fr_carac = 'm\\s+cc\\s+ct\\s+f\\s+e\\s+i\\s+agi?\\s+dex\\s+int\\s+fm\\s+soc\\s+b';
|
||||
const carac_val = '(?<m>[0-9\\-]+)\\s+(?<ws>[0-9\\-]+)\\s+(?<bs>[0-9\\-]+)\\s+(?<s>[0-9\\-]+)\\s+(?<t>[0-9\\-]+)\\s+(?<i>[0-9\\-]+)\\s+(?<ag>[0-9\\-]+)\\s+(?<dex>[0-9\\-]+)\\s+(?<int>[0-9\\-]+)\\s+(?<wp>[0-9\\-]+)\\s+(?<fel>[0-9\\-]+)\\s+(?<w>[0-9\\-\*]+)';
|
||||
const name_val = '(?<name>[a-zA-Z\\s\\-,]*)[\\s\\r\\na-zA-Z]*(?<tiers>.*|[\\(\\)a-z0-9]+)';
|
||||
let sectionData = [
|
||||
let sectionDataFR = [
|
||||
{ name: "trait", toFind: "Traits\\s*:", secondParse: '(?<name>[a-zàéè\\s]*)[\\s\\+]*(?<value>.*|[\\+0-9]+)', index: -1 },
|
||||
{ name: "skill", toFind: "Compétences\\s*:", secondParse: '(?<name>[a-zàéè\\s\\(\\)]*)[\\s\\+]*(?<value>.*|[0-9]+)', index: -1 },
|
||||
{ name: "talent", toFind: "Talents\\s*:", secondParse: '(?<name>[a-zàéè\\-\\s!/]*)[\\s\\+]*(?<value>.*|[0-9]+)', index: -1 },
|
||||
{ name: "mutation", toFind: "Mutations\\s*:", secondParse: '(?<name>[a-zàéè\\s]*)[\\s\\+]*(?<value>.*|[0-9]+)', index: -1 },
|
||||
{ name: "trapping", toFind: "Equiement\\s*:", secondParse: '(?<name>[a-zàéè\\s]*)[\\s\\+]*(?<value>.*|[0-9]+)', index: -1 }
|
||||
];
|
||||
let sectionDataUS = [
|
||||
{ name: "trait", toFind: "Traits\\s*:", secondParse: '(?<name>[a-z\\s]*)[\\s\\+]*(?<value>.*|[\\+0-9]+)', index: -1 },
|
||||
{ name: "skill", toFind: "Skills\\s*:", secondParse: '(?<name>[a-z\\s\\(\\)]*)[\\s\\+]*(?<value>.*|[0-9]+)', index: -1 },
|
||||
{ name: "talent", toFind: "Talents\\s*:", secondParse: '(?<name>[a-z\\-\\s!/]*)[\\s\\+]*(?<value>.*|[0-9]+)', index: -1 },
|
||||
@ -156,8 +179,8 @@ async function __findTalent(talentName) {
|
||||
/************************************************************************************/
|
||||
function __patchName ( name) {
|
||||
if (name.toLowerCase == 'magic sense')
|
||||
name = 'Magical Sense';
|
||||
return name;
|
||||
name = 'Magical Sense'
|
||||
return name
|
||||
}
|
||||
|
||||
/************************************************************************************/
|
||||
@ -167,15 +190,24 @@ export default async function statParserFR(statString, type = "npc") {
|
||||
// Patch wront/strange carac value before processing
|
||||
statString = statString.replace(/ –/g, " 0")
|
||||
|
||||
let reg1 = XRegExp(us_carac, 'gi');
|
||||
let res = reg1.test(statString);
|
||||
let statNameReg = us_carac
|
||||
let sectionData = sectionDataUS
|
||||
// Detect French stat block
|
||||
if (statString.includes('CC') && statString.includes('CT') && statString.includes('FM')) {
|
||||
ui.notifications.warn("Le parsing de stablock en Français n'est pas encore prêt")
|
||||
statNameReg = fr_carac
|
||||
sectionData = sectionDataFR
|
||||
}
|
||||
|
||||
let reg1 = XRegExp(statNameReg, 'gi')
|
||||
let res = reg1.test(statString)
|
||||
if (res) { //stat block identified go on
|
||||
// Extract the name
|
||||
let res1 = XRegExp.exec(statString, reg1);
|
||||
console.log("REG", res1);
|
||||
let pnjStr = statString.substring(0, res1.index);
|
||||
let nameRes = XRegExp.exec(pnjStr, regName);
|
||||
console.log(nameRes);
|
||||
let res1 = XRegExp.exec(statString, reg1)
|
||||
console.log("REG", res1)
|
||||
let pnjStr = statString.substring(0, res1.index)
|
||||
let nameRes = XRegExp.exec(pnjStr, regName)
|
||||
console.log(nameRes)
|
||||
if (nameRes.tiers && nameRes.tiers.length > 0 && hasProperty(model, "details.status.value")) {
|
||||
let regTiers = XRegExp("(?<name>[A-Za-z]*)\\s+(?<level>[0-9]*)");
|
||||
let resTiers = XRegExp.exec(nameRes.tiers, regTiers);
|
||||
@ -195,16 +227,16 @@ export default async function statParserFR(statString, type = "npc") {
|
||||
pnjName = pnjName.join(" ")
|
||||
|
||||
// Get the carac values
|
||||
let reg2 = XRegExp(carac_val, 'gi');
|
||||
let resCarac = XRegExp.exec(statString, reg2); // resr contains all carac found
|
||||
let reg2 = XRegExp(carac_val, 'gi')
|
||||
let resCarac = XRegExp.exec(statString, reg2) // resr contains all carac found
|
||||
|
||||
// Setup carac
|
||||
//console.log("CARAC", resCarac)
|
||||
if (resCarac["Agi"]) resCarac["Ag"] = resCarac["Agi"] // Auto patch
|
||||
model.details.move.value = Number(resCarac["m"]);
|
||||
model.details.move.value = Number(resCarac["m"])
|
||||
for (let key in model.characteristics) {
|
||||
if (resCarac[key] === '-') resCarac[key] = 0;
|
||||
model.characteristics[key].initial = Number(resCarac[key]);
|
||||
if (resCarac[key] === '-') resCarac[key] = 0
|
||||
model.characteristics[key].initial = Number(resCarac[key])
|
||||
}
|
||||
//console.log("CARAC", model.characteristics);
|
||||
|
||||
@ -223,12 +255,12 @@ export default async function statParserFR(statString, type = "npc") {
|
||||
for (let i = 0; i < sectionData.length; i++) {
|
||||
let def = sectionData[i];
|
||||
if (def.index > -1) {
|
||||
let maxIndex = statString.length;
|
||||
let maxIndex = statString.length
|
||||
if (sectionData[i + 1] && sectionData[i + 1].index > -1)
|
||||
maxIndex = sectionData[i + 1].index;
|
||||
def.substring = statString.substring(def.index, maxIndex);
|
||||
def.substring = XRegExp.replace(def.substring, def.regDef, "");
|
||||
def.substring = XRegExp.replace(def.substring, regLine1, " ");
|
||||
maxIndex = sectionData[i + 1].index
|
||||
def.substring = statString.substring(def.index, maxIndex)
|
||||
def.substring = XRegExp.replace(def.substring, def.regDef, "")
|
||||
def.substring = XRegExp.replace(def.substring, regLine1, " ")
|
||||
// At this point, def.substring contains the items list as a string
|
||||
|
||||
// Then create a table of it in termList, with specific sub-parsing rules
|
||||
@ -236,28 +268,30 @@ export default async function statParserFR(statString, type = "npc") {
|
||||
for (let name of termList) {
|
||||
let itemFound, subres, value;
|
||||
if (def.secondParse) {
|
||||
subres = XRegExp.exec(name, XRegExp(def.secondParse, 'gi'));
|
||||
name = subres.name.trim().replace("\n", "").replace("\r", "");
|
||||
value = XRegExp.replace(subres.value, "(", "");
|
||||
value = XRegExp.replace(subres.value, ")", "");
|
||||
subres = XRegExp.exec(name, XRegExp(def.secondParse, 'gi'))
|
||||
name = subres.name.trim().replace("\n", "").replace("\r", "")
|
||||
value = XRegExp.replace(subres.value, "(", "")
|
||||
value = XRegExp.replace(value, ")", "")
|
||||
}
|
||||
name = __patchName(name);
|
||||
name = __patchName(name)
|
||||
if (def.name == 'trait') {
|
||||
try {
|
||||
itemFound = await __findItem(name, "trait");
|
||||
itemFound = await __findItem(name, "trait")
|
||||
}
|
||||
catch { }
|
||||
if (itemFound)
|
||||
itemFound = itemFound.toObject();
|
||||
if (itemFound && subres && subres.value.length > 0) {
|
||||
if (name.toLowerCase == 'weapon') {
|
||||
itemFound.data.specification.value = Number(value) - Math.floor( Number(model.characteristics.s.initial) / 10);
|
||||
itemFound = itemFound.toObject()
|
||||
if (itemFound && value && value.length > 0) {
|
||||
if (name.toLowerCase() == 'weapon' || name.toLowerCase() == "bite" || name.toLowerCase() == "tail" ||
|
||||
name.toLowerCase() == 'arme' || name.toLowerCase() == "morsure" || name.toLowerCase() == "queue") {
|
||||
itemFound.data.specification.value = Number(value) - Math.floor( Number(model.characteristics.s.initial) / 10)
|
||||
} else {
|
||||
itemFound.data.specification.value = game.i18n.localize(value);
|
||||
itemFound.data.specification.value = game.i18n.localize(value)
|
||||
}
|
||||
}
|
||||
if (!itemFound)
|
||||
ui.notifications.error("Trait non trouvé, à ajouter manuellement : " + name, { permanent: true })
|
||||
|
||||
} else if (def.name == 'skill') {
|
||||
try {
|
||||
itemFound = await __findSkill(name, value);
|
||||
@ -324,11 +358,3 @@ export default async function statParserFR(statString, type = "npc") {
|
||||
ui.notifications.error("Impossible de convertir ces statitiques, les caractéristiques n'ont pas été trouvées", { permanent: true })
|
||||
}
|
||||
|
||||
/************************************************************************************/
|
||||
Hooks.once('ready', () => {
|
||||
|
||||
//var fullskills = game.packs.get('wfrp4e-core.skills');
|
||||
//console.log("Skills", game.wfrp4e.apps.StatBlockParser.prototype);
|
||||
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user