mirror of
https://github.com/demostf/demo.js
synced 2026-06-04 00:54:14 +02:00
use map for users within match
This commit is contained in:
parent
8f0d372b13
commit
c41928c97a
1 changed files with 26 additions and 27 deletions
|
|
@ -22,7 +22,7 @@ import {World} from './World';
|
||||||
export class Match {
|
export class Match {
|
||||||
public tick: number;
|
public tick: number;
|
||||||
public chat: any[];
|
public chat: any[];
|
||||||
public users: { [id: string]: UserInfo };
|
public users: Map<number, UserInfo>;
|
||||||
public deaths: Death[];
|
public deaths: Death[];
|
||||||
public rounds: any[];
|
public rounds: any[];
|
||||||
public startTick: number;
|
public startTick: number;
|
||||||
|
|
@ -31,16 +31,16 @@ export class Match {
|
||||||
public eventDefinitions: Map<number, GameEventDefinition>;
|
public eventDefinitions: Map<number, GameEventDefinition>;
|
||||||
public world: World;
|
public world: World;
|
||||||
public players: Player[];
|
public players: Player[];
|
||||||
public playerMap: { [entityId: number]: Player };
|
public playerMap: {[entityId: number]: Player};
|
||||||
public entityClasses: { [entityId: string]: ServerClass };
|
public entityClasses: {[entityId: string]: ServerClass};
|
||||||
public sendTableMap: { [name: string]: SendTable };
|
public sendTableMap: {[name: string]: SendTable};
|
||||||
public baseLineCache: { [serverClass: string]: PacketEntity };
|
public baseLineCache: {[serverClass: string]: PacketEntity};
|
||||||
public weaponMap: { [entityId: string]: Weapon };
|
public weaponMap: {[entityId: string]: Weapon};
|
||||||
public outerMap: { [outer: number]: number };
|
public outerMap: {[outer: number]: number};
|
||||||
public teams: Team[];
|
public teams: Team[];
|
||||||
public teamMap: { [entityId: string]: Team };
|
public teamMap: {[entityId: string]: Team};
|
||||||
public version: number;
|
public version: number;
|
||||||
public buildings: { [entityId: string]: Building } = {};
|
public buildings: {[entityId: string]: Building} = {};
|
||||||
public playerResources: PlayerResource[] = [];
|
public playerResources: PlayerResource[] = [];
|
||||||
public stringTables: StringTable[];
|
public stringTables: StringTable[];
|
||||||
public sendTables: SendTable[];
|
public sendTables: SendTable[];
|
||||||
|
|
@ -49,7 +49,7 @@ export class Match {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.tick = 0;
|
this.tick = 0;
|
||||||
this.chat = [];
|
this.chat = [];
|
||||||
this.users = {};
|
this.users = new Map();
|
||||||
this.deaths = [];
|
this.deaths = [];
|
||||||
this.rounds = [];
|
this.rounds = [];
|
||||||
this.startTick = 0;
|
this.startTick = 0;
|
||||||
|
|
@ -99,18 +99,15 @@ export class Match {
|
||||||
|
|
||||||
public getState() {
|
public getState() {
|
||||||
const users = {};
|
const users = {};
|
||||||
for (const key in this.users) {
|
for (const [key, user] of this.users.entries()) {
|
||||||
if (this.users.hasOwnProperty(key)) {
|
users[key] = {
|
||||||
const user = this.users[key];
|
classes: user.classes,
|
||||||
users[key] = {
|
name: user.name,
|
||||||
classes: user.classes,
|
steamId: user.steamId,
|
||||||
name: user.name,
|
userId: user.userId,
|
||||||
steamId: user.steamId,
|
};
|
||||||
userId: user.userId,
|
if (user.team) {
|
||||||
};
|
users[key].team = user.team;
|
||||||
if (user.team) {
|
|
||||||
users[key].team = user.team;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -169,8 +166,9 @@ export class Match {
|
||||||
while (userId > 256) {
|
while (userId > 256) {
|
||||||
userId -= 256;
|
userId -= 256;
|
||||||
}
|
}
|
||||||
if (!this.users[userId]) {
|
const user = this.users.get(userId);
|
||||||
this.users[userId] = {
|
if (!user) {
|
||||||
|
const newUser = {
|
||||||
name: '',
|
name: '',
|
||||||
userId,
|
userId,
|
||||||
steamId: '',
|
steamId: '',
|
||||||
|
|
@ -178,13 +176,14 @@ export class Match {
|
||||||
entityId: 0,
|
entityId: 0,
|
||||||
team: '',
|
team: '',
|
||||||
};
|
};
|
||||||
|
this.users.set(userId, newUser);
|
||||||
|
return newUser;
|
||||||
}
|
}
|
||||||
return this.users[userId];
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getUserInfoForEntity(entity: PacketEntity): UserInfo {
|
public getUserInfoForEntity(entity: PacketEntity): UserInfo {
|
||||||
for (const id of Object.keys(this.users)) {
|
for (const user of this.users.values()) {
|
||||||
const user = this.users[id];
|
|
||||||
if (user && user.entityId === entity.entityIndex) {
|
if (user && user.entityId === entity.entityIndex) {
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue