forked from public/foundryvtt-reve-de-dragon
		
	Amelioration parser
This commit is contained in:
		| @@ -227,6 +227,39 @@ export class RdDStatBlockParser { | |||||||
|     dialog.render(true); |     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") { |   static async parseStatBlock(statString, type = "npc") { | ||||||
|  |  | ||||||
|     //statString = statBlock03; |     //statString = statBlock03; | ||||||
| @@ -234,6 +267,9 @@ export class RdDStatBlockParser { | |||||||
|       return; |       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 |     // Replace all endline by space in the statString | ||||||
|     statString = statString.replace(/\n/g, " "); |     statString = statString.replace(/\n/g, " "); | ||||||
|     // Remove all multiple spaces |     // Remove all multiple spaces | ||||||
| @@ -311,6 +347,7 @@ export class RdDStatBlockParser { | |||||||
|     const weapons = await SystemCompendiums.getWorldOrCompendiumItems("arme", "equipement") |     const weapons = await SystemCompendiums.getWorldOrCompendiumItems("arme", "equipement") | ||||||
|     //console.log("Equipement : ", equipment); |     //console.log("Equipement : ", equipment); | ||||||
|     for (let w of weapons) { |     for (let w of weapons) { | ||||||
|  |        | ||||||
|       let weapon = XRegExp.exec(statString.toLowerCase(), XRegExp(w.name.toLowerCase()+"\\s+(?<value>\\+\\d+)", 'gi')); |       let weapon = XRegExp.exec(statString.toLowerCase(), XRegExp(w.name.toLowerCase()+"\\s+(?<value>\\+\\d+)", 'gi')); | ||||||
|       if (weapon) { |       if (weapon) { | ||||||
|         w.system.equipe = true |         w.system.equipe = true | ||||||
| @@ -377,7 +414,7 @@ export class RdDStatBlockParser { | |||||||
|     let name |     let name | ||||||
|     if (actorType == "personnage") { |     if (actorType == "personnage") { | ||||||
|       name = XRegExp.exec(statString.toLowerCase(), XRegExp("(?<value>[\\w\\s\\d]+),", 'gi')); |       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 = XRegExp.exec(statString.toLowerCase(), XRegExp("(?<value>.+)\\s+taille", 'gi')); | ||||||
|       } |       } | ||||||
|       name = name?.value || "Importé"; |       name = name?.value || "Importé"; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user