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