SYnc
This commit is contained in:
parent
b3554bc089
commit
4c348fbc72
@ -1,5 +1,5 @@
|
||||
/************************************************************************************/
|
||||
import autoTranslateItems from "./modules/import-stat-2.js";
|
||||
import statParserFR from "./modules/import-stat-2.js";
|
||||
|
||||
/************************************************************************************/
|
||||
var compmod = "wfrp4e";
|
||||
@ -15,6 +15,10 @@ Hooks.once('init', () => {
|
||||
} );
|
||||
game.wfrp4efr = { compmod: compmod };
|
||||
|
||||
game.wfrp4e.apps.StatBlockParser.parseStatBlock = async function( statString, type = "npc") {
|
||||
return statParserFR( statString, type);
|
||||
}
|
||||
|
||||
//WFRP_Tables = game.wfrp4e.tables;
|
||||
//WFRP4E = game.wfrp4e.config;
|
||||
//CONFIG.Actor.entityClass = ActorWfrp4e_fr;
|
||||
@ -226,8 +230,119 @@ Hooks.once('init', () => {
|
||||
}
|
||||
return chars;
|
||||
},
|
||||
"bestiary_traits": (beast_traits, translations) => {
|
||||
return autoTranslateItems(beast_traits, translations );
|
||||
"bestiary_traits": (beast_traits, translations) => {
|
||||
var fulltraits = game.packs.get(compmod+'.traits');
|
||||
var fullskills = game.packs.get(compmod+'.skills');
|
||||
var fulltalents = game.packs.get(compmod+'.talents');
|
||||
var fullcareers = game.packs.get(compmod+'.careers');
|
||||
var fulltrappings = game.packs.get(compmod+'.trappings');
|
||||
var fullspells = game.packs.get(compmod+'.spells');
|
||||
var fullprayers = game.packs.get(compmod+'.prayers');
|
||||
var eisitems = game.packs.get('eis.eisitems');
|
||||
var eisspells = game.packs.get('eis.eisspells');
|
||||
var ugtalents = game.packs.get('wfrp4e-unofficial-grimoire.ug-careerstalentstraits');
|
||||
var ugspells = game.packs.get('wfrp4e-unofficial-grimoire.ug-spells');
|
||||
//console.log("Comp :", compmod, fulltraits);
|
||||
|
||||
for (let trait_en of beast_traits)
|
||||
{
|
||||
var special = "";
|
||||
var nbt = "";
|
||||
var name_en = trait_en.name.trim(); // strip \r in some traits name
|
||||
|
||||
if ( trait_en.type == "trait") {
|
||||
if ( name_en.includes("Tentacles") ) { // Process specific Tentacles case
|
||||
var re = /(.d*)x Tentacles/i;
|
||||
var res = re.exec( name_en );
|
||||
if ( res && res[1] )
|
||||
nbt = res[1] + "x ";
|
||||
name_en = "Tentacles";
|
||||
} else if ( name_en.includes("(") && name_en.includes(")") ) { // Then process specific traits name with (xxxx) inside
|
||||
var re = /(.*) \((.*)\)/i;
|
||||
var res = re.exec( name_en );
|
||||
name_en = res[1]; // Get the root traits name
|
||||
special = " (" + game.i18n.localize( res[2].trim() ) + ")"; // And the special keyword
|
||||
}
|
||||
var trait_fr = fulltraits.translate( { name: name_en } );
|
||||
//console.log(">>>>> Trait ?", name_en, nbt, trait_fr.name, special);
|
||||
trait_en.name = nbt + trait_fr.name + special;
|
||||
if ( trait_fr.data && trait_fr.data.description && trait_fr.data.description.value ) {
|
||||
trait_en.data.description.value = trait_fr.data.description.value;
|
||||
} else if ( eisitems ) { // No description in the FR compendium -> test other compendium if presenr
|
||||
trait_fr = eisitems.translate( { name: name_en } );
|
||||
trait_en.name = nbt + trait_fr.name + special;
|
||||
if ( trait_fr.data && trait_fr.data.description && trait_fr.data.description.value )
|
||||
trait_en.data.description.value = trait_fr.data.description.value;
|
||||
}
|
||||
if ( trait_en.data && trait_en.data.specification && isNaN(trait_en.data.specification.value) ) { // This is a string, so translate it
|
||||
//console.log("Translating : ", trait_en.data.specification.value);
|
||||
trait_en.data.specification.value = game.i18n.localize( trait_en.data.specification.value.trim() );
|
||||
}
|
||||
} else if ( trait_en.type == "skill") {
|
||||
if ( name_en.includes("(") && name_en.includes(")") ) { // Then process specific skills name with (xxxx) inside
|
||||
var re = /(.*) +\((.*)\)/i;
|
||||
var res = re.exec( name_en );
|
||||
name_en = res[1].trim(); // Get the root skill name
|
||||
special = " (" + game.i18n.localize( res[2].trim() ) + ")"; // And the special keyword
|
||||
}
|
||||
var trait_fr = fullskills.translate( { name: name_en } );
|
||||
//console.log(">>>>> Skill ?", name_en, special, trait_fr.name, trait_fr);
|
||||
if (trait_fr.translated) {
|
||||
trait_en.name = trait_fr.name + special;
|
||||
if ( trait_fr.data ) {
|
||||
trait_en.data.description.value = trait_fr.data.description.value;
|
||||
}
|
||||
}
|
||||
} else if ( trait_en.type == "prayer") {
|
||||
var trait_fr = fullprayers.translate( { name: name_en } );
|
||||
//console.log(">>>>> Prayer ?", name_en, special, trait_fr.name );
|
||||
trait_en.name = trait_fr.name + special;
|
||||
if ( trait_fr.data && trait_fr.data.description && trait_fr.data.description.value )
|
||||
trait_en.data.description.value = trait_fr.data.description.value;
|
||||
} else if ( trait_en.type == "spell") {
|
||||
var trait_fr = fullspells.translate( { name: name_en } );
|
||||
if ( (!trait_fr.data || !trait_fr.data.description || !trait_fr.data.description.value) && eisspells) { // If no translation, test eisspells
|
||||
trait_fr = eisspells.translate( { name: name_en } );
|
||||
}
|
||||
if ( (!trait_fr.data || !trait_fr.data.description || !trait_fr.data.description.value) && ugspells) { // If no translation, test eisspells
|
||||
trait_fr = ugspells.translate( { name: name_en } );
|
||||
}
|
||||
//console.log(">>>>> Spell ?", name_en, special, trait_fr.name );
|
||||
trait_en.name = trait_fr.name + special;
|
||||
if ( trait_fr.data && trait_fr.data.description && trait_fr.data.description.value )
|
||||
trait_en.data.description.value = trait_fr.data.description.value;
|
||||
} else if ( trait_en.type == "talent") {
|
||||
if ( name_en.includes("(") && name_en.includes(")") ) { // Then process specific skills name with (xxxx) inside
|
||||
var re = /(.*) +\((.*)\)/i;
|
||||
var res = re.exec( name_en );
|
||||
name_en = res[1].trim(); // Get the root talent name, no parenthesis this time...
|
||||
special = " (" + game.i18n.localize( res[2].trim() ) + ")"; // And the special keyword
|
||||
}
|
||||
var trait_fr = fulltalents.translate( { name: name_en } );
|
||||
//console.log(">>>>> Talent ?", name_en, special, trait_fr.name);
|
||||
if ( (!trait_fr.data || !trait_fr.data.description || !trait_fr.data.description.value) && ugtalents) { // If no translation, test ugtalents
|
||||
trait_fr = ugtalents.translate( { name: name_en } );
|
||||
}
|
||||
if ( trait_fr.translated) {
|
||||
trait_en.name = trait_fr.name + special;
|
||||
if ( trait_fr.data ) { // Why ???
|
||||
trait_en.data.description.value = trait_fr.data.description.value;
|
||||
}
|
||||
}
|
||||
} else if ( trait_en.type == "career") {
|
||||
var career_fr = fullcareers.translate( trait_en );
|
||||
//console.log(">>>>> Career ?", name_en, career_fr.name);
|
||||
trait_en = career_fr;
|
||||
} else if ( trait_en.type == "trapping" || trait_en.type == "weapon" || trait_en.type == "armour" || trait_en.type == "container" || trait_en.type == "money") {
|
||||
var trapping_fr = fulltrappings.translate( trait_en );
|
||||
//console.log(">>>>> Trapping ?", name_en, trapping_fr.name);
|
||||
trait_en.name = trapping_fr.name;
|
||||
if ( trapping_fr.data) {
|
||||
trait_en.data.description = trapping_fr.data.description;
|
||||
}
|
||||
}
|
||||
}
|
||||
return beast_traits;
|
||||
},
|
||||
// To avoid duplicateing class for all careers
|
||||
"generic_localization": (value) => {
|
||||
@ -269,7 +384,10 @@ Hooks.once('init', () => {
|
||||
}
|
||||
// Per default
|
||||
var compendium = game.packs.find(p => p.collection === compmod+'.careers');
|
||||
return compendium.i18nName( { name: value } );
|
||||
if ( compendium )
|
||||
return compendium.i18nName( { name: value } );
|
||||
else
|
||||
ui.notifications.error("Impossible de trouver la carrière " + value + ". Elle n'est probablement pas traduite.", { permanent: true })
|
||||
},
|
||||
"mutations_modifier": (value) => { // This is really UGLYYYY i know, but i started like this and discovered afterward that many strings were not easy to automate... Sorry :)
|
||||
//console.log("Parsing mutation :", value);
|
||||
|
5
fr.json
5
fr.json
@ -793,6 +793,9 @@
|
||||
"Silver": "Argent",
|
||||
"Gold": "Or",
|
||||
"Brass": "Bronze",
|
||||
"SILVER": "Argent",
|
||||
"GOLD": "Or",
|
||||
"BRASS": "Bronze",
|
||||
|
||||
"Academics": "Lettrés",
|
||||
"Academic": "Lettré",
|
||||
@ -850,8 +853,6 @@
|
||||
"Mount": "Monté",
|
||||
"War": "Guerre",
|
||||
|
||||
"AP": "PA",
|
||||
"yards": "mètres",
|
||||
"yds": "m.",
|
||||
"Very Easy (+60)" : "Très facile (+60)",
|
||||
"Easy (+40)": "Facile (+40)",
|
||||
|
@ -3,7 +3,7 @@
|
||||
"name": "WH4-fr-translation",
|
||||
"title": "Traduction du module WH4 en Français.",
|
||||
"description": "La traduction du module WH4.",
|
||||
"version": "1.3.17",
|
||||
"version": "1.3.18",
|
||||
"minimumCoreVersion" : "0.6.6",
|
||||
"compatibleCoreVersion": "1.0.0",
|
||||
"author": "LeRatierBretonnien",
|
||||
|
@ -1,123 +1,5 @@
|
||||
/************************************************************************************/
|
||||
export default function autoTranslateItems(beast_traits, translations) {
|
||||
|
||||
let compmod = game.wfrp4efr.compmod;
|
||||
|
||||
var fulltraits = game.packs.get(compmod+'.traits');
|
||||
var fullskills = game.packs.get(compmod+'.skills');
|
||||
var fulltalents = game.packs.get(compmod+'.talents');
|
||||
var fullcareers = game.packs.get(compmod+'.careers');
|
||||
var fulltrappings = game.packs.get(compmod+'.trappings');
|
||||
var fullspells = game.packs.get(compmod+'.spells');
|
||||
var fullprayers = game.packs.get(compmod+'.prayers');
|
||||
var eisitems = game.packs.get('eis.eisitems');
|
||||
var eisspells = game.packs.get('eis.eisspells');
|
||||
var ugtalents = game.packs.get('wfrp4e-unofficial-grimoire.ug-careerstalentstraits');
|
||||
var ugspells = game.packs.get('wfrp4e-unofficial-grimoire.ug-spells');
|
||||
//console.log("Comp :", compmod, fulltraits);
|
||||
|
||||
for (let trait_en of beast_traits)
|
||||
{
|
||||
var special = "";
|
||||
var nbt = "";
|
||||
var name_en = trait_en.name.trim(); // strip \r in some traits name
|
||||
|
||||
if ( trait_en.type == "trait") {
|
||||
if ( name_en.includes("Tentacles") ) { // Process specific Tentacles case
|
||||
var re = /(.d*)x Tentacles/i;
|
||||
var res = re.exec( name_en );
|
||||
if ( res && res[1] )
|
||||
nbt = res[1] + "x ";
|
||||
name_en = "Tentacles";
|
||||
} else if ( name_en.includes("(") && name_en.includes(")") ) { // Then process specific traits name with (xxxx) inside
|
||||
var re = /(.*) \((.*)\)/i;
|
||||
var res = re.exec( name_en );
|
||||
name_en = res[1]; // Get the root traits name
|
||||
special = " (" + game.i18n.localize( res[2].trim() ) + ")"; // And the special keyword
|
||||
}
|
||||
var trait_fr = fulltraits.translate( { name: name_en } );
|
||||
//console.log(">>>>> Trait ?", name_en, nbt, trait_fr.name, special);
|
||||
trait_en.name = nbt + trait_fr.name + special;
|
||||
if ( trait_fr.data && trait_fr.data.description && trait_fr.data.description.value ) {
|
||||
trait_en.data.description.value = trait_fr.data.description.value;
|
||||
} else if ( eisitems ) { // No description in the FR compendium -> test other compendium if presenr
|
||||
trait_fr = eisitems.translate( { name: name_en } );
|
||||
trait_en.name = nbt + trait_fr.name + special;
|
||||
if ( trait_fr.data && trait_fr.data.description && trait_fr.data.description.value )
|
||||
trait_en.data.description.value = trait_fr.data.description.value;
|
||||
}
|
||||
if ( trait_en.data && trait_en.data.specification && isNaN(trait_en.data.specification.value) ) { // This is a string, so translate it
|
||||
//console.log("Translating : ", trait_en.data.specification.value);
|
||||
trait_en.data.specification.value = game.i18n.localize( trait_en.data.specification.value.trim() );
|
||||
}
|
||||
} else if ( trait_en.type == "skill") {
|
||||
if ( name_en.includes("(") && name_en.includes(")") ) { // Then process specific skills name with (xxxx) inside
|
||||
var re = /(.*) +\((.*)\)/i;
|
||||
var res = re.exec( name_en );
|
||||
name_en = res[1].trim(); // Get the root skill name
|
||||
special = " (" + game.i18n.localize( res[2].trim() ) + ")"; // And the special keyword
|
||||
}
|
||||
var trait_fr = fullskills.translate( { name: name_en } );
|
||||
//console.log(">>>>> Skill ?", name_en, special, trait_fr.name, trait_fr);
|
||||
if (trait_fr.translated) {
|
||||
trait_en.name = trait_fr.name + special;
|
||||
if ( trait_fr.data ) {
|
||||
trait_en.data.description.value = trait_fr.data.description.value;
|
||||
}
|
||||
}
|
||||
} else if ( trait_en.type == "prayer") {
|
||||
var trait_fr = fullprayers.translate( { name: name_en } );
|
||||
//console.log(">>>>> Prayer ?", name_en, special, trait_fr.name );
|
||||
trait_en.name = trait_fr.name + special;
|
||||
if ( trait_fr.data && trait_fr.data.description && trait_fr.data.description.value )
|
||||
trait_en.data.description.value = trait_fr.data.description.value;
|
||||
} else if ( trait_en.type == "spell") {
|
||||
var trait_fr = fullspells.translate( { name: name_en } );
|
||||
if ( (!trait_fr.data || !trait_fr.data.description || !trait_fr.data.description.value) && eisspells) { // If no translation, test eisspells
|
||||
trait_fr = eisspells.translate( { name: name_en } );
|
||||
}
|
||||
if ( (!trait_fr.data || !trait_fr.data.description || !trait_fr.data.description.value) && ugspells) { // If no translation, test eisspells
|
||||
trait_fr = ugspells.translate( { name: name_en } );
|
||||
}
|
||||
//console.log(">>>>> Spell ?", name_en, special, trait_fr.name );
|
||||
trait_en.name = trait_fr.name + special;
|
||||
if ( trait_fr.data && trait_fr.data.description && trait_fr.data.description.value )
|
||||
trait_en.data.description.value = trait_fr.data.description.value;
|
||||
} else if ( trait_en.type == "talent") {
|
||||
if ( name_en.includes("(") && name_en.includes(")") ) { // Then process specific skills name with (xxxx) inside
|
||||
var re = /(.*) +\((.*)\)/i;
|
||||
var res = re.exec( name_en );
|
||||
name_en = res[1].trim(); // Get the root talent name, no parenthesis this time...
|
||||
special = " (" + game.i18n.localize( res[2].trim() ) + ")"; // And the special keyword
|
||||
}
|
||||
var trait_fr = fulltalents.translate( { name: name_en } );
|
||||
//console.log(">>>>> Talent ?", name_en, special, trait_fr.name);
|
||||
if ( (!trait_fr.data || !trait_fr.data.description || !trait_fr.data.description.value) && ugtalents) { // If no translation, test ugtalents
|
||||
trait_fr = ugtalents.translate( { name: name_en } );
|
||||
}
|
||||
if ( trait_fr.translated) {
|
||||
trait_en.name = trait_fr.name + special;
|
||||
if ( trait_fr.data ) { // Why ???
|
||||
trait_en.data.description.value = trait_fr.data.description.value;
|
||||
}
|
||||
}
|
||||
} else if ( trait_en.type == "career") {
|
||||
var career_fr = fullcareers.translate( trait_en );
|
||||
//console.log(">>>>> Career ?", name_en, career_fr.name);
|
||||
trait_en = career_fr;
|
||||
} else if ( trait_en.type == "trapping" || trait_en.type == "weapon" || trait_en.type == "armour" || trait_en.type == "container" || trait_en.type == "money") {
|
||||
var trapping_fr = fulltrappings.translate( trait_en );
|
||||
//console.log(">>>>> Trapping ?", name_en, trapping_fr.name);
|
||||
trait_en.name = trapping_fr.name;
|
||||
if ( trapping_fr.data) {
|
||||
trait_en.data.description = trapping_fr.data.description;
|
||||
}
|
||||
}
|
||||
}
|
||||
return beast_traits;
|
||||
}
|
||||
|
||||
/************************************************************************************/
|
||||
// Some internal test strings
|
||||
let str1 = `JABBERSLYTHE
|
||||
M WS BS S T I Agi Dex
|
||||
Int WP Fel W
|
||||
@ -146,77 +28,258 @@ Etiquette (Criminals, Doktor, Guilder)
|
||||
Trappings: Dagger, Hand Weapon (Sword)
|
||||
`
|
||||
|
||||
/************************************************************************************/
|
||||
import "./xregexp-all.js";
|
||||
const us_carac = 'm\\s+ws\\s+bs\\s+s\\s+t\\s+i\\s+agi?\\s+dex\\s+int\\s+\\wp\\s+fel\\s+w';
|
||||
const fr_carac = 'm\\s+ws\\s+bs\\s+s\\s+t\\s+i\\s+agi?\\s+dex\\s+int\\s+\\wp\\s+fel\\s+w';
|
||||
const carac_val = '(?<M>[0-9-]+)\\s+(?<WS>[0-9-]+)\\s+(?<BS>[0-9-]+)\\s+(?<S>[0-9-]+)\\s+(?<T>[0-9-]+)\\s+(?<I>[0-9-]+)\\s+(?<Ag>[0-9-]+)\\s+(?<Dex>[0-9-]+)\\s+(?<Int>[0-9-]+)\\s+(?<WP>[0-9-]+)\\s+(?<Soc>[0-9-]+)\\s+(?<W>[0-9-]+)';
|
||||
const carac_val = '(?<m>[0-9-]+)\\s+(?<ws>[0-9-]+)\\s+(?<bs>[0-9-]+)\\s+(?<s>[0-9-]+)\\s+(?<t>[0-9-]+)\\s+(?<i>[0-9-]+)\\s+(?<ag>[0-9-]+)\\s+(?<dex>[0-9-]+)\\s+(?<int>[0-9-]+)\\s+(?<wp>[0-9-]+)\\s+(?<fel>[0-9-]+)\\s+(?<w>[0-9-]+)';
|
||||
const name_val = '(?<name>[a-z\\s\\-]*)[\\s\\r\\n]*(?<tiers>.*|[\\(\\)a-z0-9]+)';
|
||||
let sectionData = [
|
||||
{ name: "trait", toFind:"Traits\\s*:", secondParse: '(?<name>[a-z\\s]*)[\\s\\+]*(?<value>.*|[0-9]+)', index:-1 },
|
||||
{ name: "skill", toFind:"Skills\\s*:", secondParse: '(?<name>[a-z\\s]*)[\\s\\+]*(?<value>.*|[0-9]+)', index:-1 },
|
||||
{ name: "talent", toFind:"Talents\\s*:", index:-1 },
|
||||
{ name: "trapping", toFind:"Trappings\\s*:", index:-1 }
|
||||
{ name: "talent", toFind:"Talents\\s*:", secondParse: '(?<name>[a-z\\s]*)[\\s\\+]*(?<value>.*|[0-9]+)', index:-1 },
|
||||
{ name: "trapping", toFind:"Trappings\\s*:", secondParse: '(?<name>[a-z\\s]*)[\\s\\+]*(?<value>.*|[0-9]+)', index:-1 }
|
||||
];
|
||||
let regSep = XRegExp('\\s*,\\s*', 'gi'); // Term separator, with auto trim
|
||||
let regLine1 = XRegExp('\\r|\\n|\\.', 'gi'); // Term separator, with auto trim
|
||||
let regName = XRegExp(name_val, 'gi');
|
||||
|
||||
/************************************************************************************/
|
||||
Hooks.once('ready', () => {
|
||||
async function __findItem(itemName, itemType, location = null) {
|
||||
itemName = itemName.trim();
|
||||
let items = game.items.entities.filter(i => i.type == itemType)
|
||||
|
||||
let t1 = "agi";
|
||||
let reg0 = XRegExp('agi?', 'gi');
|
||||
//console.log("PARSER pos 1: ", reg0.test( t1 ) );
|
||||
// Search imported items first
|
||||
for (let i of items) {
|
||||
if (i.name == itemName && i.type == itemType)
|
||||
return i;
|
||||
}
|
||||
let itemList
|
||||
|
||||
// find pack -> search pack -> return entity
|
||||
if (location) {
|
||||
let pack = game.packs.find(p => {
|
||||
location.split(".")[0] == p.metadata.package &&
|
||||
location.split(".")[1] == p.metadata.name
|
||||
})
|
||||
if (pack) {
|
||||
if (pack.translations[itemName]) {
|
||||
let translItemName = pack.translations[itemName].name;
|
||||
await pack.getIndex().then(index => itemList = index);
|
||||
let searchResult = itemList.find(t => t.name == translItemName)
|
||||
if (searchResult)
|
||||
return await pack.getEntity(searchResult._id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If all else fails, search each pack
|
||||
for (let p of game.packs.filter(p => p.metadata.tags && p.metadata.tags.includes(itemType))) {
|
||||
if (p.translations[itemName]) {
|
||||
let translItemName = p.translations[itemName].name;
|
||||
await p.getIndex().then(index => itemList = index);
|
||||
let searchResult = itemList.find(t => t.name == translItemName)
|
||||
if (searchResult)
|
||||
return await p.getEntity(searchResult._id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************************************/
|
||||
async function __findSkill(skillName) {
|
||||
skillName = skillName.trim();
|
||||
// First try world items
|
||||
let worldItem = game.items.entities.filter(i => i.type == "skill" && i.name == skillName)[0];
|
||||
if (worldItem) return worldItem
|
||||
|
||||
let skillList = [];
|
||||
let packs = game.packs.filter(p => p.metadata.tags && p.metadata.tags.includes("skill"))
|
||||
for (let pack of packs) {
|
||||
if ( pack.translations[skillName] ) {
|
||||
let translSkillName = pack.translations[skillName].name;
|
||||
skillList = await pack.getIndex()
|
||||
// Search for specific skill (won't find unlisted specializations)
|
||||
let searchResult = skillList.find(s => s.name == translSkillName)
|
||||
if (!searchResult)
|
||||
searchResult = skillList.find(s => s.name.split("(")[0].trim() == skillName.split("(")[0].trim())
|
||||
if (searchResult) {
|
||||
let dbSkill;
|
||||
await pack.getEntity(searchResult._id).then(packSkill => dbSkill = packSkill);
|
||||
dbSkill.data.name = translSkillName; // This is important if a specialized skill wasn't found. Without it, <Skill ()> would be added instead of <Skill (Specialization)>
|
||||
return dbSkill;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw "Could not find skill (or specialization of) " + skillName + " in compendum or world"
|
||||
}
|
||||
|
||||
/************************************************************************************/
|
||||
async function __findTalent(talentName) {
|
||||
talentName = talentName.trim();
|
||||
// First try world items
|
||||
let worldItem = game.items.entities.filter(i => i.type == "talent" && i.name == talentName)[0];
|
||||
if (worldItem) return worldItem
|
||||
|
||||
let talentList = [];
|
||||
let packs = game.packs.filter(p => p.metadata.tags && p.metadata.tags.includes("talent"))
|
||||
for (let pack of packs) {
|
||||
if ( pack.translations[talentName] ) {
|
||||
let translTalentName = pack.translations[talentName].name;
|
||||
talentList = await pack.getIndex()
|
||||
// Search for specific talent (won't find unlisted specializations)
|
||||
let searchResult = talentList.find(t => t.name == translTalentName)
|
||||
if (!searchResult)
|
||||
searchResult = talentList.find(t => t.name.split("(")[0].trim() == talentName.split("(")[0].trim())
|
||||
|
||||
if (searchResult) {
|
||||
let dbTalent;
|
||||
await pack.getEntity(searchResult._id).then(packTalent => dbTalent = packTalent);
|
||||
dbTalent.data.name = translTalentName; // This is important if a specialized talent wasn't found. Without it, <Talent ()> would be added instead of <Talent (Specialization)>
|
||||
return dbTalent;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw "Could not find talent (or specialization of) " + talentName + " in compendium or world"
|
||||
}
|
||||
|
||||
/************************************************************************************/
|
||||
export default async function statParserFR( statString, type = "npc") {
|
||||
let model = duplicate(game.system.model.Actor[type]);
|
||||
|
||||
let reg1 = XRegExp(us_carac, 'gi');
|
||||
let res = reg1.test(str);
|
||||
let res = reg1.test(statString);
|
||||
if (res) { //stat block identified go on
|
||||
// Extract the name
|
||||
let res1 = XRegExp.exec(statString, reg1);
|
||||
let pnjStr = statString.substring(0, res1.index);
|
||||
let nameRes = XRegExp.exec(pnjStr, regName );
|
||||
console.log(nameRes);
|
||||
if ( nameRes.tiers && nameRes.tiers.length > 0 && hasProperty(model, "details.status.value") ) {
|
||||
let regTiers = XRegExp("(?<name>[A-Za-z]*)\\s+(?<level>[0-9]*)");
|
||||
let resTiers = XRegExp.exec(nameRes.tiers, regTiers);
|
||||
console.log(resTiers);
|
||||
model.details.status.value = game.i18n.localize(resTiers.name.trim()) + " " + resTiers.level;
|
||||
}
|
||||
// Compute the PNJ name
|
||||
let pnjName = nameRes.name.split("—")[0].split(" ").filter(f => !!f);
|
||||
pnjName = pnjName.map(word => {
|
||||
if (word == "VON")
|
||||
return word.toLowerCase();
|
||||
|
||||
word = word.toLowerCase();
|
||||
word = word[0].toUpperCase() + word.substring(1, word.length);
|
||||
return word;
|
||||
})
|
||||
pnjName = pnjName.join(" ")
|
||||
|
||||
// Get the carac values
|
||||
let reg2 = XRegExp(carac_val, 'gi');
|
||||
let res = XRegExp.exec(str, reg2);
|
||||
console.log("Movement is : ", res);
|
||||
let resCarac = XRegExp.exec(statString, reg2); // resr contains all carac found
|
||||
|
||||
// Setup carac
|
||||
if (resCarac["Agi"]) resCarac["Ag"] = resCarac["Agi"]; // Auto patch
|
||||
model.details.move.value = Number(resCarac["m"]);
|
||||
for (let key in model.characteristics) {
|
||||
if (resCarac[key] === '-') resCarac[key] = 0;
|
||||
model.characteristics[key].initial = Number(resCarac[key]);
|
||||
}
|
||||
//console.log("CARAC", model.characteristics);
|
||||
|
||||
// Search position of skills/talents/...
|
||||
for( let def of sectionData ) {
|
||||
def.regDef = XRegExp(def.toFind, 'gi');
|
||||
let res = XRegExp.exec(str, def.regDef);
|
||||
let res = XRegExp.exec(statString, def.regDef);
|
||||
if (res ) def.index = res.index; // Get the index in the string
|
||||
//console.log(" Parsing", def.name, res);
|
||||
}
|
||||
// Sort to split position of various substring
|
||||
sectionData.sort( function(a, b) { return a.index - b.index; } );
|
||||
// Loop again to extract
|
||||
|
||||
let globalItemList = [];
|
||||
// Then loop again and process each item type
|
||||
for(let i=0; i< sectionData.length; i++ ) {
|
||||
let def = sectionData[i];
|
||||
if ( def.index > -1) {
|
||||
let maxIndex = str.length;
|
||||
let maxIndex = statString.length;
|
||||
if ( sectionData[i+1] && sectionData[i+1].index > -1 )
|
||||
maxIndex = sectionData[i+1].index;
|
||||
def.substring = str.substring(def.index, maxIndex);
|
||||
def.substring = statString.substring(def.index, maxIndex);
|
||||
def.substring = XRegExp.replace(def.substring, def.regDef, "");
|
||||
def.substring = XRegExp.replace(def.substring, regLine1, " ");
|
||||
console.log("Substring :", def.substring);
|
||||
// At this point, def.substring contains the items list as a string
|
||||
|
||||
// Then create a table of it in termList, with specific sub-parsing rules
|
||||
let termList = XRegExp.split(def.substring, regSep);
|
||||
def.termList = [];
|
||||
for (let name of termList) {
|
||||
let itemFound, subres;
|
||||
if (def.secondParse) {
|
||||
let subres = XRegExp.exec( name, XRegExp(def.secondParse, 'gi') );
|
||||
console.log("Subres", subres);
|
||||
subres = XRegExp.exec( name, XRegExp(def.secondParse, 'gi') );
|
||||
name = subres.name.trim();
|
||||
if ( def.name == 'trait') {
|
||||
if ( subres.value.length > 0 ) {
|
||||
if ( subres.value.substring(0, 1) == '(' )
|
||||
name += ' ' + subres.value;
|
||||
else
|
||||
name += ' (' + subres.value + ')';
|
||||
}
|
||||
} else if ( def.name == 'skill') {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
def.termList.push( { name: name, type: def.name, data: { description: { value: "" } } } );
|
||||
if ( def.name == 'trait') {
|
||||
try {
|
||||
itemFound = await __findItem(name, "trait");
|
||||
}
|
||||
catch {}
|
||||
if ( itemFound && subres && subres.value.length > 0 ) {
|
||||
subres.value = XRegExp.replace(subres.value, "(", "");
|
||||
subres.value = XRegExp.replace(subres.value, ")", "");
|
||||
itemFound.data.data.specification.value = game.i18n.localize( subres.value);
|
||||
}
|
||||
if (!itemFound)
|
||||
ui.notifications.error("Trait non trouvé, à ajouter manuellemen : " + name, { permanent: true })
|
||||
} else if ( def.name == 'skill') {
|
||||
try {
|
||||
itemFound = await __findSkill(name);
|
||||
}
|
||||
catch {}
|
||||
if ( itemFound && subres && subres.value) {
|
||||
itemFound.data.data.advances.value = Number(subres.value) - Number(resCarac[itemFound.data.data.characteristic.value]);
|
||||
}
|
||||
if (!itemFound)
|
||||
ui.notifications.error("Compétence non trouvée, à ajouter manuellement : " + name, { permanent: true })
|
||||
} else if (def.name == 'talent') {
|
||||
try {
|
||||
itemFound = await __findTalent(name);
|
||||
}
|
||||
catch {}
|
||||
if ( itemFound && subres && subres.value)
|
||||
itemFound.data.data.advances.value = Number(subres.value);
|
||||
if (!itemFound)
|
||||
ui.notifications.error("Talent non trouvé, à ajouter manuellement : " + name, { permanent: true })
|
||||
} else if (def.name == 'trapping') {
|
||||
try {
|
||||
itemFound = await __findItem(name, "trapping");
|
||||
}
|
||||
catch {}
|
||||
if (!itemFound) {
|
||||
itemFound = new game.wfrp4e.entities.ItemWfrp4e({ img: "systems/wfrp4e/icons/blank.png", name: name, type: "trapping", data: game.system.model.Item.trapping })
|
||||
itemFound.data.data.trappingType.value = "misc"
|
||||
}
|
||||
}
|
||||
if (itemFound)
|
||||
globalItemList.push( itemFound );
|
||||
}
|
||||
def.itemList = autoTranslateItems( def.termList );
|
||||
console.log(def.itemList);
|
||||
}
|
||||
}
|
||||
let moneyItems = await game.wfrp4e.utility.allMoneyItems() || [];
|
||||
moneyItems = moneyItems.sort((a, b) => (a.data.coinValue.value > b.data.coinValue.value) ? -1 : 1);
|
||||
moneyItems.forEach(m => m.data.quantity.value = 0)
|
||||
globalItemList = globalItemList.concat(moneyItems);
|
||||
//console.log("My liste :", globalItemList);
|
||||
let name = pnjName;
|
||||
return { name, type, data: model, items: globalItemList }
|
||||
}
|
||||
//Do we have Traits ?
|
||||
|
||||
// If the carac string has not been found
|
||||
ui.notifications.error("Impossible de convertir ces statitiques, les caractéristiques n'ont pas été trouvées", { permanent: true } )
|
||||
}
|
||||
|
||||
/************************************************************************************/
|
||||
Hooks.once('ready', () => {
|
||||
|
||||
//var fullskills = game.packs.get('wfrp4e-core.skills');
|
||||
//console.log("Skills", game.wfrp4e.apps.StatBlockParser.prototype);
|
||||
|
||||
} )
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user