Skip to content

Commit

Permalink
close #141: add fallback for bad GSI inferno flame positions
Browse files Browse the repository at this point in the history
  • Loading branch information
drweissbrot committed Mar 2, 2024
1 parent 1b943ef commit 9bc1380
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
This project does not adhere to Semantic Versioning.

## [Unreleased]
### Added
* Added fallback for wrong GSI-reported inferno flame positions


## [2.4.0] - 2024-02-04
Expand Down
19 changes: 17 additions & 2 deletions src/themes/raw/gsi/parse-grenades.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { gsiState, players } from '/hud/core/state.js'
import { parsePosition } from '/hud/gsi/parse-position.js'
import { vectorDistance } from '/hud/helpers/vector-distance.js'

const cachedFirebombTypes = {}

Expand All @@ -22,15 +23,29 @@ const getFirebombType = (grenadeId, owner) => {
}
}

const parseInfernoFlameIdToPosition = (flameId) => flameId.replace(/^flame_/i, '').replace(/p/gi, '').replace(/n/gi, '-').split('_').map((n) => Number(n))

const additionalGrenadeData = (grenade, grenadeId, owner) => {
switch (grenade.type) {
case 'inferno':
case 'inferno': {
// GSI sometimes reports inferno flames at wildly inaccurate positions; their IDs include
// position data with less precision, but they seem to always at least be at least close
// to where they should be
const roughPositionFromFlameId = parseInfernoFlameIdToPosition(Object.keys(grenade.flames)[0])
const firstFlamePosition = parsePosition(Object.values(grenade.flames)[0])
const distanceBetweenLastProjectileAndFirstFlame = vectorDistance(roughPositionFromFlameId, firstFlamePosition)

const positionCallback = distanceBetweenLastProjectileAndFirstFlame > 512
? (id, position) => parseInfernoFlameIdToPosition(id)
: (id, position) => parsePosition(position)

return {
flames: Object.entries(grenade.flames).map(([id, position]) => ({
id,
position: parsePosition(position),
position: positionCallback(id, position),
}))
}
}

case 'firebomb':
return {
Expand Down

0 comments on commit 9bc1380

Please sign in to comment.