From 1c68c34641f6dee684bd254dff867564a68018c0 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Sat, 7 Dec 2024 22:58:02 +0100 Subject: [PATCH] =?UTF-8?q?Import=20des=20sorts=20en=20r=C3=A9serve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/apps/rdd-import-stats.js | 45 ++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/module/apps/rdd-import-stats.js b/module/apps/rdd-import-stats.js index b91c973b..b1a9f0be 100644 --- a/module/apps/rdd-import-stats.js +++ b/module/apps/rdd-import-stats.js @@ -33,16 +33,22 @@ const XREGEXP_WEAPON_MANIEMENT = "(?(" + Misc.join(Object.keys(MANIEM const XREGEXP_SORT_VOIE = "(?[OHNT](\\/[OHNT])*)" const XREGEXP_SORT_NAME = "(?[^\\(]+)" -const XREGEXP_SORT_CASE = "\\((?([A-Za-zÀ-ÖØ-öø-ÿ\\s\\-]+|[A-M]\\d{1,2})+)\\)"; +// const XREGEXP_SORT_CASE = "(?([A-Za-zÀ-ÖØ-öø-ÿ\\s\\-]+|[A-M]\\d{1,2})+)" +const XREGEXP_SORT_CASE = "(?([A-Za-zÀ-ÖØ-öø-ÿ\\s\\-]+|[A-M]\\d{1,2}))" const XREGEXP_SORT = "(" + XREGEXP_SORT_VOIE + WHITESPACES + XREGEXP_SORT_NAME - + WHITESPACES + XREGEXP_SORT_CASE + + WHITESPACES + "\\(" + XREGEXP_SORT_CASE + "\\)" + WHITESPACES + "R(?([\\-\\d]+|(\\w|\\s)+))" + WHITESPACES + "r(?(\\d+(\\+)?|\\s\\w+))" + "(" + WHITESPACES + "\\+(?\\d+)\\s?%" + WHITESPACES + "en" + WHITESPACES + "(?[A-M]\\d{1,2})" + ")?" + ")" +const XREGEXP_SORTRESERVE_CASE = "(?[A-M]\\d{1,2})"; + +const XREGEXP_SORT_RESERVE = XREGEXP_SORTRESERVE_CASE + + WHITESPACES + XREGEXP_SORT_NAME + + WHITESPACES + "(\\((?[^\\)]+)\\))?" // Main class for parsing a stat block export class RdDStatBlockParser { @@ -324,10 +330,10 @@ export class RdDStatBlockParser { XRegExp.forEach(statString, XRegExp(XREGEXP_SORT, 'gu' /* keep case sensitive to match the spell draconic skill */), function (matchSort, i) { + actorData.flags.hautRevant = true const sortName = Grammar.toLowerCaseNoAccent(matchSort.name).trim().replace("’", "'"); let sort = sorts.find(s => Grammar.toLowerCaseNoAccent(s.name) == sortName) if (sort) { - actorData.flags.hautRevant = true sort = sort.toObject(); if (matchSort.bonus && matchSort.bonuscase) { sort.system.bonuscase = `${matchSort.bonuscase}:${matchSort.bonus}`; @@ -337,7 +343,38 @@ export class RdDStatBlockParser { else { ui.notifications.warn(`Impossible de trouver le sort ${matchSort.name} / ${sortName}`) } - }); + }) + const sortsReserve = XRegExp.exec(statString, XRegExp('En réserve\\s+(?.*)', 'gu' /* keep case sensitive to match the spell draconic skill */)) + if (sortsReserve?.reserve) { + actorData.flags.hautRevant = true + XRegExp.forEach(sortsReserve.reserve, XRegExp(XREGEXP_SORT_RESERVE, 'giu'), + function (matchSortReserve, i) { + const name = Grammar.toLowerCaseNoAccent(matchSortReserve.name).trim().replace("’", "'"); + const sort = sorts.find(s => Grammar.toLowerCaseNoAccent(s.name) == name) + if (sort) { + if (!items.find(it => it._id == sort.id)) { + const nouveauSort = sort.toObject() + nouveauSort.system.bonuscase = `${matchSortReserve.coord}:1`; + items.push(sort.toObject()) + } + items.push({ + name: sort.name, + type: 'sortreserve', + img: sort.img, + system: { + sortid: sort.id, + draconic: sort.system.draconic, + coord: matchSortReserve.coord, + ptreve: Number(sort.system.ptreve.match(/\d+/)), + }, + description: matchSortReserve.description + }) + } + else { + ui.notifications.warn(`Impossible de mettre ${matchSortReserve.name} en réserve en ${matchSortReserve.coord}`) + } + }) + } if (actorData.flags.hautRevant) { const donHR = await RdDItemTete.teteDonDeHautReve();