Use player map for scoreboard players

pull/18/head
HardiReady 2017-11-06 14:22:18 +01:00
parent 36a1166cae
commit 403b6d8f34
1 changed files with 19 additions and 18 deletions

View File

@ -17,13 +17,12 @@ const parseWarLog = (lineArray, war) => {
players: [] players: []
}; };
const addPlayersIfNotExists = (inputPlayers) => { const addPlayerIfNotExists = (inputPlayer) => {
inputPlayers.forEach(player => { 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;
stats.players.push(player); stats.players.push(player);
} }
})
}; };
lineArray.some(line => { lineArray.some(line => {
@ -52,14 +51,12 @@ const parseWarLog = (lineArray, war) => {
friendlyFire: shooter ? target.fraction === shooter.fraction : false, friendlyFire: shooter ? target.fraction === shooter.fraction : false,
fraction: shooter ? shooter.fraction : 'NONE' fraction: shooter ? shooter.fraction : 'NONE'
}); });
addPlayersIfNotExists([shooter, target]);
} }
/** /**
* BUDGET * BUDGET
*/ */
if (line.includes('Budget')) { else if (line.includes('Budget')) {
stats.clean.push(line); stats.clean.push(line);
const budg = line.split(' '); const budg = line.split(' ');
if (line.includes('Endbudget')) { if (line.includes('Endbudget')) {
@ -79,7 +76,7 @@ const parseWarLog = (lineArray, war) => {
/** /**
* FLAG * FLAG
*/ */
if (line.includes('Fahne')) { else if (line.includes('Fahne')) {
stats.clean.push(line); stats.clean.push(line);
const playerName = line.substring(line.lastIndexOf('t von ') + 6, line.lastIndexOf(' :OPT LOG END')); const playerName = line.substring(line.lastIndexOf('t von ') + 6, line.lastIndexOf(' :OPT LOG END'));
const flagFraction = line.includes('NATO Flagge') ? 'BLUFOR' : 'OPFOR'; const flagFraction = line.includes('NATO Flagge') ? 'BLUFOR' : 'OPFOR';
@ -97,7 +94,7 @@ const parseWarLog = (lineArray, war) => {
/** /**
* POINTS * POINTS
*/ */
if (line.includes('Punkte')) { else if (line.includes('Punkte')) {
stats.clean.push(line); stats.clean.push(line);
const pt = line.split(' '); const pt = line.split(' ');
@ -114,7 +111,7 @@ const parseWarLog = (lineArray, war) => {
/** /**
* RESPAWN * RESPAWN
*/ */
if (line.includes('Respawn')) { else if (line.includes('Respawn')) {
stats.clean.push(line); stats.clean.push(line);
const resp = line.split(' '); const resp = line.split(' ');
const playerName = line.substring(line.lastIndexOf('Spieler:') + 9, line.lastIndexOf('-') - 1); const playerName = line.substring(line.lastIndexOf('Spieler:') + 9, line.lastIndexOf('-') - 1);
@ -124,7 +121,7 @@ const parseWarLog = (lineArray, war) => {
/** /**
* REVIVE * REVIVE
*/ */
if (line.includes('Revive')) { else if (line.includes('Revive')) {
stats.clean.push(line); stats.clean.push(line);
const stabilized = !!line.includes('stabilisiert'); const stabilized = !!line.includes('stabilisiert');
const medicName = line.substring(line.lastIndexOf('wurde von ') + 10, const medicName = line.substring(line.lastIndexOf('wurde von ') + 10,
@ -141,14 +138,12 @@ const parseWarLog = (lineArray, war) => {
patient: patient.name, patient: patient.name,
fraction: medic.fraction fraction: medic.fraction
}); });
addPlayersIfNotExists([medic, patient]);
} }
/** /**
* TRANSPORT * TRANSPORT
*/ */
if (line.includes('Transport ||')) { else if (line.includes('Transport ||')) {
stats.clean.push(line); stats.clean.push(line);
const driverString = line.substring(line.lastIndexOf('wurde von ') + 10, line.lastIndexOf(' eingeflogen')); const driverString = line.substring(line.lastIndexOf('wurde von ') + 10, line.lastIndexOf(' eingeflogen'));
const driver = getPlayerAndFractionFromString(driverString); const driver = getPlayerAndFractionFromString(driverString);
@ -164,8 +159,14 @@ const parseWarLog = (lineArray, war) => {
fraction: driver.fraction, fraction: driver.fraction,
distance: distance distance: distance
}); });
}
addPlayersIfNotExists([driver, passenger]); /**
* PLAYERS
*/
else if (line.includes('Fraktionsübersicht ||')) {
const playerString = line.substring(line.lastIndexOf('Fraktionsübersicht || ') + 22, line.lastIndexOf(' :OPT LOG END'));
addPlayerIfNotExists(playerString)
} }
}); });