diff --git a/lib/cjs/csgo.d.ts b/lib/cjs/csgo.d.ts new file mode 100644 index 0000000..c185744 --- /dev/null +++ b/lib/cjs/csgo.d.ts @@ -0,0 +1,151 @@ +export type Side = 'CT' | 'T'; +export type RoundOutcome = 'ct_win_elimination' | 't_win_elimination' | 'ct_win_time' | 'ct_win_defuse' | 't_win_bomb'; + +export type WeaponType = 'Knife' | 'Pistol' | 'Grenade' | 'Rifle' | 'SniperRifle' | 'C4' | 'Submachine Gun'; + +export interface WeaponRaw { + name: string; + paintkit: string; + type?: WeaponType; + ammo_clip?: number; + ammo_clip_max?: number; + ammo_reserve?: number; + state: 'active' | 'holstered'; +} + +export interface TeamRaw { + score: number; + consecutive_round_losses: number; + timeouts_remaining: number; + matches_won_this_series: number; + name?: string; + flag?: string; +} + +export interface PlayerRaw { + steamid?: string; + name: string; + clan?: string; + observer_slot?: number; + team: Side; + match_stats: { + kills: number; + assists: number; + deaths: number; + mvps: number; + score: number; + }; + weapons: { + [key: string]: WeaponRaw; + }; + state: { + health: number; + armor: number; + helmet: boolean; + defusekit?: boolean; + flashed: number; + smoked?: number; + burning: number; + money: number; + round_kills: number; + round_killhs: number; + round_totaldmg: number; + equip_value: number; + }; + position: string; + forward: string; +} + +export interface PlayerObservedRaw { + steamid: string; + clan?: string; + name: string; + observer_slot?: number; + team?: Side; + activity: 'playing' | 'textinput' | 'menu'; + state: { + health: number; + armor: number; + helmet: boolean; + flashed: number; + smoked: number; + burning: number; + money: number; + round_kills: number; + round_killhs: number; + round_totaldmg: number; + equip_value: number; + }; + spectarget: 'free' | string; + position: string; + forward: string; +} + +export interface PlayersRaw { + [key: string]: PlayerRaw; +} + +export interface Provider { + name: 'Counter-Strike: Global Offensive'; + appid: 730; + version: number; + steamid: string; + timestamp: number; +} + +export interface MapRaw { + mode: 'competitive'; + name: string; + phase: 'warmup' | 'live' | 'intermission' | 'gameover'; + round: number; + team_ct: TeamRaw; + team_t: TeamRaw; + num_matches_to_win_series: number; + current_spectators: number; + souvenirs_total: number; + round_wins: { + [key: string]: RoundOutcome; + }; +} + +export interface RoundRaw { + phase: 'freezetime' | 'live' | 'over'; + bomb?: 'planted' | 'exploded' | 'defused'; + win_team?: Side; +} + +export interface BombRaw { + state: 'carried' | 'planted' | 'dropped' | 'defused' | 'defusing' | 'planting' | 'exploded'; + countdown?: string; + player?: string; + position: string; +} +export interface PhaseRaw { + phase?: 'freezetime' | 'bomb' | 'warmup' | 'live' | 'over' | 'defuse' | 'paused' | 'timeout_ct' | 'timeout_t'; + phase_ends_in: string; +} + +export interface CSGORaw { + provider: Provider; + map?: MapRaw; + round?: RoundRaw; + player?: PlayerObservedRaw; + allplayers?: PlayersRaw; + bomb?: BombRaw; + grenades?: { + [key: string]: any; + /*{ + owner:number, + position:string, + velocity:string, + lifetime:string, + type:string, + effecttime?:string + }*/ + }; + previously?: any; + phase_countdowns?: PhaseRaw; + auth?: { + token: string; + }; +} diff --git a/lib/cjs/events.d.ts b/lib/cjs/events.d.ts new file mode 100644 index 0000000..1e83240 --- /dev/null +++ b/lib/cjs/events.d.ts @@ -0,0 +1,38 @@ +import * as I from './interfaces'; + +export interface Events { + raw: (data: I.CSGORaw) => void; + data: (data: I.CSGO) => void; + roundEnd: (team: I.Score) => void; + matchEnd: (score: I.Score) => void; + kill: (kill: I.KillEvent) => void; + hurt: (kill: I.HurtEvent) => void; + timeoutStart: (team: any) => void; + timeoutEnd: () => void; + /*roundStart: (round: number) => void, + warmupStart: () => void, + warmupEnd: () => void,*/ + mvp: (player: I.Player) => void; + freezetimeStart: () => void; + freezetimeEnd: () => void; + intermissionStart: () => void; + intermissionEnd: () => void; + defuseStart: (player: I.Player) => void; + defuseStop: (player: I.Player) => void; + bombPlantStart: (player: I.Player) => void; + bombPlant: (player: I.Player) => void; + bombExplode: () => void; + bombDefuse: (player: I.Player) => void; + newListener: (eventName: K, listener: Events[K]) => void; + removeListener: (eventName: K, listener: Events[K]) => void; +} + +export type AnyEventName = T | (string & {}); + +export type BaseEvents = keyof Events; + +export type EventNames = AnyEventName; + +export type EmptyListener = () => void; + +export type Callback = K extends BaseEvents ? Events[K] | EmptyListener : EmptyListener; diff --git a/lib/cjs/index.d.ts b/lib/cjs/index.d.ts new file mode 100644 index 0000000..c3b8626 --- /dev/null +++ b/lib/cjs/index.d.ts @@ -0,0 +1,120 @@ +import { + CSGO, + CSGORaw, + Events, + KillEvent, + PlayerExtension, + RawKill, + Score, + TeamExtension, + Callback, + EventNames, + BaseEvents +} from './interfaces'; +import { RawHurt } from './mirv'; +import { DigestMirvType, HurtEvent } from './parsed'; +import { mapSteamIDToPlayer, parseTeam, getHalfFromRound, didTeamWinThatRound } from './utils.js'; +interface EventDescriptor { + listener: Events[BaseEvents]; + once: boolean; +} +declare type RoundPlayerDamage = { + steamid: string; + damage: number; +}; +declare type RoundDamage = { + round: number; + players: RoundPlayerDamage[]; +}; +declare class CSGOGSI { + private descriptors; + private maxListeners; + teams: { + left: TeamExtension | null; + right: TeamExtension | null; + }; + damage: RoundDamage[]; + players: PlayerExtension[]; + overtimeMR: number; + regulationMR: number; + last?: CSGO; + current?: CSGO; + constructor(); + eventNames: () => EventNames[]; + getMaxListeners: () => number; + listenerCount: (eventName: EventNames) => number; + listeners: ( + eventName: EventNames + ) => ( + | ((data: CSGORaw) => void) + | ((data: CSGO) => void) + | ((team: Score) => void) + | ((score: Score) => void) + | ((kill: KillEvent) => void) + | ((kill: HurtEvent) => void) + | ((team: any) => void) + | (() => void) + | ((player: import('./parsed').Player) => void) + | (() => void) + | (() => void) + | (() => void) + | (() => void) + | ((player: import('./parsed').Player) => void) + | ((player: import('./parsed').Player) => void) + | ((player: import('./parsed').Player) => void) + | ((player: import('./parsed').Player) => void) + | (() => void) + | ((player: import('./parsed').Player) => void) + | ((eventName: K, listener: Events[K]) => void) + | ((eventName: K_1, listener: Events[K_1]) => void) + )[]; + removeListener: (eventName: K, listener: Callback) => this; + off: (eventName: K, listener: Callback) => this; + addListener: (eventName: K, listener: Callback) => this; + on: (eventName: K, listener: Callback) => this; + once: (eventName: K, listener: Callback) => this; + prependListener: (eventName: K, listener: Callback) => this; + emit: (eventName: EventNames, arg?: any, arg2?: any) => boolean; + prependOnceListener: (eventName: K, listener: Callback) => this; + removeAllListeners: (eventName: EventNames) => this; + setMaxListeners: (n: number) => this; + rawListeners: (eventName: EventNames) => EventDescriptor[]; + digest: (raw: CSGORaw) => CSGO | null; + digestMIRV: (raw: RawKill | RawHurt, eventType?: string) => DigestMirvType; + static findSite(mapName: string, position: number[]): 'A' | 'B' | null; +} +export { CSGOGSI, mapSteamIDToPlayer, parseTeam, getHalfFromRound, didTeamWinThatRound, RoundDamage }; +export { + CSGO, + CSGORaw, + Side, + RoundOutcome, + WeaponType, + Observer, + RawHurt, + WeaponRaw, + TeamRaw, + PlayerRaw, + PlayerObservedRaw, + PlayersRaw, + Provider, + HurtEvent, + RoundWins, + MapRaw, + RoundRaw, + BombRaw, + PhaseRaw, + Events, + Team, + Player, + Bomb, + Map, + Round, + Score, + KillEvent, + RawKill, + TeamExtension, + RoundInfo, + PlayerExtension, + Orientation +} from './interfaces'; diff --git a/lib/cjs/interfaces.d.ts b/lib/cjs/interfaces.d.ts new file mode 100644 index 0000000..432580a --- /dev/null +++ b/lib/cjs/interfaces.d.ts @@ -0,0 +1,23 @@ +export * from './csgo'; +export * from './events'; +export * from './parsed'; +export * from './mirv'; + +export interface TeamExtension { + id: string; + name: string; + country: string | null; + logo: string | null; + map_score: number; + extra: Record; +} + +export interface PlayerExtension { + id: string; + name: string; + steamid: string; + realName: string | null; + country: string | null; + avatar: string | null; + extra: Record; +} diff --git a/lib/cjs/mirv.d.ts b/lib/cjs/mirv.d.ts new file mode 100644 index 0000000..37bde14 --- /dev/null +++ b/lib/cjs/mirv.d.ts @@ -0,0 +1,53 @@ +export interface RawKill { + name: 'player_death'; + clientTime: number; + keys: { + userid: { + value: number; + xuid: string; + }; + attacker: { + value: number; + xuid: string; + }; + assister: { + value: number; + xuid: string; + }; + assistedflash: boolean; + weapon: string; + weapon_itemid: string; + weapon_fauxitemid: string; + weapon_originalowner_xuid: string; + headshot: boolean; + dominated: number; + revenge: number; + wipe: number; + attackerblind: boolean; + thrusmoke: boolean; + noscope: boolean; + penetrated: number; + noreplay: boolean; + }; +} + +export interface RawHurt { + name: 'player_hurt'; + clientTime: number; + keys: { + userid: { + value: number; + xuid: string; + }; + attacker: { + value: number; + xuid: string; + }; + health: number; + armor: number; + weapon: string; + dmg_health: number; + dmg_armor: number; + hitgroup: number; + }; +} diff --git a/lib/cjs/parsed.d.ts b/lib/cjs/parsed.d.ts new file mode 100644 index 0000000..9906e85 --- /dev/null +++ b/lib/cjs/parsed.d.ts @@ -0,0 +1,152 @@ +import * as I from './interfaces'; + +export type Orientation = 'left' | 'right'; + +export interface Team { + logo: string | null; + score: number; + consecutive_round_losses: number; + timeouts_remaining: number; + matches_won_this_series: number; + side: I.Side; + name: string; + country: string | null; + id: string | null; + orientation: Orientation; + extra: Record; +} + +export interface RoundInfo { + team: Team; + round: number; + side: I.Side; + outcome: I.RoundOutcome; +} +export interface Player { + steamid: string; + name: string; + defaultName: string; + clan?: string; + observer_slot?: number; + team: Team; + stats: { + kills: number; + assists: number; + deaths: number; + mvps: number; + score: number; + }; + weapons: { + [key: string]: I.WeaponRaw; + }; + state: { + health: number; + armor: number; + helmet: boolean; + defusekit?: boolean; + flashed: number; + smoked: number; + burning: number; + money: number; + round_kills: number; + round_killhs: number; + round_totaldmg: number; + equip_value: number; + adr: number; + }; + position: number[]; + forward: number[]; + avatar: string | null; + country: string | null; + realName: string | null; + extra: Record; +} + +export type RoundWins = { + [key: string]: I.RoundOutcome; +}; +export interface Bomb { + state: 'carried' | 'planted' | 'dropped' | 'defused' | 'defusing' | 'planting' | 'exploded'; + countdown?: string; + player?: Player; + site: 'A' | 'B' | null; + position: number[]; +} + +export interface Map { + mode: string; + name: string; + phase: 'warmup' | 'live' | 'intermission' | 'gameover'; + round: number; + team_ct: Team; + team_t: Team; + num_matches_to_win_series: number; + current_spectators: number; + souvenirs_total: number; + round_wins: RoundWins; + rounds: I.RoundInfo[]; +} + +export interface Round { + phase: 'freezetime' | 'live' | 'over'; + bomb?: 'planted' | 'exploded' | 'defused'; + win_team?: I.Side; +} + +export interface Observer { + activity?: 'playing' | 'textinput' | 'menu'; + spectarget?: 'free' | (string & {}); + position?: number[]; + forward?: number[]; +} + +export interface CSGO { + provider: I.Provider; + map: Map; + round: Round | null; + observer: Observer; + player: Player | null; + players: Player[]; + bomb: Bomb | null; + grenades?: { + [key: string]: any; + }; + previously?: any; + phase_countdowns: I.PhaseRaw; + auth?: { + token: string; + }; +} +export interface Score { + winner: I.Team; + loser: I.Team; + map: Map; + mapEnd: boolean; +} + +export interface KillEvent { + killer: Player | null; + victim: Player; + assister: Player | null; + flashed: boolean; + headshot: boolean; + weapon: string; + wallbang: boolean; + attackerblind: boolean; + thrusmoke: boolean; + noscope: boolean; +} + +export interface HurtEvent { + attacker: Player; + victim: Player; + health: number; + armor: number; + weapon: string; + dmg_health: number; + dmg_armor: number; + hitgroup: number; +} + +//export type DigestMirvType = ((kill: RawKill, eventType: 'player_death') => KillEvent | null) | ((hurt: RawHurt, eventType: 'player_hurt') => HurtEvent | null) +export type DigestMirvType = KillEvent | HurtEvent | null; diff --git a/lib/cjs/utils.d.ts b/lib/cjs/utils.d.ts new file mode 100644 index 0000000..0b029b7 --- /dev/null +++ b/lib/cjs/utils.d.ts @@ -0,0 +1,46 @@ +import { + Team, + PlayerExtension, + Player, + PlayersRaw, + Side, + Orientation, + TeamExtension, + TeamRaw, + RoundInfo, + RoundWins +} from '.'; +export declare const mapSteamIDToPlayer: ( + players: PlayersRaw, + teams: { + CT: Team; + T: Team; + }, + extensions: PlayerExtension[] +) => (steamid: string) => Player; +export declare const parseTeam: ( + team: TeamRaw, + orientation: Orientation, + side: Side, + extension: TeamExtension | null +) => Team; +export declare const getHalfFromRound: (round: number, regulationMR: number, mr: number) => number; +export declare const didTeamWinThatRound: ( + team: Team, + round: number, + wonBy: Side, + currentRound: number, + regulationMR: number, + mr: number +) => boolean; +export declare const getRoundWin: ( + mapRound: number, + teams: { + ct: Team; + t: Team; + }, + roundWins: RoundWins, + round: number, + regulationMR: number, + overtimeMR: number +) => RoundInfo | null; diff --git a/lib/esm/csgo.d.ts b/lib/esm/csgo.d.ts new file mode 100644 index 0000000..c185744 --- /dev/null +++ b/lib/esm/csgo.d.ts @@ -0,0 +1,151 @@ +export type Side = 'CT' | 'T'; +export type RoundOutcome = 'ct_win_elimination' | 't_win_elimination' | 'ct_win_time' | 'ct_win_defuse' | 't_win_bomb'; + +export type WeaponType = 'Knife' | 'Pistol' | 'Grenade' | 'Rifle' | 'SniperRifle' | 'C4' | 'Submachine Gun'; + +export interface WeaponRaw { + name: string; + paintkit: string; + type?: WeaponType; + ammo_clip?: number; + ammo_clip_max?: number; + ammo_reserve?: number; + state: 'active' | 'holstered'; +} + +export interface TeamRaw { + score: number; + consecutive_round_losses: number; + timeouts_remaining: number; + matches_won_this_series: number; + name?: string; + flag?: string; +} + +export interface PlayerRaw { + steamid?: string; + name: string; + clan?: string; + observer_slot?: number; + team: Side; + match_stats: { + kills: number; + assists: number; + deaths: number; + mvps: number; + score: number; + }; + weapons: { + [key: string]: WeaponRaw; + }; + state: { + health: number; + armor: number; + helmet: boolean; + defusekit?: boolean; + flashed: number; + smoked?: number; + burning: number; + money: number; + round_kills: number; + round_killhs: number; + round_totaldmg: number; + equip_value: number; + }; + position: string; + forward: string; +} + +export interface PlayerObservedRaw { + steamid: string; + clan?: string; + name: string; + observer_slot?: number; + team?: Side; + activity: 'playing' | 'textinput' | 'menu'; + state: { + health: number; + armor: number; + helmet: boolean; + flashed: number; + smoked: number; + burning: number; + money: number; + round_kills: number; + round_killhs: number; + round_totaldmg: number; + equip_value: number; + }; + spectarget: 'free' | string; + position: string; + forward: string; +} + +export interface PlayersRaw { + [key: string]: PlayerRaw; +} + +export interface Provider { + name: 'Counter-Strike: Global Offensive'; + appid: 730; + version: number; + steamid: string; + timestamp: number; +} + +export interface MapRaw { + mode: 'competitive'; + name: string; + phase: 'warmup' | 'live' | 'intermission' | 'gameover'; + round: number; + team_ct: TeamRaw; + team_t: TeamRaw; + num_matches_to_win_series: number; + current_spectators: number; + souvenirs_total: number; + round_wins: { + [key: string]: RoundOutcome; + }; +} + +export interface RoundRaw { + phase: 'freezetime' | 'live' | 'over'; + bomb?: 'planted' | 'exploded' | 'defused'; + win_team?: Side; +} + +export interface BombRaw { + state: 'carried' | 'planted' | 'dropped' | 'defused' | 'defusing' | 'planting' | 'exploded'; + countdown?: string; + player?: string; + position: string; +} +export interface PhaseRaw { + phase?: 'freezetime' | 'bomb' | 'warmup' | 'live' | 'over' | 'defuse' | 'paused' | 'timeout_ct' | 'timeout_t'; + phase_ends_in: string; +} + +export interface CSGORaw { + provider: Provider; + map?: MapRaw; + round?: RoundRaw; + player?: PlayerObservedRaw; + allplayers?: PlayersRaw; + bomb?: BombRaw; + grenades?: { + [key: string]: any; + /*{ + owner:number, + position:string, + velocity:string, + lifetime:string, + type:string, + effecttime?:string + }*/ + }; + previously?: any; + phase_countdowns?: PhaseRaw; + auth?: { + token: string; + }; +} diff --git a/lib/esm/events.d.ts b/lib/esm/events.d.ts new file mode 100644 index 0000000..1e83240 --- /dev/null +++ b/lib/esm/events.d.ts @@ -0,0 +1,38 @@ +import * as I from './interfaces'; + +export interface Events { + raw: (data: I.CSGORaw) => void; + data: (data: I.CSGO) => void; + roundEnd: (team: I.Score) => void; + matchEnd: (score: I.Score) => void; + kill: (kill: I.KillEvent) => void; + hurt: (kill: I.HurtEvent) => void; + timeoutStart: (team: any) => void; + timeoutEnd: () => void; + /*roundStart: (round: number) => void, + warmupStart: () => void, + warmupEnd: () => void,*/ + mvp: (player: I.Player) => void; + freezetimeStart: () => void; + freezetimeEnd: () => void; + intermissionStart: () => void; + intermissionEnd: () => void; + defuseStart: (player: I.Player) => void; + defuseStop: (player: I.Player) => void; + bombPlantStart: (player: I.Player) => void; + bombPlant: (player: I.Player) => void; + bombExplode: () => void; + bombDefuse: (player: I.Player) => void; + newListener: (eventName: K, listener: Events[K]) => void; + removeListener: (eventName: K, listener: Events[K]) => void; +} + +export type AnyEventName = T | (string & {}); + +export type BaseEvents = keyof Events; + +export type EventNames = AnyEventName; + +export type EmptyListener = () => void; + +export type Callback = K extends BaseEvents ? Events[K] | EmptyListener : EmptyListener; diff --git a/lib/esm/index.d.ts b/lib/esm/index.d.ts new file mode 100644 index 0000000..c3b8626 --- /dev/null +++ b/lib/esm/index.d.ts @@ -0,0 +1,120 @@ +import { + CSGO, + CSGORaw, + Events, + KillEvent, + PlayerExtension, + RawKill, + Score, + TeamExtension, + Callback, + EventNames, + BaseEvents +} from './interfaces'; +import { RawHurt } from './mirv'; +import { DigestMirvType, HurtEvent } from './parsed'; +import { mapSteamIDToPlayer, parseTeam, getHalfFromRound, didTeamWinThatRound } from './utils.js'; +interface EventDescriptor { + listener: Events[BaseEvents]; + once: boolean; +} +declare type RoundPlayerDamage = { + steamid: string; + damage: number; +}; +declare type RoundDamage = { + round: number; + players: RoundPlayerDamage[]; +}; +declare class CSGOGSI { + private descriptors; + private maxListeners; + teams: { + left: TeamExtension | null; + right: TeamExtension | null; + }; + damage: RoundDamage[]; + players: PlayerExtension[]; + overtimeMR: number; + regulationMR: number; + last?: CSGO; + current?: CSGO; + constructor(); + eventNames: () => EventNames[]; + getMaxListeners: () => number; + listenerCount: (eventName: EventNames) => number; + listeners: ( + eventName: EventNames + ) => ( + | ((data: CSGORaw) => void) + | ((data: CSGO) => void) + | ((team: Score) => void) + | ((score: Score) => void) + | ((kill: KillEvent) => void) + | ((kill: HurtEvent) => void) + | ((team: any) => void) + | (() => void) + | ((player: import('./parsed').Player) => void) + | (() => void) + | (() => void) + | (() => void) + | (() => void) + | ((player: import('./parsed').Player) => void) + | ((player: import('./parsed').Player) => void) + | ((player: import('./parsed').Player) => void) + | ((player: import('./parsed').Player) => void) + | (() => void) + | ((player: import('./parsed').Player) => void) + | ((eventName: K, listener: Events[K]) => void) + | ((eventName: K_1, listener: Events[K_1]) => void) + )[]; + removeListener: (eventName: K, listener: Callback) => this; + off: (eventName: K, listener: Callback) => this; + addListener: (eventName: K, listener: Callback) => this; + on: (eventName: K, listener: Callback) => this; + once: (eventName: K, listener: Callback) => this; + prependListener: (eventName: K, listener: Callback) => this; + emit: (eventName: EventNames, arg?: any, arg2?: any) => boolean; + prependOnceListener: (eventName: K, listener: Callback) => this; + removeAllListeners: (eventName: EventNames) => this; + setMaxListeners: (n: number) => this; + rawListeners: (eventName: EventNames) => EventDescriptor[]; + digest: (raw: CSGORaw) => CSGO | null; + digestMIRV: (raw: RawKill | RawHurt, eventType?: string) => DigestMirvType; + static findSite(mapName: string, position: number[]): 'A' | 'B' | null; +} +export { CSGOGSI, mapSteamIDToPlayer, parseTeam, getHalfFromRound, didTeamWinThatRound, RoundDamage }; +export { + CSGO, + CSGORaw, + Side, + RoundOutcome, + WeaponType, + Observer, + RawHurt, + WeaponRaw, + TeamRaw, + PlayerRaw, + PlayerObservedRaw, + PlayersRaw, + Provider, + HurtEvent, + RoundWins, + MapRaw, + RoundRaw, + BombRaw, + PhaseRaw, + Events, + Team, + Player, + Bomb, + Map, + Round, + Score, + KillEvent, + RawKill, + TeamExtension, + RoundInfo, + PlayerExtension, + Orientation +} from './interfaces'; diff --git a/lib/esm/interfaces.d.ts b/lib/esm/interfaces.d.ts new file mode 100644 index 0000000..432580a --- /dev/null +++ b/lib/esm/interfaces.d.ts @@ -0,0 +1,23 @@ +export * from './csgo'; +export * from './events'; +export * from './parsed'; +export * from './mirv'; + +export interface TeamExtension { + id: string; + name: string; + country: string | null; + logo: string | null; + map_score: number; + extra: Record; +} + +export interface PlayerExtension { + id: string; + name: string; + steamid: string; + realName: string | null; + country: string | null; + avatar: string | null; + extra: Record; +} diff --git a/lib/esm/mirv.d.ts b/lib/esm/mirv.d.ts new file mode 100644 index 0000000..37bde14 --- /dev/null +++ b/lib/esm/mirv.d.ts @@ -0,0 +1,53 @@ +export interface RawKill { + name: 'player_death'; + clientTime: number; + keys: { + userid: { + value: number; + xuid: string; + }; + attacker: { + value: number; + xuid: string; + }; + assister: { + value: number; + xuid: string; + }; + assistedflash: boolean; + weapon: string; + weapon_itemid: string; + weapon_fauxitemid: string; + weapon_originalowner_xuid: string; + headshot: boolean; + dominated: number; + revenge: number; + wipe: number; + attackerblind: boolean; + thrusmoke: boolean; + noscope: boolean; + penetrated: number; + noreplay: boolean; + }; +} + +export interface RawHurt { + name: 'player_hurt'; + clientTime: number; + keys: { + userid: { + value: number; + xuid: string; + }; + attacker: { + value: number; + xuid: string; + }; + health: number; + armor: number; + weapon: string; + dmg_health: number; + dmg_armor: number; + hitgroup: number; + }; +} diff --git a/lib/esm/parsed.d.ts b/lib/esm/parsed.d.ts new file mode 100644 index 0000000..9906e85 --- /dev/null +++ b/lib/esm/parsed.d.ts @@ -0,0 +1,152 @@ +import * as I from './interfaces'; + +export type Orientation = 'left' | 'right'; + +export interface Team { + logo: string | null; + score: number; + consecutive_round_losses: number; + timeouts_remaining: number; + matches_won_this_series: number; + side: I.Side; + name: string; + country: string | null; + id: string | null; + orientation: Orientation; + extra: Record; +} + +export interface RoundInfo { + team: Team; + round: number; + side: I.Side; + outcome: I.RoundOutcome; +} +export interface Player { + steamid: string; + name: string; + defaultName: string; + clan?: string; + observer_slot?: number; + team: Team; + stats: { + kills: number; + assists: number; + deaths: number; + mvps: number; + score: number; + }; + weapons: { + [key: string]: I.WeaponRaw; + }; + state: { + health: number; + armor: number; + helmet: boolean; + defusekit?: boolean; + flashed: number; + smoked: number; + burning: number; + money: number; + round_kills: number; + round_killhs: number; + round_totaldmg: number; + equip_value: number; + adr: number; + }; + position: number[]; + forward: number[]; + avatar: string | null; + country: string | null; + realName: string | null; + extra: Record; +} + +export type RoundWins = { + [key: string]: I.RoundOutcome; +}; +export interface Bomb { + state: 'carried' | 'planted' | 'dropped' | 'defused' | 'defusing' | 'planting' | 'exploded'; + countdown?: string; + player?: Player; + site: 'A' | 'B' | null; + position: number[]; +} + +export interface Map { + mode: string; + name: string; + phase: 'warmup' | 'live' | 'intermission' | 'gameover'; + round: number; + team_ct: Team; + team_t: Team; + num_matches_to_win_series: number; + current_spectators: number; + souvenirs_total: number; + round_wins: RoundWins; + rounds: I.RoundInfo[]; +} + +export interface Round { + phase: 'freezetime' | 'live' | 'over'; + bomb?: 'planted' | 'exploded' | 'defused'; + win_team?: I.Side; +} + +export interface Observer { + activity?: 'playing' | 'textinput' | 'menu'; + spectarget?: 'free' | (string & {}); + position?: number[]; + forward?: number[]; +} + +export interface CSGO { + provider: I.Provider; + map: Map; + round: Round | null; + observer: Observer; + player: Player | null; + players: Player[]; + bomb: Bomb | null; + grenades?: { + [key: string]: any; + }; + previously?: any; + phase_countdowns: I.PhaseRaw; + auth?: { + token: string; + }; +} +export interface Score { + winner: I.Team; + loser: I.Team; + map: Map; + mapEnd: boolean; +} + +export interface KillEvent { + killer: Player | null; + victim: Player; + assister: Player | null; + flashed: boolean; + headshot: boolean; + weapon: string; + wallbang: boolean; + attackerblind: boolean; + thrusmoke: boolean; + noscope: boolean; +} + +export interface HurtEvent { + attacker: Player; + victim: Player; + health: number; + armor: number; + weapon: string; + dmg_health: number; + dmg_armor: number; + hitgroup: number; +} + +//export type DigestMirvType = ((kill: RawKill, eventType: 'player_death') => KillEvent | null) | ((hurt: RawHurt, eventType: 'player_hurt') => HurtEvent | null) +export type DigestMirvType = KillEvent | HurtEvent | null; diff --git a/lib/esm/utils.d.ts b/lib/esm/utils.d.ts new file mode 100644 index 0000000..0b029b7 --- /dev/null +++ b/lib/esm/utils.d.ts @@ -0,0 +1,46 @@ +import { + Team, + PlayerExtension, + Player, + PlayersRaw, + Side, + Orientation, + TeamExtension, + TeamRaw, + RoundInfo, + RoundWins +} from '.'; +export declare const mapSteamIDToPlayer: ( + players: PlayersRaw, + teams: { + CT: Team; + T: Team; + }, + extensions: PlayerExtension[] +) => (steamid: string) => Player; +export declare const parseTeam: ( + team: TeamRaw, + orientation: Orientation, + side: Side, + extension: TeamExtension | null +) => Team; +export declare const getHalfFromRound: (round: number, regulationMR: number, mr: number) => number; +export declare const didTeamWinThatRound: ( + team: Team, + round: number, + wonBy: Side, + currentRound: number, + regulationMR: number, + mr: number +) => boolean; +export declare const getRoundWin: ( + mapRound: number, + teams: { + ct: Team; + t: Team; + }, + roundWins: RoundWins, + round: number, + regulationMR: number, + overtimeMR: number +) => RoundInfo | null; diff --git a/package.json b/package.json index a43bc96..2910063 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "csgogsi", - "version": "2.7.2", + "version": "2.7.3", "description": "", "type": "module", "main": "./lib/cjs/index.js", @@ -9,7 +9,6 @@ "import": "./lib/esm/index.js", "default": "./lib/cjs/index.js" }, - "types": "./types/index.d.ts", "devDependencies": { "@types/jest": "^26.0.21", "@types/lodash.merge": "^4.6.6", @@ -34,7 +33,7 @@ "transpile:esm": "tsc -p tsconfig.esm.json", "transpile:all": "npm run transpile:cjs && npm run transpile:esm", "transpile": "npm run transpile:all && npm run post-compile && npm run move-build", - "move-build": "cp tsc/*.d.ts lib/cjs && mv lib/cjs/*.d.ts types/", + "move-build": "cp tsc/*.d.ts lib/cjs && cp lib/cjs/*.d.ts lib/esm", "lint": "eslint . --ext .ts", "prettier-format": "prettier --config .prettierrc --write **/*.ts", "post-compile": "npm run prettier-format && npm run lint && npm test && npm run make-badges"