perf: remove some if statements in gamespy 2
This commit is contained in:
parent
96289b2b00
commit
fb6a5a1c7a
|
@ -10,6 +10,7 @@
|
||||||
* TeamSpeak 2 - Fixed how `state.name` is set (By @podrivo #544)
|
* TeamSpeak 2 - Fixed how `state.name` is set (By @podrivo #544)
|
||||||
* Grand Theft Auto: San Andreas OpenMP - Fixed `state.players` returning an empty array (By @Focus04 #547)
|
* Grand Theft Auto: San Andreas OpenMP - Fixed `state.players` returning an empty array (By @Focus04 #547)
|
||||||
* Perf: Re-write of the `core` class.
|
* Perf: Re-write of the `core` class.
|
||||||
|
* Perf: Remove many if statements from `GameSpy2`.
|
||||||
|
|
||||||
## 5.0.0-beta.2
|
## 5.0.0-beta.2
|
||||||
* Fixed support for projects using `require`.
|
* Fixed support for projects using `require`.
|
||||||
|
|
|
@ -110,26 +110,23 @@ export default class gamespy2 extends Core {
|
||||||
const units = []
|
const units = []
|
||||||
while (!reader.done()) {
|
while (!reader.done()) {
|
||||||
const unit = {}
|
const unit = {}
|
||||||
for (let iField = 0; iField < fields.length; iField++) {
|
for (let index = 0; index < fields.length; index++) {
|
||||||
let key = fields[iField]
|
let key = fields[index]
|
||||||
let value = reader.string()
|
let value = reader.string()
|
||||||
if (!value && iField === 0) return units
|
if (!value && index === 0) return units
|
||||||
|
|
||||||
this.logger.debug('value:' + value)
|
this.logger.debug('value:' + value)
|
||||||
if (key === 'player_') key = 'name'
|
|
||||||
else if (key === 'score_') key = 'score'
|
// many fields end with "_"
|
||||||
else if (key === 'deaths_') key = 'deaths'
|
if (key.endsWith('_')) {
|
||||||
else if (key === 'ping_') key = 'ping'
|
key = key.slice(0, -1)
|
||||||
else if (key === 'team_') key = 'team'
|
}
|
||||||
else if (key === 'kills_') key = 'kills'
|
|
||||||
|
if (key === 'player') key = 'name'
|
||||||
else if (key === 'team_t') key = 'name'
|
else if (key === 'team_t') key = 'name'
|
||||||
else if (key === 'tickets_t') key = 'tickets'
|
else if (key === 'tickets_t') key = 'tickets'
|
||||||
|
|
||||||
if (
|
if (['score', 'deaths', 'ping', 'team', 'kills', 'tickets'].includes(key)) {
|
||||||
key === 'score' || key === 'deaths' ||
|
|
||||||
key === 'ping' || key === 'team' ||
|
|
||||||
key === 'kills' || key === 'tickets'
|
|
||||||
) {
|
|
||||||
if (value === '') continue
|
if (value === '') continue
|
||||||
value = parseInt(value)
|
value = parseInt(value)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue