From 874292f2630fcfc8b4a6dace89a19920a41eae82 Mon Sep 17 00:00:00 2001 From: ShaunLWM Date: Sat, 11 May 2019 16:13:57 +0800 Subject: [PATCH] Refactor json readability --- index.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/index.js b/index.js index 0ad0edb..9d1dd18 100644 --- a/index.js +++ b/index.js @@ -41,22 +41,22 @@ class CSGOGSI extends EventEmitter { } process(data) { - if (typeof data.map !== "undefined") { - this.emit("gameMap", data.map.name); - this.emit("gamePhase", data.map.phase); //warmup etc - this.emit("gameRounds", data.map.round); - this.emit("gameCTscore", data.map.team_ct_score); - this.emit("gameTscore", data.map.team_t_score); + if (typeof data["map"] !== "undefined") { + this.emit("gameMap", data["map"]["name"]); + this.emit("gamePhase", data["map"]["phase"]); //warmup etc + this.emit("gameRounds", data["map"]["round"]); + this.emit("gameCTscore", data["map"]["team_ct_score"]); + this.emit("gameTscore", data["map"]["team_t_score"]); } - if (typeof data.player !== "undefined") { - this.emit("player", data.player); + if (typeof data["player"] !== "undefined") { + this.emit("player", data["player"]); } - if (typeof data.round !== "undefined") { + if (typeof data["round"] !== "undefined") { let maxTime = 0; - this.emit("roundPhase", data.round.phase); - switch (data.round.phase) { + this.emit("roundPhase", data["round"]["phase"]); + switch (data["round"]["phase"]) { case "live": maxTime = 115; break; @@ -69,17 +69,17 @@ class CSGOGSI extends EventEmitter { this.stopC4Countdown(); } - this.emit("roundWinTeam", data.round.win_team); + this.emit("roundWinTeam", data["round"]["win_team"]); break; } - if (typeof data.round.bomb !== "undefined") { - this.emit("bombState", data.round.bomb); - switch (data.round.bomb) { + if (typeof data["round"]["bomb"] !== "undefined") { + this.emit("bombState", data["round"]["bomb"]); + switch (data["round"]["bomb"]) { case "planted": if (!this.isBombPlanted) { this.isBombPlanted = true; - let timeleft = this.bombTime - (new Date().getTime() / 1000 - data.provider.timestamp); + let timeleft = this.bombTime - (new Date().getTime() / 1000 - data["provider"]["timestamp"]); this.emit("bombTimeStart", timeleft); this.startC4Countdown(timeleft); }