-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
77 lines (67 loc) · 3.08 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
var config = require('./config').Configuration;
var battlelog = require('./battlelog');
var locallog = require('./locallog');
var lastWeaponStats = locallog.loadObject(config.localWeaponFile);
battlelog.getSoldier(start);
function start() {
battlelog.getSoldierStats(getSoldierCallback);
battlelog.getWeaponStats(getWeaponsCallback);
}
function getSoldierCallback(soldierStats) {
for(var propName in soldierStats) {
if(soldierStats.hasOwnProperty(propName)) {
var propValue = soldierStats[propName];
console.log(propName + ': ' + propValue);
}
}
}
function getWeaponsCallback(weaponStats) {
var differences = checkWeaponStatsDifferences(weaponStats, lastWeaponStats)
console.log(differences.length);
differences.forEach(function (element) {
console.log(element.slug);
if (element.serviceStars) console.log('Service stars: ' + element.serviceStars);
if (element.kills) console.log('Kills: ' + element.kills);
if (element.headshots) console.log('Headshots: ' + element.headshots);
if (element.accuracy) console.log('Accuracy: ' + element.accuracy);
if (element.timeEquipped) console.log('timeEquipped: ' + element.timeEquipped);
}, this);
}
function checkWeaponStatsDifferences(battlelogData, locallogData) {
var differences = [];
battlelogData.forEach(function (battlelogElement) {
var locallogElement = getBattellogElement(locallogData, battlelogElement.slug);
if (locallogElement) {
var diffElement = {};
diffElement.slug = battlelogElement.slug;
diffElement.serviceStars = compareElements(battlelogElement.serviceStars, locallogElement.serviceStars);
diffElement.kills = compareElements(battlelogElement.kills, locallogElement.kills);
diffElement.headshots = compareElements(battlelogElement.headshots, locallogElement.headshots);
diffElement.accuracy = compareElements(battlelogElement.accuracy, locallogElement.accuracy);
diffElement.timeEquipped = compareElements(battlelogElement.timeEquipped, locallogElement.timeEquipped);
if (diffElement.serviceStars || diffElement.kills || diffElement.headshots || diffElement.accuracy || differences.timeEquipped)
differences.push(diffElement);
}
}, this);
return differences;
}
function getBattellogElement(locallogData, slug) {
if (locallogData) {
for (var i = 0; i < locallogData.length; i++) {
var element = locallogData[i];
if (element.slug == slug) {
return element;
}
}
} else {
return null;
}
}
function compareElements(battlelogDataValue, locallogDataValue) {
var battlelogDataValueNumber = Number(battlelogDataValue);
var locallogDataValueNumber = Number(locallogDataValue);
if (battlelogDataValueNumber - locallogDataValueNumber != 0) {
return battlelogDataValueNumber - locallogDataValueNumber;
} else
return null;
}