@ -5,12 +5,12 @@ import { RdDBaseActorReve } from "../actor/base-actor-reve.js";
import { Grammar } from "../grammar.js" ;
import { Misc } from "../misc.js" ;
import { ENTITE _INCARNE , ENTITE _NONINCARNE } from "../constants.js" ;
import { RdDItemTete } from "../item/tete.js" ;
const WHITESPACES = "\\s+"
const NUMERIC = "[\\+\\-]?\\d+"
const NUMERIC _VALUE = "(?<value>" + NUMERIC + ")"
const XREGEXP _NAME = "(?<name>[A-Za-zÀ-ÖØ-öø-ÿ\\s\\-]+)"
const XREGEXP _COMP _CREATURE = WHITESPACES + "(?<carac>\\d+)"
+ WHITESPACES + NUMERIC _VALUE
+ "(" + WHITESPACES + "(?<init>\\d+)?\\s+?(?<dommages>[\\+\\-]?\\d+)?" + ")?"
@ -22,11 +22,12 @@ const compParser = {
entite : XREGEXP _COMP _CREATURE
}
const XREGEXP _SORT _VOIE = "[OHNT\\/]+"
const XREGEXP _SORT _VOIE = "(?<voies>[OHNT](\\/[OHNT])*)"
const XREGEXP _SORT _NAME = "(?<name>[^\\(]+)"
const XREGEXP _SORT _CASE = "\\((?<case>[A-Za-zÀ-ÖØ-öø-ÿ\\s\\-]+)\\)" ;
const XREGEXP _SORT = "(" + XREGEXP _SORT _VOIE
+ WHITESPACES + XREGEXP _ NAME
+ WHITESPACES + XREGEXP _ SORT_ NAME
+ WHITESPACES + XREGEXP _SORT _CASE
+ WHITESPACES + "R(?<diff>([\\-\\d]+|(\\w|\\s)+))"
+ WHITESPACES + "r(?<reve>(\\d+(\\+)?|\\s\\w+))"
@ -104,7 +105,7 @@ export class RdDStatBlockParser {
return "vaisseau" ;
}
static async parseStatBlock ( statString , type = "npc" ) {
static async parseStatBlock ( statString ) {
//statString = statBlock03;
if ( ! statString ) {
@ -122,10 +123,10 @@ export class RdDStatBlockParser {
statString = statString . trim ( ) ;
// TODO: check for entite
let ac torT ype = RdDStatBlockParser . parseActorType ( statString ) ;
let type = RdDStatBlockParser . parseActorType ( statString ) ;
// Now start carac
let actorData = foundry . utils . deepClone ( game . model . Actor [ ac torT ype] ) ;
let actorData = foundry . utils . deepClone ( game . model . Actor [ type] ) ;
for ( let key in actorData . carac ) {
let caracDef = actorData . carac [ key ] ;
// Parse the stat string for each caracteristic
@ -136,7 +137,7 @@ export class RdDStatBlockParser {
}
// If creature we need to setup additionnal fields
switch ( ac torT ype) {
switch ( type) {
case "creature" :
RdDStatBlockParser . parseCreature ( statString , actorData )
break
@ -147,14 +148,14 @@ export class RdDStatBlockParser {
let items = [ ] ;
// Get skills from compendium
const competences = await SystemCompendiums . getCompetences ( ac torT ype) ;
const competences = await SystemCompendiums . getCompetences ( type) ;
//console.log("Competences : ", competences);
for ( let comp of competences ) {
let compMatch = XRegExp . exec ( statString , XRegExp ( comp . name + compParser [ ac torT ype] , 'giu' ) ) ;
let compMatch = XRegExp . exec ( statString , XRegExp ( comp . name + compParser [ type] , 'giu' ) ) ;
if ( compMatch ) {
comp = comp . toObject ( )
comp . system . niveau = Number ( compMatch . value ) ;
if ( ac torT ype == "creature" || ac torT ype == "entite" ) {
if ( type == "creature" || type == "entite" ) {
comp . system . carac _value = Number ( compMatch . carac ) ;
if ( compMatch . dommages != undefined ) {
comp . system . dommages = Number ( compMatch . dommages ) ;
@ -163,7 +164,7 @@ export class RdDStatBlockParser {
}
items . push ( comp )
}
else if ( ac torT ype == "personnage" ) {
else if ( type == "personnage" ) {
comp = comp . toObject ( )
items . push ( comp )
}
@ -213,83 +214,103 @@ export class RdDStatBlockParser {
}
}
// Attemp to detect spell
let hautRevant = false
let sorts = await SystemCompendiums . getWorldOrCompendiumItems ( "sort" , "sorts-oniros" )
sorts = sorts . concat ( await SystemCompendiums . getWorldOrCompendiumItems ( "sort" , "sorts-hypnos" ) )
sorts = sorts . concat ( await SystemCompendiums . getWorldOrCompendiumItems ( "sort" , "sorts-narcos" ) )
sorts = sorts . concat ( await SystemCompendiums . getWorldOrCompendiumItems ( "sort" , "sorts-thanatos" ) )
XRegExp . forEach ( statString , XRegExp ( XREGEXP _SORT , 'giu' ) ,
if ( type == "personnage" ) {
await RdDStatBlockParser . parseHautReve ( statString , actorData , items ) ;
RdDStatBlockParser . parsePersonnage ( statString , actorData ) ;
}
let name = RdDStatBlockParser . extractName ( type , statString ) ;
let newActor = await RdDBaseActorReve . create ( { name , type : type , system : actorData , items } ) ;
await newActor . remiseANeuf ( )
// DUmp....
console . log ( actorData ) ;
}
static async parseHautReve ( statString , actorData , items ) {
let hautRevant = false ;
// Attemp to detect spell
let sorts = await SystemCompendiums . getWorldOrCompendiumItems ( "sort" , "sorts-oniros" ) ;
sorts = sorts . concat ( await SystemCompendiums . getWorldOrCompendiumItems ( "sort" , "sorts-hypnos" ) ) ;
sorts = sorts . concat ( await SystemCompendiums . getWorldOrCompendiumItems ( "sort" , "sorts-narcos" ) ) ;
sorts = sorts . concat ( await SystemCompendiums . getWorldOrCompendiumItems ( "sort" , "sorts-thanatos" ) ) ;
XRegExp . forEach ( statString , XRegExp ( XREGEXP _SORT , 'gu' /* keep case sensitive to match the spell draconic skill */ ) ,
function ( matchSort , i ) {
let sort = sorts . find ( s => Grammar . equalsInsensitive ( s . name , matchSort . name ) )
const sortName = Grammar . toLowerCaseNoAccent ( matchSort . name ) . trim ( ) . replace ( "’ " , "'" ) ;
let sort = sorts . find ( s => Grammar . toLowerCaseNoAccent ( s . name ) == sortName )
if ( sort ) {
hautRevant = true
hautRevant = true ;
sort = sort . toObject ( ) ;
if ( matchSort . bonus && matchSort . bonuscase ) {
sort . system . bonuscase = ` ${ matchSort . bonuscase } : ${ matchSort . bonus } `
sort . system . bonuscase = ` ${ matchSort . bonuscase } : ${ matchSort . bonus } ` ;
}
items . push ( sort ) ;
}
else {
ui . notifications . warn ( ` Impossible de trouver le sort ${ matchSort . name } / ${ sortName } ` )
console . warn ( ` Impossible de trouver le sort ${ matchSort . name } / ${ sortName } ` )
}
} ) ;
if ( hautRevant ) {
const donHR = await RdDItemTete . teteDonDeHautReve ( )
const donHR = await RdDItemTete . teteDonDeHautReve ( ) ;
if ( donHR ) {
items . push ( donHR . toObject ( ) ) ;
}
}
if ( actorType == "personnage" ) {
let feminin = XRegExp . exec ( statString , XRegExp ( "né(?<value>e?) à" , 'giu' ) ) ;
actorData . sexe = ( feminin ? . value == 'e' ) ? 'féminin' : 'masculin'
const demiReve = XRegExp . exec ( statString , XRegExp ( "Demi-rêve\\s+(?<value>[A-M]\\d{1,2})" , 'giu' ) )
actorData . reve . tmrpos . coord = demiReve ? . value ? ? 'A1'
}
}
static parsePersonnage ( statString , actorData ) {
actorData . reve . seuil . value = actorData . carac . reve . value
const reveActuel = XRegExp . exec ( statString , XRegExp ( "Rêve actuel\\s+(?<value>\\d+)" , 'giu' ) )
actorData . reve . reve . value = reveActuel ? . value ? Number ( reveActuel . value ) : actorData . reve . seuil . value
const feminin = XRegExp . exec ( statString , XRegExp ( "né(?<value>e?) à" , 'giu' ) ) ;
actorData . sexe = ( feminin ? . value == 'e' ) ? 'féminin' : 'masculin' ;
// Get hour name : heure du XXXXX
let heure = XRegExp . exec ( statString , XRegExp ( "heure (du|de la|des|de l\')\\s*(?<value>[A-Za-zÀ-ÖØ-öø-ÿ\\s]+)," , 'giu' ) ) ;
cons t heure = XRegExp . exec ( statString , XRegExp ( "heure (du|de la|des|de l\')\\s*(?<value>[A-Za-zÀ-ÖØ-öø-ÿ\\s]+)," , 'giu' ) ) ;
actorData . heure = this . getHeureKey ( heure ? . value || "Vaisseau" ) ;
// Get age
let age = XRegExp . exec ( statString , XRegExp ( "(?<value>\\d+) ans" , 'giu' ) ) ;
cons t age = XRegExp . exec ( statString , XRegExp ( "(?<value>\\d+) ans" , 'giu' ) ) ;
if ( age ? . value ) {
actorData . age = Number ( age . value ) ;
}
// Get height
le t taille = XRegExp . exec ( statString , XRegExp ( "(?<value>\\d+m\\d+)" , 'giu' ) ) ;
cons t taille = XRegExp . exec ( statString , XRegExp ( "(?<value>\\d+m\\d+)" , 'giu' ) ) ;
if ( taille ? . value ) {
actorData . taille = taille . value ;
}
// Get weight
le t poids = XRegExp . exec ( statString , XRegExp ( "(?<value>\\d+) kg" , 'giu' ) ) ;
cons t poids = XRegExp . exec ( statString , XRegExp ( "(?<value>\\d+) kg" , 'giu' ) ) ;
if ( poids ? . value ) {
actorData . poids = poids . value ;
}
// Get cheveux
le t cheveux = XRegExp . exec ( statString , XRegExp ( "kg,\\s+(?<value>[A-Za-zÀ-ÖØ-öø-ÿ\\s\\-]+),\\s+yeux" , 'giu' ) ) ;
cons t cheveux = XRegExp . exec ( statString , XRegExp ( "kg,\\s+(?<value>[A-Za-zÀ-ÖØ-öø-ÿ\\s\\-]+),\\s+yeux" , 'giu' ) ) ;
if ( cheveux ? . value ) {
actorData . cheveux = cheveux . value ;
}
// Get yeux
le t yeux = XRegExp . exec ( statString , XRegExp ( "yeux\\s+(?<value>[A-Za-zÀ-ÖØ-öø-ÿ\\s\\-]+), Beau" , 'giu' ) ) ;
cons t yeux = XRegExp . exec ( statString , XRegExp ( "yeux\\s+(?<value>[A-Za-zÀ-ÖØ-öø-ÿ\\s\\-]+), Beau" , 'giu' ) ) ;
if ( yeux ? . value ) {
actorData . yeux = yeux . value ;
}
// Get beauty
le t beaute = XRegExp . exec ( statString , XRegExp ( "beauté\\s+(?<value>\\d+)" , 'giu' ) ) ;
cons t beaute = XRegExp . exec ( statString , XRegExp ( "beauté\\s+(?<value>\\d+)" , 'giu' ) ) ;
if ( beaute ? . value ) {
actorData . beaute = Number ( beaute . value ) ;
}
}
// Name is all string before ', né'
let name = RdDStatBlockParser . extractName ( actorType , statString ) ;
let newActor = RdDBaseActorReve . create ( { name : name || "Importé" , type : actorType , system : actorData , items : items } ) ;
// DUmp....
console . log ( actorData ) ;
}
static parseCreature ( statString , actorData ) {
let plusDom = XRegExp . exec ( statString , XRegExp ( "\\+dom\\s+(?<value>[\\+\\-]?\\d+)" , 'giu' ) ) ;
if ( plusDom ? . values ) {
@ -349,24 +370,17 @@ export class RdDStatBlockParser {
static extractName ( actorType , statString ) {
switch ( actorType ) {
case "personnage" : return RdDStatBlockParser . extractNamePersonnage ( statString ) ;
case "creature" : return RdDStatBlockParser . extractNameCreature ( statString ) ;
case "personnage" :
// Name is all string before first comma ','
const namePersonnage = XRegExp . exec ( statString , XRegExp ( "(?<value>[\\p{Letter}\\s\\d]+)," , 'giu' ) ) ;
if ( namePersonnage ? . value ) {
return Misc . upperFirst ( namePersonnage ? . value ) ;
}
return RdDStatBlockParser . extractNameCreature ( statString ) ;
}
static extractNamePersonnage ( statString ) {
let name = XRegExp . exec ( statString , XRegExp ( "(?<value>[\\p{Letter}\\s\\d]+)," , 'giu' ) ) ;
if ( ! name ? . value ) {
name = XRegExp . exec ( statString , XRegExp ( "(?<value>.+)\\s+taille" , 'giu' ) ) ;
}
return Misc . upperFirst ( name ? . value || "Importé" ) ;
}
static extractNameCreature ( statString ) {
const name = XRegExp . exec ( statString , XRegExp ( "(?<value>.+)\\s+taille" , 'giu' ) ) ;
return Misc . upperFirst ( name ? . value || "Importé" ) ;
}
}
/************************************************************************************/