Fix char import
This commit is contained in:
parent
4bf5b4ec0f
commit
31ef890408
@ -380,7 +380,7 @@ Hooks.once('init', () => {
|
||||
"trapping_qualities_flaws": (value) => {
|
||||
if ( value ) {
|
||||
let newQF = [];
|
||||
console.log("ATOUTS", value);
|
||||
//console.log("ATOUTS", value);
|
||||
var i=0;
|
||||
//var re = /(.*) (\d+)/i;
|
||||
for (i=0; i<value.length; i++) {
|
||||
|
@ -2,7 +2,7 @@
|
||||
"name": "WH4-fr-translation",
|
||||
"title": "WFRP4e - Core Module en français.",
|
||||
"description": "Traduction Française pour Warhammer v4.",
|
||||
"version": "4.0.11",
|
||||
"version": "4.0.12",
|
||||
"minimumCoreVersion" : "0.8.0",
|
||||
"compatibleCoreVersion": "0.8.8",
|
||||
"author": "LeRatierBretonnien",
|
||||
|
@ -27,6 +27,8 @@ Talents: Briber, Criminal, Dealmaker,
|
||||
Etiquette (Criminals, Doktor, Guilder)
|
||||
Trappings: Dagger, Hand Weapon (Sword)
|
||||
`
|
||||
import ItemWfrp4e from "/systems/wfrp4e/modules/item/item-wfrp4e.js";
|
||||
import WFRP_Utility from "/systems/wfrp4e/modules/system/utility-wfrp4e.js";
|
||||
|
||||
/************************************************************************************/
|
||||
import "./xregexp-all.js";
|
||||
@ -46,8 +48,8 @@ let regName = XRegExp(name_val, 'gi');
|
||||
|
||||
/************************************************************************************/
|
||||
async function __findItem(itemName, itemType, location = null) {
|
||||
itemName = itemName.trim();
|
||||
let items = game.items.entities.filter(i => i.type == itemType)
|
||||
let toSearch = itemName.toLowerCase().trim();
|
||||
let items = game.items.contents.filter(i => i.type == itemType)
|
||||
|
||||
// Search imported items first
|
||||
for (let i of items) {
|
||||
@ -63,52 +65,54 @@ async function __findItem(itemName, itemType, location = null) {
|
||||
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)
|
||||
let searchResult = itemList.find(t => (t.translated && t.originalName.toLowerCase() == toSearch) || (t.name.toLowerCase() == toSearch) );
|
||||
if (searchResult)
|
||||
return await pack.getEntity(searchResult._id)
|
||||
}
|
||||
return await pack.getDocument(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;
|
||||
for (let p of game.wfrp4e.tags.getPacksWithTag(itemType)) {
|
||||
await p.getIndex().then(index => itemList = index);
|
||||
let searchResult = itemList.find(t => t.name == translItemName)
|
||||
let searchResult = itemList.find(t => (t.translated && t.originalName.toLowerCase() == toSearch) || (t.name.toLowerCase() == toSearch) );
|
||||
if (searchResult)
|
||||
return await p.getEntity(searchResult._id)
|
||||
}
|
||||
return await p.getDocument(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
|
||||
async function __findSkill(skillName, value = undefined) {
|
||||
let toSearch = skillName.toLowerCase().trim();
|
||||
let parseStr = '(?<name>[a-z\\s]*)[\\s\\+]*(?<specialized>[a-z\\s\\(\\)]*)';
|
||||
let skillSplit = XRegExp.exec(skillName, XRegExp(parseStr, 'gi'));
|
||||
|
||||
let skillList = [];
|
||||
let packs = game.packs.filter(p => p.metadata.tags && p.metadata.tags.includes("skill"))
|
||||
// First try world items
|
||||
let worldItem = game.items.contents.filter(i => i.type == "skill" && i.name.toLowerCase() == toSearch)[0];
|
||||
if (worldItem) return worldItem;
|
||||
|
||||
let packs = game.wfrp4e.tags.getPacksWithTag("skill");
|
||||
for (let pack of packs) {
|
||||
//console.log("SEARCH : ", skillName, pack);
|
||||
if ( pack.translations[skillName] ) {
|
||||
let translSkillName = pack.translations[skillName].name;
|
||||
skillList = await pack.getIndex()
|
||||
let 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())
|
||||
let searchResult = skillList.find(s => (s.translated && s.originalName.toLowerCase() == toSearch) || (s.name.toLowerCase() == toSearch ) );
|
||||
if (!searchResult) {
|
||||
let toSearchClean = toSearch.split("(")[0].trim();
|
||||
searchResult = skillList.find(s => (s.translated && s.originalName.toLowerCase().split("(")[0].trim() == toSearchClean) ||
|
||||
(s.name.toLowerCase().split("(")[0].trim() == toSearchClean) );
|
||||
}
|
||||
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;
|
||||
await pack.getDocument(searchResult._id).then(packSkill => dbSkill = packSkill);
|
||||
if (skillSplit.specialized && ( dbSkill.name.includes('()') || dbSkill.name.includes('( )' ) ) ) {
|
||||
let spec = XRegExp.replace(skillSplit.specialized, "(", "");
|
||||
spec = XRegExp.replace(spec, ")", "");
|
||||
let skillSplit2 = XRegExp.exec(dbSkill.name, XRegExp(parseStr, 'gi'));
|
||||
dbSkill.data.update( { name: skillSplit2.name + '(' + game.i18n.localize( spec.trim() ) + ')' } );
|
||||
}
|
||||
//game.babele.translate('wfrp4e-core.skills', dbSkill);
|
||||
return dbSkill;
|
||||
}
|
||||
}
|
||||
throw "Could not find skill (or specialization of) " + skillName + " in compendum or world"
|
||||
@ -116,28 +120,33 @@ async function __findSkill(skillName) {
|
||||
|
||||
/************************************************************************************/
|
||||
async function __findTalent(talentName) {
|
||||
talentName = talentName.trim();
|
||||
let parseStr = '(?<name>[a-z\\s]*)[\\s\\+]*(?<specialized>[a-z\\s\\(\\)]*)';
|
||||
let talentSplit = XRegExp.exec(talentName, XRegExp(parseStr, 'gi'));
|
||||
let toSearch = talentSplit.name.toLowerCase().trim();
|
||||
|
||||
// First try world items
|
||||
let worldItem = game.items.entities.filter(i => i.type == "talent" && i.name == talentName)[0];
|
||||
if (worldItem) return worldItem
|
||||
let worldItem = game.items.contents.filter(i => i.type == "talent" && i.name.toLowerCase() == toSearch)[0];
|
||||
if (worldItem) return worldItem;
|
||||
|
||||
let talentList = [];
|
||||
let packs = game.packs.filter(p => p.metadata.tags && p.metadata.tags.includes("talent"))
|
||||
let packs = game.wfrp4e.tags.getPacksWithTag("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())
|
||||
|
||||
let talentList = await pack.getIndex();
|
||||
// Search for specific skill (won't find unlisted specializations)
|
||||
let searchResult = talentList.find(s => (s.translated && s.originalName.toLowerCase() == toSearch) || (s.name.toLowerCase() == toSearch ) );
|
||||
if (!searchResult) {
|
||||
let toSearchClean = toSearch.split("(")[0].trim();
|
||||
searchResult = talentList.find(s => (s.translated && s.originalName.toLowerCase().split("(")[0].trim() == toSearchClean) ||
|
||||
(s.name.toLowerCase().split("(")[0].trim() == toSearchClean) );
|
||||
}
|
||||
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;
|
||||
await pack.getDocument(searchResult._id).then(packTalent => dbTalent = packTalent);
|
||||
if ( talentSplit.specialized ) {
|
||||
let spec = XRegExp.replace(talentSplit.specialized, "(", "");
|
||||
spec = XRegExp.replace(spec, ")", "");
|
||||
dbTalent.data.update( { name: talentSplit.name + '(' + game.i18n.localize( spec.trim() ) + ')' } );
|
||||
}
|
||||
return dbTalent;
|
||||
}
|
||||
}
|
||||
throw "Could not find talent (or specialization of) " + talentName + " in compendium or world"
|
||||
@ -213,10 +222,12 @@ export default async function statParserFR( statString, type = "npc") {
|
||||
// Then create a table of it in termList, with specific sub-parsing rules
|
||||
let termList = XRegExp.split(def.substring, regSep);
|
||||
for (let name of termList) {
|
||||
let itemFound, subres;
|
||||
let itemFound, subres, value;
|
||||
if (def.secondParse) {
|
||||
subres = XRegExp.exec(name, XRegExp(def.secondParse, 'gi'));
|
||||
name = subres.name.trim();
|
||||
value = XRegExp.replace(subres.value, "(", "");
|
||||
value = XRegExp.replace(subres.value, ")", "");
|
||||
}
|
||||
if (def.name == 'trait') {
|
||||
try {
|
||||
@ -224,19 +235,17 @@ export default async function statParserFR( statString, type = "npc") {
|
||||
}
|
||||
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);
|
||||
itemFound.data.data.specification.value = game.i18n.localize(value);
|
||||
}
|
||||
if (!itemFound)
|
||||
ui.notifications.error("Trait non trouvé, à ajouter manuellemen : " + name, { permanent: true })
|
||||
ui.notifications.error("Trait non trouvé, à ajouter manuellement : " + name, { permanent: true })
|
||||
} else if (def.name == 'skill') {
|
||||
try {
|
||||
itemFound = await __findSkill(name);
|
||||
itemFound = await __findSkill(name, value);
|
||||
}
|
||||
catch { }
|
||||
if ( itemFound && subres && subres.value) {
|
||||
itemFound.data.data.advances.value = Number(subres.value) - Number(resCarac[itemFound.data.data.characteristic.value]);
|
||||
if (itemFound && subres && value) {
|
||||
itemFound.data.data.advances.value = Number(value) - Number(model.characteristics[itemFound.data.data.characteristic.value].initial);
|
||||
}
|
||||
if (!itemFound)
|
||||
ui.notifications.error("Compétence non trouvée, à ajouter manuellement : " + name, { permanent: true })
|
||||
@ -245,8 +254,8 @@ export default async function statParserFR( statString, type = "npc") {
|
||||
itemFound = await __findTalent(name);
|
||||
}
|
||||
catch { }
|
||||
if ( itemFound && subres && subres.value)
|
||||
itemFound.data.data.advances.value = Number(subres.value);
|
||||
if (itemFound && subres && value)
|
||||
itemFound.data.data.advances.value = Number(value);
|
||||
if (!itemFound)
|
||||
ui.notifications.error("Talent non trouvé, à ajouter manuellement : " + name, { permanent: true })
|
||||
} else if (def.name == 'trapping') {
|
||||
@ -255,7 +264,7 @@ export default async function statParserFR( statString, type = "npc") {
|
||||
}
|
||||
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 = new ItemWfrp4e({ img: "systems/wfrp4e/icons/blank.png", name: name, type: "trapping", data: game.system.model.Item.trapping })
|
||||
itemFound.data.data.trappingType.value = "misc"
|
||||
}
|
||||
}
|
||||
@ -270,7 +279,12 @@ export default async function statParserFR( statString, type = "npc") {
|
||||
globalItemList = globalItemList.concat(moneyItems);
|
||||
//console.log("My liste :", globalItemList);
|
||||
let name = pnjName;
|
||||
return { name, type, data: model, items: globalItemList }
|
||||
|
||||
let effects = globalItemList.reduce((total, globItem) => total.concat(globItem.data.effects), [])
|
||||
effects = effects.filter(e => !!e)
|
||||
effects = effects.filter(e => e.transfer)
|
||||
|
||||
return { name, type, data: model, items: globalItemList, effects }
|
||||
}
|
||||
|
||||
// If the carac string has not been found
|
||||
|
11
workspace.code-workspace
Normal file
11
workspace.code-workspace
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"folders": [
|
||||
{
|
||||
"path": "."
|
||||
},
|
||||
{
|
||||
"path": "../WFRP4e-FoundryVTT"
|
||||
}
|
||||
],
|
||||
"settings": {}
|
||||
}
|
Loading…
Reference in New Issue
Block a user