ensl_gathers/lib/hive/stats_wrapper.js

30 lines
1.2 KiB
JavaScript
Raw Normal View History

2016-11-15 10:54:44 +00:00
"use strict";
2023-03-05 13:07:36 +00:00
// UserStatistics constructor parses Steam ISteamUserStats responses into
2016-11-15 10:54:44 +00:00
// unified statistical interface
2023-03-05 13:07:36 +00:00
// StatAttributes also provides default value as fallback
2016-11-15 10:54:44 +00:00
const StatAttributes = {
2023-03-05 13:07:36 +00:00
level: (stats, apiValue) => { stats['level'] = apiValue },
score: (stats, apiValue) => { stats['score'] = apiValue },
skill: (stats, apiValue) => { stats['score'] = apiValue },
td_rounds_won_player: (stats, apiValue) => {stats['player_wins'] = apiValue },
td_rounds_won_commander: (stats, apiValue) => {stats['comm_wins'] = apiValue },
skill: (stats, apiValue) => {stats['skill'] = apiValue },
comm_skill: (stats, apiValue) => {stats['comm_skill'] = apiValue },
td_total_time_player: (stats, apiValue) => {stats['player_time'] = apiValue },
td_total_time_commander: (stats, apiValue) => {stats['commander_time'] = apiValue },
2016-11-15 10:54:44 +00:00
};
2023-03-05 13:07:36 +00:00
const NoopSetter = (_stats, _apiValue) => {};
2016-11-15 10:54:44 +00:00
function UserStatisticsWrapper (apiResponse = {}) {
2023-03-05 13:07:36 +00:00
this["steamId"] = apiResponse.steamID
var stats = apiResponse.stats || {};
for(attribute in stats) {
var setter = StatAttributes[attribute.name] || NoopSetter;
setter(this,attribute.value);
2016-11-15 10:54:44 +00:00
}
}
module.exports = UserStatisticsWrapper;