40 lines
1.6 KiB
JavaScript
40 lines
1.6 KiB
JavaScript
|
/* -------------------------------------------- */
|
||
|
|
||
|
import { HawkmoonUtility } from "./hawkmoon-utility.js";
|
||
|
import "./xregexp-all.js";
|
||
|
|
||
|
const __level1Expr = '(?<effectType>[a-z]+):(?<objectType>[a-zA-Z]+)\\((?<objectName>[a-zA-Z0-9\\.]+)\\)\\s+(?<modifierValue>[\\d]+)\\s*{*(?<modifierLabel>[a-zA-Zàéè\\s]*)}*'
|
||
|
const __effectTypes = {modifier: 1, cost: 1, provide: 1}
|
||
|
|
||
|
/* -------------------------------------------- */
|
||
|
export class HawkmoonEffectParser {
|
||
|
|
||
|
/* -------------------------------------------- */
|
||
|
static init() {
|
||
|
this.__objectTypes = { }
|
||
|
|
||
|
Object.entries(game.data.model.Actor).forEach(kv => {
|
||
|
this.__objectTypes[kv[0]] = duplicate(kv[1])
|
||
|
})
|
||
|
Object.entries(game.data.model.Item).forEach(kv => {
|
||
|
this.__objectTypes[kv[0]] = duplicate(kv[1])
|
||
|
})
|
||
|
}
|
||
|
|
||
|
/* -------------------------------------------- */
|
||
|
static parseEffectString(effectString) {
|
||
|
let parse1 = XRegExp.exec(effectString, XRegExp(__level1Expr, 'gi'))
|
||
|
if (parse1.effectType && __effectTypes[parse1.effectType.toLowerCase()]) {
|
||
|
parse1.effectType = parse1.effectType.toLowerCase()
|
||
|
if ( parse1.objectType && this.__objectTypes[parse1.objectType.toLowerCase()] ) {
|
||
|
parse1.objectType = parse1.objectType.toLowerCase()
|
||
|
console.log("Level 1 parsing : ", parse1, Object.keys(__effectTypes) )
|
||
|
} else {
|
||
|
ui.notifications.warn("EffectParser : Le type d'objet est inconnu. Les valeurs valides sont : " + Object.keys(this.__objectTypes).toString() )
|
||
|
}
|
||
|
} else {
|
||
|
ui.notifications.warn("EffectParser : Le type d'effet est inconnu. Les valeurs valides sont : " + Object.keys(__effectTypes).toString() )
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|