foundryvtt-wh4-lang-fr-fr/babele-register.js

346 lines
15 KiB
JavaScript
Raw Normal View History

2020-11-08 00:22:04 +01:00
/************************************************************************************/
import autoTranslateItems from "./modules/import-stat-2.js";
2020-06-29 08:12:31 +02:00
/************************************************************************************/
var compmod = "wfrp4e";
/************************************************************************************/
2020-03-25 20:37:09 +01:00
Hooks.once('init', () => {
2020-07-03 11:38:38 +02:00
// Check various settings in the installation
2020-06-29 07:44:16 +02:00
game.modules.forEach((module, name) => {
2020-11-05 21:53:12 +01:00
if ( name == "wfrp4e-core" && module.active) {
compmod = "wfrp4e-core";
}
2020-06-29 07:47:22 +02:00
} );
2020-11-08 00:22:04 +01:00
game.wfrp4efr = { compmod: compmod };
2020-11-06 17:51:31 +01:00
//WFRP_Tables = game.wfrp4e.tables;
//WFRP4E = game.wfrp4e.config;
2020-11-07 13:46:15 +01:00
//CONFIG.Actor.entityClass = ActorWfrp4e_fr;
game.wfrp4e.entities.ActorWfrp4e.prototype.calculateRangeOrDamage = function(formula)
{
//console.log("FR function calculateRangeOrDamage !", formula);
let actorData = this.data
try
{
formula = formula.toLowerCase();
// Iterate through characteristics
for(let ch in actorData.data.characteristics)
{
// Determine if the formula includes the characteristic's abbreviation + B (SB, WPB, etc.)
if (formula.includes(ch.concat('b')))
{
// Replace that abbreviation with the Bonus value
formula = formula.replace(ch.concat('b'), actorData.data.characteristics[ch].bonus.toString());
}
}
if (formula.includes("yard") )
formula = formula.replace('yard', "mètre" );
if (formula.includes("yds") )
formula = formula.replace('yds', "m." );
// To evaluate multiplication, replace x with *
formula = formula.replace('x', '*');
return eval(formula);
}
catch
{
return formula
}
}
game.wfrp4e.entities.ActorWfrp4e.prototype.calculateSpellDamage = function(formula, isMagicMissile) {
//console.log("Compute FR")
let actorData = this.data
formula = formula.toLowerCase();
if (isMagicMissile) // If it's a magic missile, damage includes willpower bonus
{
formula += "+ " + actorData.data.characteristics["wp"].bonus
}
2020-06-29 07:44:16 +02:00
2020-11-07 13:46:15 +01:00
// Specific case, to avoid wrong matching with "Force"
if (formula.includes("force mentale"))
{
// Determine if it's looking for the bonus or the value
if (formula.includes('bonus')) {
formula = formula.replace( "bonus de force mentale", actorData.data.characteristics["wp"].bonus);
formula = formula.replace( "force mentale bonus", actorData.data.characteristics["wp"].bonus);
} else
formula = formula.replace("force mentale", actorData.data.characteristics["wp"].value);
}
// Iterate through characteristics
for(let ch in actorData.data.characteristics)
{
// If formula includes characteristic name
while (formula.includes(actorData.data.characteristics[ch].label.toLowerCase()))
{
// Determine if it's looking for the bonus or the value
if (formula.includes('bonus')) {
formula = formula.replace("bonus de " + game.wfrp4e.config.characteristics[ch].toLowerCase(), actorData.data.characteristics[ch].bonus);
formula = formula.replace(game.wfrp4e.config.characteristics[ch].toLowerCase() + " bonus", actorData.data.characteristics[ch].bonus);
}
else
formula = formula.replace(game.wfrp4e.config.characteristics[ch].toLowerCase(), actorData.data.characteristics[ch].value);
}
}
//console.log("calculateSpellDamage -> " + formula );
return eval(formula);
}
game.wfrp4e.entities.ActorWfrp4e.prototype.calculateSpellAttributes = function(formula, aoe=false) {
//console.log("Compute FR")
let actorData = this.data
formula = formula.toLowerCase();
// Do not process these special values
if (formula != game.i18n.localize("You").toLowerCase() && formula != game.i18n.localize("Special").toLowerCase() && formula != game.i18n.localize("Instant").toLowerCase())
{
// Specific case, to avoid wrong matching with "Force"
if (formula.includes("force mentale"))
{
// Determine if it's looking for the bonus or the value
if (formula.includes('bonus')) {
formula = formula.replace( "bonus de force mentale", actorData.data.characteristics["wp"].bonus);
formula = formula.replace( "force mentale bonus", actorData.data.characteristics["wp"].bonus);
}
else
formula = formula.replace("force mentale", actorData.data.characteristics["wp"].value);
}
if (formula.includes("yard") )
formula = formula.replace('yard', "mètre" );
if (formula.includes("yds") )
formula = formula.replace('yds', "m." );
// Iterate through remaining characteristics
for(let ch in actorData.data.characteristics)
{
// If formula includes characteristic name
//console.log("Testing :", ch, WFRP4E.characteristics[ch].toLowerCase());
if (formula.includes(game.wfrp4e.config.characteristics[ch].toLowerCase()))
{
// Determine if it's looking for the bonus or the value
if (formula.includes('bonus')) {
formula = formula.replace("bonus de " + game.wfrp4e.config.characteristics[ch].toLowerCase(), actorData.data.characteristics[ch].bonus);
formula = formula.replace(game.wfrp4e.config.characteristics[ch].toLowerCase() + " bonus", actorData.data.characteristics[ch].bonus);
}
else
formula = formula.replace(game.wfrp4e.config.characteristics[ch].toLowerCase(), actorData.data.characteristics[ch].value);
}
}
}
// If AoE - wrap with AoE ( )
if (aoe)
formula = "AoE (" + formula.capitalize() + ")";
//console.log("calculateSpellAttributes -> " + formula );
return formula.capitalize();
}
2020-11-08 00:22:04 +01:00
//1console.log("PROTO", game.wfrp4e.entities.ActorWfrp4e.prototype);
2020-11-07 13:46:15 +01:00
2020-06-29 07:47:22 +02:00
// Babele stuff
2020-03-25 20:37:09 +01:00
if(typeof Babele !== 'undefined') {
Babele.get().register({
module: 'WH4-fr-translation',
lang: 'fr',
dir: 'compendium'
});
2020-07-04 21:48:40 +02:00
Babele.get().registerConverters({
2020-03-31 09:03:19 +02:00
"career_skills": (skills_list) => {
2020-06-29 07:44:16 +02:00
var compendium = game.packs.find(p => p.collection === compmod+'.skills');
//console.log( "Thru here ...", compendium, skills_list);
2020-05-05 09:21:03 +02:00
if ( skills_list ) {
var i;
var len = skills_list.length;
var re = /(.*)\((.*)\)/i;
for (i = 0; i < len; i++) {
var transl = compendium.i18nName( { name: skills_list[i] } );
//console.log("List ...", skills_list[i]);
if ( transl == skills_list[i] ) {
var res = re.exec( skills_list[i]);
if (res) {
//console.log("Matched/split:", res[1], res[2]);
var subword = game.i18n.localize(res[2].trim() );
var s1 = res[1].trim() + " ()";
var translw = compendium.i18nName( { name: s1} );
if (translw != s1) {
var res2 = re.exec(translw);
transl = res2[1] + "(" + subword + ")";
} else {
s1 = res[1].trim() + " ( )";
translw = compendium.i18nName( { name: s1} );
var res2 = re.exec(translw);
transl = res2[1] + "(" + subword + ")";
}
}
}
2020-05-05 09:21:03 +02:00
skills_list[i] = transl;
}
}
return skills_list;
},
"career_talents": (talents_list) => {
2020-06-30 18:37:02 +02:00
var compendium = game.packs.find(p => p.collection === compmod+'.talents');
var i;
2020-05-05 09:21:03 +02:00
if ( talents_list ) {
var len = talents_list.length;
var re = /(.*)\((.*)\)/i;
for (i = 0; i < len; i++) {
var transl = compendium.i18nName( { name: talents_list[i]} );
if ( transl == talents_list[i] ) {
var res = re.exec( talents_list[i]);
if (res) {
//console.log("Matched/split:", res[1], res[2]);
var subword = game.i18n.localize(res[2].trim() );
var s1 = res[1].trim(); // No () in talents table
var translw = compendium.i18nName( { name: s1 } );
if (translw != s1) {
transl = translw + "(" + subword + ")";
} else {
s1 = res[1].trim() + " ( )";
translw = compendium.i18nName( { name: s1 } );
var res2 = re.exec(translw);
transl = res2[1] + "(" + subword + ")";
}
}
}
2020-05-05 09:21:03 +02:00
talents_list[i] = transl;
}
}
return talents_list;
2020-03-31 09:27:04 +02:00
},
"npc_characteristics": (chars) => { // Auto-convert char names in the sheet
for (var key in chars) {
var char = chars[key];
//console.log("Was here !", key, char );
var abrev = char["abrev"];
2020-06-06 13:27:59 +02:00
let toTransl = "CHAR." + abrev;
if ( game.i18n.localize( toTransl ) != toTransl) { // Manages unknown language
char["label"] = game.i18n.localize( "CHAR." + abrev );
char["abrev"] = game.i18n.localize( "CHARAbbrev." + abrev );
}
}
return chars;
},
2020-04-22 20:22:34 +02:00
"bestiary_traits": (beast_traits, translations) => {
2020-11-08 00:22:04 +01:00
return autoTranslateItems(beast_traits, translations );
},
2020-03-31 09:27:04 +02:00
// To avoid duplicateing class for all careers
2020-03-31 17:44:46 +02:00
"generic_localization": (value) => {
2020-04-01 00:41:20 +02:00
if ( value )
return game.i18n.localize( value.trim() );
2020-04-10 15:11:26 +02:00
},
2020-04-01 00:41:20 +02:00
"trapping_qualities_flaws": (value) => {
if ( value ) {
2020-06-22 09:10:40 +02:00
//console.log("ATOUTS", value);
2020-04-01 00:41:20 +02:00
var list = value.split( "," );
var i=0;
var re = /(.*) (\d+)/i;
for (i=0; i<list.length; i++) {
2020-06-19 00:26:15 +02:00
let trim = list[i].trim();
if ( trim == "Trap Blade") {
trim = "TrapBlade"; // Auto-patch, without space!
//console.log("PATCHED", trim);
}
var splitted = re.exec( trim );
2020-06-22 09:10:40 +02:00
//console.log("Current quality", splitted, trim );
2020-04-01 00:41:20 +02:00
if ( splitted ) {
//console.log("FOund:", splitted[0], splitted[1], splitted[2] );
list[i] = game.i18n.localize( splitted[1] ) + " " + splitted[2];
} else {
2020-06-19 00:26:15 +02:00
list[i] = game.i18n.localize( trim ) ;
2020-04-01 00:41:20 +02:00
}
2020-03-31 17:44:46 +02:00
}
2020-04-01 00:41:20 +02:00
return list.toString();
2020-03-31 17:44:46 +02:00
}
},
2020-03-31 09:27:04 +02:00
// Search back in careers the translated name of the groupe (as it is the name of the level career itself)
"career_careergroup": (value) => {
2020-10-06 08:25:51 +02:00
// Manage exception - Dirty hack
2020-07-03 11:38:38 +02:00
if ( value == 'Slayer' ) {
return "Tueurs Nains";
}
2020-10-06 08:25:51 +02:00
if ( value == 'Druidic Priest' ) {
return "Druide";
}
2020-07-03 11:38:38 +02:00
// Per default
2020-06-29 07:44:16 +02:00
var compendium = game.packs.find(p => p.collection === compmod+'.careers');
2020-04-14 17:16:25 +02:00
return compendium.i18nName( { name: value } );
2020-04-10 15:11:26 +02:00
},
2020-06-21 22:28:51 +02:00
"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 :)
2020-06-14 21:22:07 +02:00
//console.log("Parsing mutation :", value);
value = value.toLowerCase();
2020-06-21 22:28:51 +02:00
value = value.replace("gain a broken condition if you fail a test derived from ", "Gagnez un état Brisé si vous échouez à un test dérivé de ");
value = value.replace("weapon skill" ,"Capacité de Combat");
value = value.replace("ballistic skill", "Capacité de Tir");
value = value.replace("strength", "Force");
value = value.replace("toughness", "Endurance");
value = value.replace("agility", "Agilité");
value = value.replace("dexterity", "Dextérité");
value = value.replace("willpower", "Force Mentale");
value = value.replace("fellowship", "Sociabilité");
value = value.replace("initiative", "Initiative");
value = value.replace("intelligence", "Intelligence");
2020-06-21 22:28:51 +02:00
value = value.replace("armor points to the head", "PA à la Tête");
value = value.replace("subject to frenzy", "Sujet à la Frénésie");
value = value.replace("you do not scar", "Aucune cicatrice");
value = value.replace("movement", "Mouvement");
value = value.replace("armor points to all locations", "PA sur tout le corps");
value = value.replace("to any test when alone", "à tout les tests lorsque seul");
value = value.replace("track", "Pistage");
value = value.replace("to any test not hurting another", "à tout les Tests n'aggressant pas autrui");
value = value.replace("on tests to hurt", "pour les tests impliquant une agression")
value = value.replace("to all language tests when speaking", "à tout les Tests de Langue lorsque vous parlez");
value = value.replace("on perception tests involving sight", "aux Tests de Perception impliquant la Vue");
value = value.replace("to all Sociabilité tests", "à tout les Tests de Sociabilité");
return value;
},
2020-04-10 15:11:26 +02:00
// Auto-translate duration
"spells_duration_range_target_damage": (value) => {
2020-04-10 17:36:32 +02:00
//console.log("Spell duration/range/damage/target :", value);
2020-04-10 15:11:26 +02:00
if ( value == "" ) return ""; // Hop !
if ( value == "Touch" ) return "Contact"; // Hop !
if ( value == "You" ) return "Vous"; // Hop !
if ( value == "Instant" ) return "Instantané"; // Hop !
var translw = value;
var re = /(.*) Bonus (\w*)/i;
var res = re.exec( value );
var unit = "";
if ( res ) { // Test "<charac> Bonus <unit>" pattern
if ( res[1] ) { // We have char name, then convert it
translw = "Bonus de " + game.i18n.localize( res[1].trim() );
}
unit = res[2];
} else {
re = /(\d+) (\w+)/i;
res = re.exec( value );
if (res) { // Test : "<number> <unit>" pattern
translw = res[1];
unit = res[2];
} else { // Test
re = /(\w+) (\w+)/i;
res = re.exec( value );
if (res) { // Test : "<charac> <unit>" pattern
translw = game.i18n.localize( res[1].trim() );
unit = res[2];
}
}
}
if ( unit == "hour") unit = "heure";
if ( unit == "hours") unit = "heures";
if ( unit == "days") unit = "jours";
if ( unit == "yard") unit = "mètre";
if ( unit == "yards") unit = "mètres";
translw += " " + unit;
return translw;
2020-03-31 17:44:46 +02:00
}
});
2020-03-27 23:12:43 +01:00
}
2020-03-25 21:03:36 +01:00
} );
2020-04-12 08:59:47 +02:00