Skip to content

Commit

Permalink
Fixed crash on 3rd person
Browse files Browse the repository at this point in the history
  • Loading branch information
osztenkurden committed Sep 29, 2023
1 parent 40de9c9 commit 540f7e7
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 28 deletions.
11 changes: 6 additions & 5 deletions lib/cjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class CSGOGSI {
return this.descriptors.get(eventName) || [];
};
this.digest = (raw) => {
var _a, _b, _c, _d;
if (!raw.allplayers || !raw.map || !raw.phase_countdowns) {
return null;
}
Expand All @@ -108,12 +109,12 @@ class CSGOGSI {
const teamT = (0, utils_js_1.parseTeam)(raw.map.team_t, isCTLeft ? 'right' : 'left', 'T', isCTLeft ? this.teams.right : this.teams.left);
const playerMapper = (0, utils_js_1.mapSteamIDToPlayer)(raw.allplayers, { CT: teamCT, T: teamT }, this.players);
const players = Object.keys(raw.allplayers).map(playerMapper);
const observed = players.find(player => player.steamid === raw.player.steamid) || null;
const observed = players.find(player => raw.player && player.steamid === raw.player.steamid) || null;
const observer = {
activity: raw.player.activity,
spectarget: raw.player.spectarget,
position: raw.player.position.split(', ').map(n => Number(n)),
forward: raw.player.forward.split(', ').map(n => Number(n))
activity: (_a = raw.player) === null || _a === void 0 ? void 0 : _a.activity,
spectarget: (_b = raw.player) === null || _b === void 0 ? void 0 : _b.spectarget,
position: (_c = raw.player) === null || _c === void 0 ? void 0 : _c.position.split(', ').map(n => Number(n)),
forward: (_d = raw.player) === null || _d === void 0 ? void 0 : _d.forward.split(', ').map(n => Number(n))
};
const rounds = [];
if (raw.round && raw.map && raw.map.round_wins) {
Expand Down
10 changes: 5 additions & 5 deletions lib/esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ class CSGOGSI {
const teamT = parseTeam(raw.map.team_t, isCTLeft ? 'right' : 'left', 'T', isCTLeft ? this.teams.right : this.teams.left);
const playerMapper = mapSteamIDToPlayer(raw.allplayers, { CT: teamCT, T: teamT }, this.players);
const players = Object.keys(raw.allplayers).map(playerMapper);
const observed = players.find(player => player.steamid === raw.player.steamid) || null;
const observed = players.find(player => raw.player && player.steamid === raw.player.steamid) || null;
const observer = {
activity: raw.player.activity,
spectarget: raw.player.spectarget,
position: raw.player.position.split(', ').map(n => Number(n)),
forward: raw.player.forward.split(', ').map(n => Number(n))
activity: raw.player?.activity,
spectarget: raw.player?.spectarget,
position: raw.player?.position.split(', ').map(n => Number(n)),
forward: raw.player?.forward.split(', ').map(n => Number(n))
};
const rounds = [];
if (raw.round && raw.map && raw.map.round_wins) {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "csgogsi",
"version": "2.7.1",
"version": "2.7.2",
"description": "",
"type": "module",
"main": "./lib/cjs/index.js",
Expand Down
2 changes: 1 addition & 1 deletion tsc/csgo.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export interface CSGORaw {
provider: Provider;
map?: MapRaw;
round?: RoundRaw;
player: PlayerObservedRaw;
player?: PlayerObservedRaw;
allplayers?: PlayersRaw;
bomb?: BombRaw;
grenades?: {
Expand Down
10 changes: 5 additions & 5 deletions tsc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,13 @@ class CSGOGSI {
const playerMapper = mapSteamIDToPlayer(raw.allplayers, { CT: teamCT, T: teamT }, this.players);

const players = Object.keys(raw.allplayers).map(playerMapper);
const observed = players.find(player => player.steamid === raw.player.steamid) || null;
const observed = players.find(player => raw.player && player.steamid === raw.player.steamid) || null;

const observer: Observer = {
activity: raw.player.activity,
spectarget: raw.player.spectarget,
position: raw.player.position.split(', ').map(n => Number(n)),
forward: raw.player.forward.split(', ').map(n => Number(n))
activity: raw.player?.activity,
spectarget: raw.player?.spectarget,
position: raw.player?.position.split(', ').map(n => Number(n)),
forward: raw.player?.forward.split(', ').map(n => Number(n))
};

const rounds: RoundInfo[] = [];
Expand Down
8 changes: 4 additions & 4 deletions tsc/parsed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ export interface Round {
}

export interface Observer {
activity: 'playing' | 'textinput' | 'menu';
spectarget: 'free' | string;
position: number[];
forward: number[];
activity?: 'playing' | 'textinput' | 'menu';
spectarget?: 'free' | (string & {});
position?: number[];
forward?: number[];
}

export interface CSGO {
Expand Down
2 changes: 1 addition & 1 deletion types/csgo.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export interface CSGORaw {
provider: Provider;
map?: MapRaw;
round?: RoundRaw;
player: PlayerObservedRaw;
player?: PlayerObservedRaw;
allplayers?: PlayersRaw;
bomb?: BombRaw;
grenades?: {
Expand Down
8 changes: 4 additions & 4 deletions types/parsed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ export interface Round {
}

export interface Observer {
activity: 'playing' | 'textinput' | 'menu';
spectarget: 'free' | string;
position: number[];
forward: number[];
activity?: 'playing' | 'textinput' | 'menu';
spectarget?: 'free' | (string & {});
position?: number[];
forward?: number[];
}

export interface CSGO {
Expand Down

0 comments on commit 540f7e7

Please sign in to comment.