Fix vehicle kill parsing

pull/35/head
HardiReady 2018-06-06 18:45:25 +02:00
parent f3f5638667
commit 58d0c781a2
2 changed files with 95 additions and 81 deletions

View File

@ -13,11 +13,15 @@ const VehicleClasses = Object.freeze({
const playerNameRegex = /^(.*?)\s\(/; const playerNameRegex = /^(.*?)\s\(/;
const vehicleNameEndRegex = /\s\(\w+:/;
const sideRegex = /(side:\s(.*?)\))/; const sideRegex = /(side:\s(.*?)\))/;
const magazineRegex = /(magazine:\s(.*?)\))/; // const magazineRegex = /(magazine:\s(.*?)\))/;
const vehicleRegex = /(vehicle:\s(.*?)\))/; // const vehicleRegex = /(vehicle:\s(.*?)\))/;
const categoryRegex = /(category:\s(.*?)\))/;
const parseWarLog = (lineArray, war) => { const parseWarLog = (lineArray, war) => {
const NAME_TOO_LONG_ERROR = 'Error: ENAMETOOLONG: name too long, open \''; const NAME_TOO_LONG_ERROR = 'Error: ENAMETOOLONG: name too long, open \'';
@ -47,7 +51,6 @@ const parseWarLog = (lineArray, war) => {
]; ];
const addPlayerIfNotExists = (inputPlayer, steamUUID) => { const addPlayerIfNotExists = (inputPlayer, steamUUID) => {
console.log(inputPlayer)
const player = getPlayerAndFractionFromString(inputPlayer); const player = getPlayerAndFractionFromString(inputPlayer);
if (player && player.name && player.fraction && !playerArrayContains(stats.players, player)) { if (player && player.name && player.fraction && !playerArrayContains(stats.players, player)) {
player['warId'] = war._id; player['warId'] = war._id;
@ -276,8 +279,8 @@ 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 magazineMatch = magazineRegex.exec(inputString);
const vehicleMatch = vehicleRegex.exec(inputString); // const vehicleMatch = vehicleRegex.exec(inputString);
let name; let name;
if (playerNameRegexMatch && playerNameRegexMatch.length >= 2) { if (playerNameRegexMatch && playerNameRegexMatch.length >= 2) {
@ -285,30 +288,30 @@ const getPlayerAndFractionFromString = (inputString) => {
name = playerNameRegexMatch[1]; name = playerNameRegexMatch[1];
} }
let side let side;
if (sideMatch && sideMatch.length >= 3) { if (sideMatch && sideMatch.length >= 3) {
// SIDE // SIDE
side = sideMatch[2]; side = sideMatch[2];
} else { } else {
const inputArray = inputString.split(WHITESPACE) const inputArray = inputString.split(WHITESPACE);
if (inputArray && inputArray.length === 2) { if (inputArray) {
side = inputArray[ 1 ].replace('(', '').replace(')', ''); side = inputArray[inputArray.length - 1].replace('(', '').replace(')', '');
} }
} }
if (magazineMatch && magazineMatch.length >= 3) { // if (magazineMatch && magazineMatch.length >= 3) {
// MAGAZINE // MAGAZINE
// console.log(magazineMatch[2]) // console.log(magazineMatch[2])
} // }
if (vehicleMatch && vehicleMatch.length >= 3 && vehicleMatch[ 2 ]) { // if (vehicleMatch && vehicleMatch.length >= 3 && vehicleMatch[2]) {
let vehicle = vehicleMatch[ 2 ]; // let vehicle = vehicleMatch[2];
if (new RegExp("\\(.*$").test(vehicle)) { // if (new RegExp("\\(.*$").test(vehicle)) {
vehicle = vehicle.concat(")"); // vehicle = vehicle.concat(")");
} // }
// VEHICLE // VEHICLE
// console.log(vehicle) // console.log(vehicle)
} // }
let fraction; let fraction;
if (side) { if (side) {
@ -324,21 +327,30 @@ const getPlayerAndFractionFromString = (inputString) => {
}; };
const getVehicleAndFractionFromString = (nameClassFractionString) => { const getVehicleAndFractionFromString = (nameClassFractionString) => {
const nameArray = nameClassFractionString.trim().split(WHITESPACE); const sideMatch = sideRegex.exec(nameClassFractionString);
const vehicleFraction = nameArray[ nameArray.length - 1 ].slice(0, -1); const categoryMatch = categoryRegex.exec(nameClassFractionString);
nameArray.pop();
nameArray.pop();
const vehicleClassString = nameArray[ nameArray.length - 1 ].replace('(', '').replace(')', '');
nameArray.pop();
nameArray.pop();
const vehicleName = nameArray.join(WHITESPACE);
// skip logging here - this is some basic equipment identifier (i.e. parachute) // NAME
if (vehicleFraction === 'OPF_F' || vehicleFraction === 'BLU_F' || vehicleClassString === VehicleClasses.UNKNOWN) { const vehicleName = nameClassFractionString.substring(0,
return; nameClassFractionString.indexOf(vehicleNameEndRegex.exec(nameClassFractionString)));
let fraction;
if (sideMatch && sideMatch.length >= 3) {
// SIDE
const side = sideMatch[2];
fraction = side === 'OPT_NATO' || side === 'OPT_NATO_T' || side === 'WEST' ? 'BLUFOR' : 'OPFOR';
} }
const fraction = vehicleFraction === '(OPT_NATO)' || vehicleFraction === '(OPT_NATO_T)' ? 'BLUFOR' : 'OPFOR'; let vehicleClassString;
if (categoryMatch && categoryMatch.length >= 3) {
// CATEGORY
vehicleClassString = categoryMatch[2];
}
// skip logging here - this is some basic equipment identifier (i.e. parachute)
if (fraction === 'OPF_F' || fraction === 'BLU_F' || vehicleClassString === VehicleClasses.UNKNOWN) {
return;
}
let vehicleClass; let vehicleClass;
for (const key in VehicleClasses) { for (const key in VehicleClasses) {
@ -347,11 +359,13 @@ const getVehicleAndFractionFromString = (nameClassFractionString) => {
} }
} }
if (vehicleName && fraction && vehicleClass) {
return { return {
name: vehicleName, name: vehicleName,
fraction: fraction, fraction: fraction,
vehicleClass: vehicleClass, vehicleClass: vehicleClass,
}; };
}
}; };
const transformMoneyString = (budgetString) => { const transformMoneyString = (budgetString) => {

View File

@ -1,4 +1,4 @@
<code_scheme name="OPT-CC" version="173"> <code_scheme name="OPT-CC copy" version="173">
<option name="FORMATTER_TAGS_ENABLED" value="true" /> <option name="FORMATTER_TAGS_ENABLED" value="true" />
<JSCodeStyleSettings> <JSCodeStyleSettings>
<option name="USE_CHAINED_CALLS_GROUP_INDENTS" value="true" /> <option name="USE_CHAINED_CALLS_GROUP_INDENTS" value="true" />