Various fixes

This commit is contained in:
LeRatierBretonnien 2023-09-08 08:01:54 +02:00
parent 07419d8685
commit 838bf6cd85
7 changed files with 335 additions and 2785 deletions

View File

@ -1,5 +1,11 @@
{ {
"label": "Tables (Archives Vol. I)", "label": "Tables (Archives Vol. I)",
"mapping": {
"results": {
"path": "results",
"converter": "resultConverter"
}
},
"entries": [ "entries": [
{ {
"id": "Career - Wood Elf (Toriour)", "id": "Career - Wood Elf (Toriour)",

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,11 @@
{ {
"label": "Tables (Middenheim)", "label": "Tables (Middenheim)",
"mapping": {
"results": {
"path": "results",
"converter": "resultConverter"
}
},
"entries": [ "entries": [
{ {
"id": "Athletics - Middenball", "id": "Athletics - Middenball",

View File

@ -8,7 +8,7 @@
} }
], ],
"url": "https://www.uberwald.me/gitea/public/foundryvtt-wh4-lang-fr-fr", "url": "https://www.uberwald.me/gitea/public/foundryvtt-wh4-lang-fr-fr",
"version": "7.0.1", "version": "7.0.2",
"esmodules": [ "esmodules": [
"babele-register.js", "babele-register.js",
"addon-register.js", "addon-register.js",
@ -127,7 +127,7 @@
} }
], ],
"manifest": "https://www.uberwald.me/gitea/public/foundryvtt-wh4-lang-fr-fr/raw/v10/module.json", "manifest": "https://www.uberwald.me/gitea/public/foundryvtt-wh4-lang-fr-fr/raw/v10/module.json",
"download": "https://www.uberwald.me/gitea/public/foundryvtt-wh4-lang-fr-fr/archive/foundryvtt-wh4-lang-fr-7.0.1.zip", "download": "https://www.uberwald.me/gitea/public/foundryvtt-wh4-lang-fr-fr/archive/foundryvtt-wh4-lang-fr-7.0.2.zip",
"id": "wh4-fr-translation", "id": "wh4-fr-translation",
"compatibility": { "compatibility": {
"minimum": "10", "minimum": "10",

View File

@ -56,17 +56,19 @@ const name_val = '(?<name>[a-zA-Z\\s\\-,]*)[\\s\\r\\na-zA-Z]*(?<tiers>.*|[\\(\\)
let sectionDataFR = [ let sectionDataFR = [
{ name: "trait", toFind: "Traits\\s*:", secondParse: '(?<name>[a-zàéè\\s]*)[\\s\\+]*(?<value>.*|[\\+0-9]+)', index: -1 }, { name: "trait", toFind: "Traits\\s*:", secondParse: '(?<name>[a-zàéè\\s]*)[\\s\\+]*(?<value>.*|[\\+0-9]+)', index: -1 },
{ name: "skill", toFind: "Compétences\\s*:", secondParse: '(?<name>[a-zàéè\\s\\(\\)]*)[\\s\\+]*(?<value>.*|[0-9]+)', index: -1 }, { name: "skill", toFind: "Compétences\\s*:", secondParse: '(?<name>[a-zàéè\\s\\(\\)]*)[\\s\\+]*(?<value>.*|[0-9]+)', index: -1 },
{ name: "talent", toFind: "Talents\\s*:", secondParse: '(?<name>[a-zàéè\\-\\s!/]*)[\\s\\+]*(?<value>.*|[0-9]+)', index: -1 }, { name: "talent", toFind: "Talents\\s*:", secondParse: '(?<name>[a-zàéè\\-\\(\\)\\s\\/]*)[\\s\\+]*(?<value>.*|[0-9]+)', index: -1 },
{ name: "mutation", toFind: "Mutations\\s*:", secondParse: '(?<name>[a-zàéè\\s]*)[\\s\\+]*(?<value>.*|[0-9]+)', index: -1 }, { name: "mutation", toFind: "Mutations\\s*:", secondParse: '(?<name>[a-zàéè\\s]*)[\\s\\+]*(?<value>.*|[0-9]+)', index: -1 },
{ name: "trapping", toFind: "Equiement\\s*:", secondParse: '(?<name>[a-zàéè\\s]*)[\\s\\+]*(?<value>.*|[0-9]+)', index: -1 } { name: "trapping", toFind: "Equipement\\s*:", secondParse: '(?<name>[a-zàéè\\s]*)[\\s\\+]*(?<value>.*|[0-9]+)', index: -1 },
{ name: "spell", toFind: "Sorts\\s*\\([a-z\\s]*\\)*:", secondParse: '(?<name>[a-zàéè\\s]*)', index: -1 }
]; ];
let sectionDataUS = [ let sectionDataUS = [
{ name: "trait", toFind: "Traits\\s*:", secondParse: '(?<name>[a-z\\s]*)[\\s\\+]*(?<value>.*|[\\+0-9]+)', index: -1 }, { 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: "skill", toFind: "Skills\\s*:", secondParse: '(?<name>[a-z\\s\\(\\)]*)[\\s\\+]*(?<value>.*|[0-9]+)', index: -1 },
{ name: "talent", toFind: "Talents\\s*:", secondParse: '(?<name>[a-z\\-\\s!/]*)[\\s\\+]*(?<value>.*|[0-9]+)', index: -1 }, { name: "talent", toFind: "Talents\\s*:", secondParse: '(?<name>[a-z\\-\\s\\(\\)\\/]*)[\\s\\+]*(?<value>.*|[0-9]+)', index: -1 },
{ name: "mutation", toFind: "Mutations\\s*:", secondParse: '(?<name>[a-z\\s]*)[\\s\\+]*(?<value>.*|[0-9]+)', index: -1 }, { name: "mutation", toFind: "Mutations\\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 } { name: "trapping", toFind: "Trappings\\s*:", secondParse: '(?<name>[a-z\\s]*)[\\s\\+]*(?<value>.*|[0-9]+)', index: -1 },
]; { name: "spell", toFind: "Spells\\s*\\([a-z\\s]*\\)*:", secondParse: '(?<name>[a-z\\s]*)', index: -1 }
]
let regSep = XRegExp('\\s*,\\s*', 'gi'); // Term separator, with auto trim let regSep = XRegExp('\\s*,\\s*', 'gi'); // Term separator, with auto trim
let regLine1 = XRegExp('[\\r\\n\\.]', 'gi'); // Term separator, with auto trim let regLine1 = XRegExp('[\\r\\n\\.]', 'gi'); // Term separator, with auto trim
let regName = XRegExp(name_val, 'gi'); let regName = XRegExp(name_val, 'gi');
@ -79,7 +81,7 @@ async function __findItem(itemName, itemType, location = null) {
// Search imported items first // Search imported items first
for (let i of items) { for (let i of items) {
if (i.name.toLowerCase() == itemName.toLowerCase() && i.type == itemType) if (i.name.toLowerCase() == itemName.toLowerCase() && i.type == itemType)
return i; return i.toObject();
} }
let itemList let itemList
@ -92,8 +94,10 @@ async function __findItem(itemName, itemType, location = null) {
if (pack) { if (pack) {
await pack.getIndex().then(index => itemList = index); await pack.getIndex().then(index => itemList = index);
let searchResult = itemList.find(t => (t.translated && t.type == itemType && t.originalName.toLowerCase() == toSearch) || (t.type == itemType && t.name.toLowerCase() == toSearch) ); let searchResult = itemList.find(t => (t.translated && t.type == itemType && t.originalName.toLowerCase() == toSearch) || (t.type == itemType && t.name.toLowerCase() == toSearch) );
if (searchResult) if (searchResult) {
return await pack.getDocument(searchResult._id) let item = await pack.getDocument(searchResult._id)
return item.toObject()
}
} }
} }
@ -101,8 +105,10 @@ async function __findItem(itemName, itemType, location = null) {
for (let p of game.wfrp4e.tags.getPacksWithTag(itemType)) { for (let p of game.wfrp4e.tags.getPacksWithTag(itemType)) {
await p.getIndex().then(index => itemList = index); await p.getIndex().then(index => itemList = index);
let searchResult = itemList.find(t => (t.translated && t.type == itemType && t.originalName.toLowerCase() == toSearch) || (t.type == itemType && t.name.toLowerCase() == toSearch) ); let searchResult = itemList.find(t => (t.translated && t.type == itemType && t.originalName.toLowerCase() == toSearch) || (t.type == itemType && t.name.toLowerCase() == toSearch) );
if (searchResult) if (searchResult) {
return await p.getDocument(searchResult._id) let item = await p.getDocument(searchResult._id)
return item.toObject()
}
} }
} }
@ -121,24 +127,26 @@ async function __findSkill(skillName, value = undefined) {
for (let pack of packs) { for (let pack of packs) {
let skillList = await pack.getIndex(); let skillList = await pack.getIndex();
// Search for specific skill (won't find unlisted specializations) // Search for specific skill (won't find unlisted specializations)
let searchResult = skillList.find(s => (s.translated && s.originalName.toLowerCase() == toSearch) || (s.name.toLowerCase() == toSearch ) ); let searchResult = skillList.find(s => (s.type == "skill" && s.translated && s.originalName.toLowerCase() == toSearch) || (s.type == "skill" && s.name.toLowerCase() == toSearch ) );
if (!searchResult) { if (!searchResult) {
let toSearchClean = toSearch.split("(")[0].trim(); let toSearchClean = toSearch.split("(")[0].trim();
searchResult = skillList.find(s => (s.translated && s.originalName.toLowerCase().split("(")[0].trim() == toSearchClean) || searchResult = skillList.find(s => (s.type == "skill" && s.translated && s.originalName.toLowerCase().split("(")[0].trim() == toSearchClean) ||
(s.name.toLowerCase().split("(")[0].trim() == toSearchClean) ); (s.type == "skill" && s.name.toLowerCase().split("(")[0].trim() == toSearchClean) );
} }
if (searchResult) { if (searchResult) {
let dbSkill; let dbSkill;
await pack.getDocument(searchResult._id).then(packSkill => dbSkill = packSkill); await pack.getDocument(searchResult._id).then(packSkill => dbSkill = packSkill);
if (skillSplit.specialized && ( dbSkill.name.includes('()') || dbSkill.name.includes('( )' ) ) ) { let item = dbSkill.toObject();
//console.log("Skill name1", skillSplit)
if (skillSplit.specialized && ( item.name.includes('()') || item.name.includes('( )' ) ) ) {
let spec = XRegExp.replace(skillSplit.specialized, "(", ""); let spec = XRegExp.replace(skillSplit.specialized, "(", "");
spec = XRegExp.replace(spec, ")", ""); spec = XRegExp.replace(spec, ")", "");
let skillSplit2 = XRegExp.exec(dbSkill.name, XRegExp(parseStr, 'gi')); let skillSplit2 = XRegExp.exec(item.name, XRegExp(parseStr, 'gi'));
dbSkill.name = skillSplit2.name + '(' + game.i18n.localize( spec.trim() ) + ')' item.name = skillSplit2.name + '(' + game.i18n.localize( spec.trim() ) + ')'
//dbSkill.update( { name: } ); //dbSkill.update( { name: } );
} }
//game.babele.translate('wfrp4e-core.skills', dbSkill); //game.babele.translate('wfrp4e-core.skills', dbSkill);
return dbSkill; return item
} }
} }
throw "Could not find skill (or specialization of) " + skillName + " in compendum or world" throw "Could not find skill (or specialization of) " + skillName + " in compendum or world"
@ -146,10 +154,12 @@ async function __findSkill(skillName, value = undefined) {
/************************************************************************************/ /************************************************************************************/
async function __findTalent(talentName) { async function __findTalent(talentName) {
let parseStr = '(?<name>[a-z\\s]*)[\\s\\+]*(?<specialized>[a-z\\s\\(\\)]*)'; let parseStr = '(?<name>[a-z\\s\\/]*)[\\s\\+]*(?<specialized>[a-z\\s\\(\\)]*)';
let talentSplit = XRegExp.exec(talentName, XRegExp(parseStr, 'gi')); let talentSplit = XRegExp.exec(talentName, XRegExp(parseStr, 'gi'));
let toSearch = talentSplit.name.toLowerCase().trim(); let toSearch = talentSplit.name.toLowerCase().trim();
//console.log("Talent name", talentName, talentSplit)
// First try world items // First try world items
let worldItem = game.items.contents.filter(i => i.type == "talent" && i.name.toLowerCase() == toSearch)[0]; let worldItem = game.items.contents.filter(i => i.type == "talent" && i.name.toLowerCase() == toSearch)[0];
if (worldItem) return worldItem; if (worldItem) return worldItem;
@ -166,13 +176,16 @@ async function __findTalent(talentName) {
} }
if (searchResult) { if (searchResult) {
let dbTalent; let dbTalent;
//console.log("Talent name1", talentSplit)
await pack.getDocument(searchResult._id).then(packTalent => dbTalent = packTalent); await pack.getDocument(searchResult._id).then(packTalent => dbTalent = packTalent);
let item = dbTalent.toObject();
if ( talentSplit.specialized ) { if ( talentSplit.specialized ) {
let spec = XRegExp.replace(talentSplit.specialized, "(", ""); let spec = XRegExp.replace(talentSplit.specialized, "(", "");
spec = XRegExp.replace(spec, ")", ""); spec = XRegExp.replace(spec, ")", "");
dbTalent.update( { name: talentSplit.name + '(' + game.i18n.localize( spec.trim() ) + ')' } ); item.name = talentSplit.name + '(' + game.i18n.localize( spec.trim() ) + ')'
//console.log("Talent name2", dbTalent.name, spec, game.i18n.localize( spec.trim()) )
} }
return dbTalent; return item;
} }
} }
throw "Could not find talent (or specialization of) " + talentName + " in compendium or world" throw "Could not find talent (or specialization of) " + talentName + " in compendium or world"
@ -267,13 +280,19 @@ export default async function statParserFR(statString, type = "npc") {
// Then create a table of it in termList, with specific sub-parsing rules // Then create a table of it in termList, with specific sub-parsing rules
let termList = XRegExp.split(def.substring, regSep); let termList = XRegExp.split(def.substring, regSep);
let lastSkillName
for (let name of termList) { for (let name of termList) {
let itemFound, subres, value; let itemFound, subres, value;
if (def.secondParse) { if (def.secondParse) {
subres = XRegExp.exec(name, XRegExp(def.secondParse, 'gi')) subres = XRegExp.exec(name, XRegExp(def.secondParse, 'gi'))
//console.log("Second pars", def, name, subres)
name = subres.name.trim().replace("\n", "").replace("\r", "") name = subres.name.trim().replace("\n", "").replace("\r", "")
value = XRegExp.replace(subres.value, "(", "") if (subres.value) {
value = XRegExp.replace(value, ")", "") value = XRegExp.replace(subres.value, "(", "")
value = XRegExp.replace(value, ")", "")
} else {
value = 0
}
} }
name = __patchName(name) name = __patchName(name)
if (def.name == 'trait') { if (def.name == 'trait') {
@ -281,12 +300,10 @@ export default async function statParserFR(statString, type = "npc") {
itemFound = await __findItem(name, "trait") itemFound = await __findItem(name, "trait")
} }
catch { } catch { }
if (itemFound)
itemFound = itemFound.toObject()
if (itemFound && value && value.length > 0) { if (itemFound && value && value.length > 0) {
if (name.toLowerCase() == 'weapon' || name.toLowerCase() == "bite" || name.toLowerCase() == "tail" || if (name.toLowerCase() == 'weapon' || name.toLowerCase() == "bite" || name.toLowerCase() == "tail" ||
name.toLowerCase() == 'arme' || name.toLowerCase() == "morsure" || name.toLowerCase() == "queue") { name.toLowerCase() == 'arme' || name.toLowerCase() == "morsure" || name.toLowerCase() == "queue") {
console.log(itemFound) //console.log(itemFound)
itemFound.system.specification.value = Number(value) - Math.floor( Number(model.characteristics.s.initial) / 10) itemFound.system.specification.value = Number(value) - Math.floor( Number(model.characteristics.s.initial) / 10)
} else { } else {
itemFound.system.specification.value = game.i18n.localize(value) itemFound.system.specification.value = game.i18n.localize(value)
@ -300,11 +317,20 @@ export default async function statParserFR(statString, type = "npc") {
itemFound = await __findSkill(name, value); itemFound = await __findSkill(name, value);
} }
catch { } catch { }
if (itemFound) if (!itemFound && lastSkillName) {
itemFound = itemFound.toObject(); name = lastSkillName + " (" + name + ")"
itemFound = await __findSkill(name, value);
}
if (itemFound && subres && value) { if (itemFound && subres && value) {
itemFound.system.advances.value = Number(value) - Number(model.characteristics[itemFound.system.characteristic.value].initial); itemFound.system.advances.value = Number(value) - Number(model.characteristics[itemFound.system.characteristic.value].initial);
} }
lastSkillName = undefined
if ( itemFound?.name?.includes('Trade')) { // useful to handle skills grouping
lastSkillName = "Trade"
}
if ( itemFound?.name?.includes('Lore')) {
lastSkillName = "Lore"
}
if (!itemFound) if (!itemFound)
ui.notifications.error("Compétence non trouvée, à ajouter manuellement : " + name, { permanent: true }) ui.notifications.error("Compétence non trouvée, à ajouter manuellement : " + name, { permanent: true })
} else if (def.name == 'talent') { } else if (def.name == 'talent') {
@ -312,8 +338,6 @@ export default async function statParserFR(statString, type = "npc") {
itemFound = await __findTalent(name); itemFound = await __findTalent(name);
} }
catch { } catch { }
if (itemFound)
itemFound = itemFound.toObject();
if (itemFound && subres && value) if (itemFound && subres && value)
itemFound.system.advances.value = Number(value); itemFound.system.advances.value = Number(value);
if (!itemFound) if (!itemFound)
@ -324,18 +348,25 @@ export default async function statParserFR(statString, type = "npc") {
} }
catch { } catch { }
if (!itemFound && name) { if (!itemFound && name) {
itemFound = new game.entities.ItemWfrp4e({ img: "systems/wfrp4e/icons/blank.png", name: name, type: "trapping", system: game.system.model.Item.trapping }) itemFound = new ItemWfrp4e({ img: "systems/wfrp4e/icons/blank.png", name: name, type: "trapping", system: game.system.model.Item.trapping })
itemFound.system.trappingType.value = "misc" itemFound.system.trappingType.value = "misc"
itemFound = itemFound.toObject()
} }
if (itemFound) } else if (def.name == 'spell') {
itemFound = itemFound.toObject(); console.log("Found spells section!!!!")
try {
itemFound = await __findItem(name, "spell");
}
catch { }
if (!itemFound && name) {
itemFound = new ItemWfrp4e({ img: "systems/wfrp4e/icons/blank.png", name: name, type: "spell", system: game.system.model.Item.spell })
itemFound = itemFound.toObject();
}
} else if (def.name == 'mutation') { } else if (def.name == 'mutation') {
try { try {
itemFound = await __findItem(name, "mutation"); itemFound = await __findItem(name, "mutation");
} }
catch { } catch { }
if (itemFound)
itemFound = itemFound.toObject();
} }
if (itemFound) if (itemFound)

File diff suppressed because it is too large Load Diff

View File

@ -3,7 +3,7 @@ local JSON = require"json"
--local enjsonf = "/home/morr/foundry/foundrydata-dev/Data/modules/wfrp4e-dotr/lang/en.json" --local enjsonf = "/home/morr/foundry/foundrydata-dev/Data/modules/wfrp4e-dotr/lang/en.json"
local careerv10 = "careerv10.json" local careerv10 = "careerv10.json"
local goodC = "../compendium/wfrp4e-core.careers.json" local goodC = "../compendium/wfrp4e-core.items.json"
local fp = io.open(careerv10, "r") local fp = io.open(careerv10, "r")
local c10 = JSON.decode( fp:read("*a") ) local c10 = JSON.decode( fp:read("*a") )