Amelioration parser
This commit is contained in:
parent
97138b25c7
commit
025c3483a9
@ -227,6 +227,39 @@ export class RdDStatBlockParser {
|
||||
dialog.render(true);
|
||||
}
|
||||
|
||||
static fixWeirdPDF(statString) {
|
||||
// Split the statString into lines
|
||||
let lines = statString.split("\n");
|
||||
let newLines = [];
|
||||
let index = 0;
|
||||
let nextType = "string";
|
||||
// Loop through each line
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
// remove trailing spaces
|
||||
lines[i] = lines[i].trim();
|
||||
// Is it text ?
|
||||
if (lines[i].match(/^[a-zA-Zéêè\s]+/)) {
|
||||
if ( nextType == "string" ) {
|
||||
newLines[index] = lines[i];
|
||||
nextType = "number";
|
||||
} else {
|
||||
console.log("Wrong sequence string detected...", lines[i], nextType);
|
||||
}
|
||||
}
|
||||
// Is it a number ?
|
||||
if (lines[i].match(/^[\d\s]+/)) {
|
||||
if ( nextType == "number" ) {
|
||||
newLines[index] = newLines[index] + lines[i];
|
||||
nextType = "string";
|
||||
index++;
|
||||
} else {
|
||||
console.log("Wrong sequence number detected...", lines[i], nextType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static async parseStatBlock(statString, type = "npc") {
|
||||
|
||||
//statString = statBlock03;
|
||||
@ -234,6 +267,9 @@ export class RdDStatBlockParser {
|
||||
return;
|
||||
}
|
||||
|
||||
// Special function to fix strange/weird copy/paste from PDF readers
|
||||
// Unused up to now : this.fixWeirdPDF(statString);
|
||||
|
||||
// Replace all endline by space in the statString
|
||||
statString = statString.replace(/\n/g, " ");
|
||||
// Remove all multiple spaces
|
||||
@ -311,6 +347,7 @@ export class RdDStatBlockParser {
|
||||
const weapons = await SystemCompendiums.getWorldOrCompendiumItems("arme", "equipement")
|
||||
//console.log("Equipement : ", equipment);
|
||||
for (let w of weapons) {
|
||||
|
||||
let weapon = XRegExp.exec(statString.toLowerCase(), XRegExp(w.name.toLowerCase()+"\\s+(?<value>\\+\\d+)", 'gi'));
|
||||
if (weapon) {
|
||||
w.system.equipe = true
|
||||
@ -377,7 +414,7 @@ export class RdDStatBlockParser {
|
||||
let name
|
||||
if (actorType == "personnage") {
|
||||
name = XRegExp.exec(statString.toLowerCase(), XRegExp("(?<value>[\\w\\s\\d]+),", 'gi'));
|
||||
if (!name.value) {
|
||||
if (!name?.value) {
|
||||
name = XRegExp.exec(statString.toLowerCase(), XRegExp("(?<value>.+)\\s+taille", 'gi'));
|
||||
}
|
||||
name = name?.value || "Importé";
|
||||
|
Loading…
Reference in New Issue
Block a user