mirror of
https://github.com/demostf/demo.js
synced 2026-06-04 00:54:14 +02:00
fix some typings
This commit is contained in:
parent
48b376fa2e
commit
ba7ce734e3
7 changed files with 146 additions and 95 deletions
|
|
@ -1,7 +1,7 @@
|
|||
export interface Death {
|
||||
weapon: string;
|
||||
victim: number;
|
||||
assister: number;
|
||||
assister: number|null;
|
||||
killer: number;
|
||||
tick: number;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ export interface GameEventDefinition {
|
|||
|
||||
export interface GameEvent {
|
||||
name: string;
|
||||
values: GameEventValueMap;
|
||||
values: GameEventValues;
|
||||
}
|
||||
|
||||
export interface GameEventEntry {
|
||||
|
|
@ -15,13 +15,32 @@ export interface GameEventEntry {
|
|||
}
|
||||
|
||||
export enum GameEventType {
|
||||
STRING = 1,
|
||||
FLOAT = 2,
|
||||
LONG = 3,
|
||||
SHORT = 4,
|
||||
BYTE = 5,
|
||||
STRING = 1,
|
||||
FLOAT = 2,
|
||||
LONG = 3,
|
||||
SHORT = 4,
|
||||
BYTE = 5,
|
||||
BOOLEAN = 6,
|
||||
LOCAL = 7
|
||||
LOCAL = 7
|
||||
}
|
||||
|
||||
export interface DeathEventValues {
|
||||
attacker: number;
|
||||
userid: number;
|
||||
assister: number;
|
||||
weapon: string;
|
||||
}
|
||||
|
||||
export interface RoundWinEventValues {
|
||||
winreason: number;
|
||||
team: number;
|
||||
round_time: number;
|
||||
}
|
||||
|
||||
export interface PlayerSpawnEventValues {
|
||||
userid: number;
|
||||
team: number;
|
||||
'class': number
|
||||
}
|
||||
|
||||
export type GameEventValue = string|number|boolean;
|
||||
|
|
@ -30,6 +49,11 @@ export type GameEventValueMap = {
|
|||
[name: string]: GameEventValue;
|
||||
}
|
||||
|
||||
export type GameEventValues = GameEventValueMap |
|
||||
DeathEventValues |
|
||||
RoundWinEventValues |
|
||||
PlayerSpawnEventValues;
|
||||
|
||||
export type GameEventDefinitionMap = {
|
||||
[id: number]: GameEventDefinition;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import {handlePacketEntities} from "../PacketHandler/PacketEntities";
|
|||
export class Match {
|
||||
tick: number;
|
||||
chat: any[];
|
||||
users: UserInfo[];
|
||||
users: {[id: string]: UserInfo};
|
||||
deaths: Death[];
|
||||
rounds: any[];
|
||||
startTick: number;
|
||||
|
|
@ -36,7 +36,7 @@ export class Match {
|
|||
constructor() {
|
||||
this.tick = 0;
|
||||
this.chat = [];
|
||||
this.users = [];
|
||||
this.users = {};
|
||||
this.deaths = [];
|
||||
this.rounds = [];
|
||||
this.startTick = 0;
|
||||
|
|
@ -76,9 +76,25 @@ export class Match {
|
|||
}
|
||||
|
||||
getState() {
|
||||
const users = {};
|
||||
for (const key in this.users) {
|
||||
const user = this.users[key];
|
||||
if (this.users.hasOwnProperty(key)) {
|
||||
users[key] = {
|
||||
classes: user.classes,
|
||||
name: user.name,
|
||||
steamId: user.steamId,
|
||||
userId: user.userId,
|
||||
};
|
||||
if (user.team) {
|
||||
users[key].team = user.team;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
'chat': this.chat,
|
||||
'users': this.users,
|
||||
'users': users,
|
||||
'deaths': this.deaths,
|
||||
'rounds': this.rounds,
|
||||
'startTick': this.startTick,
|
||||
|
|
@ -132,7 +148,8 @@ export class Match {
|
|||
}
|
||||
|
||||
getUserInfoForEntity(entity: Entity): UserInfo {
|
||||
for (const user of this.users) {
|
||||
for (const id of Object.keys(this.users)) {
|
||||
const user = this.users[id];
|
||||
if (user && user.entityId === entity.entityIndex) {
|
||||
return user;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue