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 {
|
||||
public tick: number;
|
||||
public chat: any[];
|
||||
public users: { [id: string]: UserInfo };
|
||||
public users: Map<number, UserInfo>;
|
||||
public deaths: Death[];
|
||||
public rounds: any[];
|
||||
public startTick: number;
|
||||
|
|
@ -49,7 +49,7 @@ export class Match {
|
|||
constructor() {
|
||||
this.tick = 0;
|
||||
this.chat = [];
|
||||
this.users = {};
|
||||
this.users = new Map();
|
||||
this.deaths = [];
|
||||
this.rounds = [];
|
||||
this.startTick = 0;
|
||||
|
|
@ -99,9 +99,7 @@ export class Match {
|
|||
|
||||
public getState() {
|
||||
const users = {};
|
||||
for (const key in this.users) {
|
||||
if (this.users.hasOwnProperty(key)) {
|
||||
const user = this.users[key];
|
||||
for (const [key, user] of this.users.entries()) {
|
||||
users[key] = {
|
||||
classes: user.classes,
|
||||
name: user.name,
|
||||
|
|
@ -112,7 +110,6 @@ export class Match {
|
|||
users[key].team = user.team;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
chat: this.chat,
|
||||
|
|
@ -169,8 +166,9 @@ export class Match {
|
|||
while (userId > 256) {
|
||||
userId -= 256;
|
||||
}
|
||||
if (!this.users[userId]) {
|
||||
this.users[userId] = {
|
||||
const user = this.users.get(userId);
|
||||
if (!user) {
|
||||
const newUser = {
|
||||
name: '',
|
||||
userId,
|
||||
steamId: '',
|
||||
|
|
@ -178,13 +176,14 @@ export class Match {
|
|||
entityId: 0,
|
||||
team: '',
|
||||
};
|
||||
this.users.set(userId, newUser);
|
||||
return newUser;
|
||||
}
|
||||
return this.users[userId];
|
||||
return user;
|
||||
}
|
||||
|
||||
public getUserInfoForEntity(entity: PacketEntity): UserInfo {
|
||||
for (const id of Object.keys(this.users)) {
|
||||
const user = this.users[id];
|
||||
for (const user of this.users.values()) {
|
||||
if (user && user.entityId === entity.entityIndex) {
|
||||
return user;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue