From 1f564e0d892bcbc673b7c909322785955e33f9a7 Mon Sep 17 00:00:00 2001
From: Vincent Vandemeulebrouck <vincent.vandeme@gmail.com>
Date: Tue, 17 Dec 2024 01:51:23 +0100
Subject: [PATCH] Meilleure extraction du nom
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

- cas des entités non incarnées
---
 module/apps/rdd-import-stats.js | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/module/apps/rdd-import-stats.js b/module/apps/rdd-import-stats.js
index cd109e4d..bb0b9509 100644
--- a/module/apps/rdd-import-stats.js
+++ b/module/apps/rdd-import-stats.js
@@ -491,21 +491,27 @@ export class RdDStatBlockParser {
   }
 
   static extractName(actorType, statString) {
-    switch (actorType) {
-      case "personnage":
-        // Check if ',né le' is present 
-        let namePersonnage = "Importé"
-        if (statString.includes(", né")) {
-          // Name is all string before first comma ','
-          namePersonnage = XRegExp.exec(statString, XRegExp("(?<value>[\\p{Letter}\\'\\-\\s\\d]+),", 'giu'));
-        } else {
-          namePersonnage = XRegExp.exec(statString, XRegExp("(?<value>[\\p{Letter}\\'\\-\\s\\d]+)\\s+TAILLE", 'giu'));
-        }
-        if (namePersonnage?.value) {
-          return Misc.upperFirst(namePersonnage?.value.toLowerCase());
-        }
+    if (actorType == "personnage") {
+      // Check if ',né le' is present 
+      let namePersonnage = "Importé"
+      if (statString.includes(", né")) {
+        // Name is all string before first comma ','
+        namePersonnage = XRegExp.exec(statString, XRegExp("(?<value>[\\p{Letter}\\'\\-\\s\\d]+),", 'giu'));
+      } else {
+        namePersonnage = XRegExp.exec(statString, XRegExp("(?<value>[\\p{Letter}\\'\\-\\s\\d]+)\\s+TAILLE", 'giu'));
+      }
+      if (namePersonnage?.value) {
+        return Misc.upperFirst(namePersonnage?.value.toLowerCase());
+      }
     }
+
     const name = XRegExp.exec(statString, XRegExp("(?<value>.+)\\s+taille", 'giu'));
+    if (actorType == "entite") {
+      if (!(name?.value)) {
+        const nameEntiteReve = XRegExp.exec(statString, XRegExp("(?<value>.+)\\s+rêve", 'giu'));
+        return Misc.upperFirst(nameEntiteReve?.value || "Importé");
+      }
+    }
     return Misc.upperFirst(name?.value || "Importé");
   }