resolve multi player names

pull/36/head
HardiReady 2018-06-09 19:17:38 +02:00
parent 7797397764
commit d10fc8e49a
1 changed files with 20 additions and 6 deletions

View File

@ -11,7 +11,7 @@ const VehicleClasses = Object.freeze({
UNKNOWN: 'Unbekannt', UNKNOWN: 'Unbekannt',
}); });
const playerNameRegex = /^(.*?)\s\(/; const playerNameRegex = /(^|,\s)(.*?)\s\(/g;
const vehicleNameEndRegex = /\s\(\w+:/; const vehicleNameEndRegex = /\s\(\w+:/;
@ -279,18 +279,27 @@ const getBudgetEntry = (budg, warId, warDate) => {
const getPlayerAndFractionFromString = (inputString) => { const getPlayerAndFractionFromString = (inputString) => {
const playerNameRegexMatch = playerNameRegex.exec(inputString); const playerNameRegexMatch = playerNameRegex.exec(inputString);
const sideMatch = sideRegex.exec(inputString); const sideMatch = sideRegex.exec(inputString);
// const magazineMatch = magazineRegex.exec(inputString);
// const vehicleMatch = vehicleRegex.exec(inputString);
// SINGLE PLAYER NAME
let name; let name;
if (playerNameRegexMatch && playerNameRegexMatch.length >= 2) { if (playerNameRegexMatch && playerNameRegexMatch.length >= 2) {
// NAME // NAME
name = playerNameRegexMatch[1]; name = playerNameRegexMatch[2].trim();
}
// ADDITIONAL PLAYER NAMES
let additionalPlayerMatch;
while ((additionalPlayerMatch = playerNameRegex.exec(inputString)) !== null) {
const addPlayer = additionalPlayerMatch[0].replace(/^,\s/, '').replace(/\s\($/, '').trim();
if (name instanceof Array) {
name.push(addPlayer)
} else {
name = [name, addPlayer];
}
} }
// PLAYER FRACTION
let side; let side;
if (sideMatch && sideMatch.length >= 3) { if (sideMatch && sideMatch.length >= 3) {
// SIDE
side = sideMatch[2]; side = sideMatch[2];
} else { } else {
const inputArray = inputString.split(WHITESPACE); const inputArray = inputString.split(WHITESPACE);
@ -299,6 +308,9 @@ const getPlayerAndFractionFromString = (inputString) => {
} }
} }
// const magazineMatch = magazineRegex.exec(inputString);
// const vehicleMatch = vehicleRegex.exec(inputString);
// if (magazineMatch && magazineMatch.length >= 3) { // if (magazineMatch && magazineMatch.length >= 3) {
// MAGAZINE // MAGAZINE
// console.log(magazineMatch[2]) // console.log(magazineMatch[2])
@ -320,9 +332,11 @@ const getPlayerAndFractionFromString = (inputString) => {
undefined; undefined;
} }
console.log(name);
// do not return player for 'Error: No unit' // do not return player for 'Error: No unit'
if (name && name !== 'Error: No unit') { if (name && name !== 'Error: No unit') {
return {name: name.trim(), fraction: fraction}; return {name: name, fraction: fraction};
} }
}; };