mirror of
https://github.com/demostf/demo.js
synced 2026-06-04 00:54:14 +02:00
code style and add tslint
This commit is contained in:
parent
da007aca8c
commit
52a36ed8c8
61 changed files with 1708 additions and 872 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import {Vector} from "./Vector";
|
||||
import {Vector} from './Vector';
|
||||
|
||||
export interface BaseBuilding {
|
||||
builder: number;
|
||||
|
|
|
|||
|
|
@ -15,13 +15,13 @@ 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 {
|
||||
|
|
@ -40,7 +40,7 @@ export interface RoundWinEventValues {
|
|||
export interface PlayerSpawnEventValues {
|
||||
userid: number;
|
||||
team: number;
|
||||
'class': number
|
||||
'class': number;
|
||||
}
|
||||
|
||||
export interface ObjectDestroyedValues {
|
||||
|
|
@ -52,9 +52,9 @@ export interface ObjectDestroyedValues {
|
|||
index: number;
|
||||
}
|
||||
|
||||
export type GameEventValue = string|number|boolean;
|
||||
export type GameEventValue = string | number | boolean;
|
||||
|
||||
export type GameEventValueMap = {
|
||||
export interface GameEventValueMap {
|
||||
[name: string]: GameEventValue;
|
||||
}
|
||||
|
||||
|
|
@ -64,6 +64,6 @@ export type GameEventValues = GameEventValueMap |
|
|||
PlayerSpawnEventValues |
|
||||
ObjectDestroyedValues;
|
||||
|
||||
export type GameEventDefinitionMap = {
|
||||
export interface GameEventDefinitionMap {
|
||||
[id: number]: GameEventDefinition;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,81 +1,81 @@
|
|||
import {PacketEntity} from "./PacketEntity";
|
||||
import {ServerClass} from "./ServerClass";
|
||||
import {SendTable} from "./SendTable";
|
||||
import {StringTable} from "./StringTable";
|
||||
import {GameEventDefinitionMap} from "./GameEvent";
|
||||
import {BitStream} from "bit-buffer";
|
||||
import {UserInfo} from "./UserInfo";
|
||||
import {World} from "./World";
|
||||
import {Player} from "./Player";
|
||||
import {Death} from "./Death";
|
||||
import {handleStringTable} from "../PacketHandler/StringTable";
|
||||
import {handleSayText2} from "../PacketHandler/SayText2";
|
||||
import {handleGameEvent} from "../PacketHandler/GameEvent";
|
||||
import {handlePacketEntities} from "../PacketHandler/PacketEntities";
|
||||
import {handleGameEventList} from "../PacketHandler/GameEventList";
|
||||
import {handleDataTable} from "../PacketHandler/DataTable";
|
||||
import {Weapon} from "./Weapon";
|
||||
import {Team} from "./Team";
|
||||
import {Building} from "./Building";
|
||||
import {PlayerResource} from "./PlayerResource";
|
||||
import {BitStream} from 'bit-buffer';
|
||||
import {handleDataTable} from '../PacketHandler/DataTable';
|
||||
import {handleGameEvent} from '../PacketHandler/GameEvent';
|
||||
import {handleGameEventList} from '../PacketHandler/GameEventList';
|
||||
import {handlePacketEntities} from '../PacketHandler/PacketEntities';
|
||||
import {handleSayText2} from '../PacketHandler/SayText2';
|
||||
import {handleStringTable} from '../PacketHandler/StringTable';
|
||||
import {Building} from './Building';
|
||||
import {Death} from './Death';
|
||||
import {GameEventDefinitionMap} from './GameEvent';
|
||||
import {PacketEntity} from './PacketEntity';
|
||||
import {Player} from './Player';
|
||||
import {PlayerResource} from './PlayerResource';
|
||||
import {SendTable} from './SendTable';
|
||||
import {ServerClass} from './ServerClass';
|
||||
import {StringTable} from './StringTable';
|
||||
import {Team} from './Team';
|
||||
import {UserInfo} from './UserInfo';
|
||||
import {Weapon} from './Weapon';
|
||||
import {World} from './World';
|
||||
|
||||
export class Match {
|
||||
tick: number;
|
||||
chat: any[];
|
||||
users: {[id: string]: UserInfo};
|
||||
deaths: Death[];
|
||||
rounds: any[];
|
||||
startTick: number;
|
||||
intervalPerTick: number;
|
||||
stringTables: StringTable[];
|
||||
serverClasses: ServerClass[];
|
||||
sendTables: SendTable[];
|
||||
staticBaseLines: BitStream[];
|
||||
eventDefinitions: GameEventDefinitionMap;
|
||||
world: World;
|
||||
players: Player[];
|
||||
playerMap: {[entityId: number]: Player};
|
||||
entityClasses: {[entityId: string]: ServerClass};
|
||||
sendTableMap: {[name: string]: SendTable};
|
||||
baseLineCache: {[serverClass: string]: PacketEntity};
|
||||
weaponMap: {[entityId: string]: Weapon};
|
||||
outerMap: {[outer: number]: number};
|
||||
teams: Team[];
|
||||
teamMap: {[entityId: string]: Team};
|
||||
version: number;
|
||||
buildings: {[entityId: string]: Building} = {};
|
||||
playerResources: PlayerResource[] = [];
|
||||
public tick: number;
|
||||
public chat: any[];
|
||||
public users: { [id: string]: UserInfo };
|
||||
public deaths: Death[];
|
||||
public rounds: any[];
|
||||
public startTick: number;
|
||||
public intervalPerTick: number;
|
||||
public staticBaseLines: BitStream[];
|
||||
public eventDefinitions: GameEventDefinitionMap;
|
||||
public world: World;
|
||||
public players: Player[];
|
||||
public playerMap: { [entityId: number]: Player };
|
||||
public entityClasses: { [entityId: string]: ServerClass };
|
||||
public sendTableMap: { [name: string]: SendTable };
|
||||
public baseLineCache: { [serverClass: string]: PacketEntity };
|
||||
public weaponMap: { [entityId: string]: Weapon };
|
||||
public outerMap: { [outer: number]: number };
|
||||
public teams: Team[];
|
||||
public teamMap: { [entityId: string]: Team };
|
||||
public version: number;
|
||||
public buildings: { [entityId: string]: Building } = {};
|
||||
public playerResources: PlayerResource[] = [];
|
||||
public stringTables: StringTable[];
|
||||
public sendTables: SendTable[];
|
||||
public serverClasses: ServerClass[];
|
||||
|
||||
constructor() {
|
||||
this.tick = 0;
|
||||
this.chat = [];
|
||||
this.users = {};
|
||||
this.deaths = [];
|
||||
this.rounds = [];
|
||||
this.startTick = 0;
|
||||
this.intervalPerTick = 0;
|
||||
this.stringTables = [];
|
||||
this.sendTables = [];
|
||||
this.serverClasses = [];
|
||||
this.staticBaseLines = [];
|
||||
this.tick = 0;
|
||||
this.chat = [];
|
||||
this.users = {};
|
||||
this.deaths = [];
|
||||
this.rounds = [];
|
||||
this.startTick = 0;
|
||||
this.intervalPerTick = 0;
|
||||
this.stringTables = [];
|
||||
this.sendTables = [];
|
||||
this.serverClasses = [];
|
||||
this.staticBaseLines = [];
|
||||
this.eventDefinitions = {};
|
||||
this.players = [];
|
||||
this.playerMap = {};
|
||||
this.world = {
|
||||
this.players = [];
|
||||
this.playerMap = {};
|
||||
this.world = {
|
||||
boundaryMin: {x: 0, y: 0, z: 0},
|
||||
boundaryMax: {x: 0, y: 0, z: 0}
|
||||
boundaryMax: {x: 0, y: 0, z: 0},
|
||||
};
|
||||
this.entityClasses = {};
|
||||
this.sendTableMap = {};
|
||||
this.baseLineCache = {};
|
||||
this.weaponMap = {};
|
||||
this.outerMap = {};
|
||||
this.teams = [];
|
||||
this.teamMap = {};
|
||||
this.version = 0;
|
||||
this.entityClasses = {};
|
||||
this.sendTableMap = {};
|
||||
this.baseLineCache = {};
|
||||
this.weaponMap = {};
|
||||
this.outerMap = {};
|
||||
this.teams = [];
|
||||
this.teamMap = {};
|
||||
this.version = 0;
|
||||
}
|
||||
|
||||
getSendTable(name) {
|
||||
public getSendTable(name) {
|
||||
if (this.sendTableMap[name]) {
|
||||
return this.sendTableMap[name];
|
||||
}
|
||||
|
|
@ -85,10 +85,10 @@ export class Match {
|
|||
return table;
|
||||
}
|
||||
}
|
||||
throw new Error("unknown SendTable " + name);
|
||||
throw new Error('unknown SendTable ' + name);
|
||||
}
|
||||
|
||||
getStringTable(name) {
|
||||
public getStringTable(name) {
|
||||
for (const table of this.stringTables) {
|
||||
if (table.name === name) {
|
||||
return table;
|
||||
|
|
@ -97,16 +97,16 @@ export class Match {
|
|||
return null;
|
||||
}
|
||||
|
||||
getState() {
|
||||
public getState() {
|
||||
const users = {};
|
||||
for (const key in this.users) {
|
||||
const user = this.users[key];
|
||||
if (this.users.hasOwnProperty(key)) {
|
||||
const user = this.users[key];
|
||||
users[key] = {
|
||||
classes: user.classes,
|
||||
name: user.name,
|
||||
name: user.name,
|
||||
steamId: user.steamId,
|
||||
userId: user.userId,
|
||||
userId: user.userId,
|
||||
};
|
||||
if (user.team) {
|
||||
users[key].team = user.team;
|
||||
|
|
@ -115,16 +115,16 @@ export class Match {
|
|||
}
|
||||
|
||||
return {
|
||||
'chat': this.chat,
|
||||
'users': users,
|
||||
'deaths': this.deaths,
|
||||
'rounds': this.rounds,
|
||||
'startTick': this.startTick,
|
||||
'intervalPerTick': this.intervalPerTick
|
||||
chat: this.chat,
|
||||
users,
|
||||
deaths: this.deaths,
|
||||
rounds: this.rounds,
|
||||
startTick: this.startTick,
|
||||
intervalPerTick: this.intervalPerTick,
|
||||
};
|
||||
}
|
||||
|
||||
handlePacket(packet) {
|
||||
public handlePacket(packet) {
|
||||
switch (packet.packetType) {
|
||||
case 'packetEntities':
|
||||
handlePacketEntities(packet, this);
|
||||
|
|
@ -137,7 +137,7 @@ export class Match {
|
|||
break;
|
||||
case 'serverInfo':
|
||||
this.intervalPerTick = packet.intervalPerTick;
|
||||
this.version = packet.version;
|
||||
this.version = packet.version;
|
||||
break;
|
||||
case 'sayText2':
|
||||
handleSayText2(packet, this);
|
||||
|
|
@ -157,7 +157,7 @@ export class Match {
|
|||
}
|
||||
}
|
||||
|
||||
getUserInfo(userId: number): UserInfo {
|
||||
public getUserInfo(userId: number): UserInfo {
|
||||
// no clue why it does this
|
||||
// only seems to be the case with per user ready
|
||||
while (userId > 256) {
|
||||
|
|
@ -165,18 +165,18 @@ export class Match {
|
|||
}
|
||||
if (!this.users[userId]) {
|
||||
this.users[userId] = {
|
||||
name: '',
|
||||
userId: userId,
|
||||
steamId: '',
|
||||
classes: {},
|
||||
name: '',
|
||||
userId,
|
||||
steamId: '',
|
||||
classes: {},
|
||||
entityId: 0,
|
||||
team: ''
|
||||
}
|
||||
team: '',
|
||||
};
|
||||
}
|
||||
return this.users[userId];
|
||||
}
|
||||
|
||||
getUserInfoForEntity(entity: PacketEntity): UserInfo {
|
||||
public getUserInfoForEntity(entity: PacketEntity): UserInfo {
|
||||
for (const id of Object.keys(this.users)) {
|
||||
const user = this.users[id];
|
||||
if (user && user.entityId === entity.entityIndex) {
|
||||
|
|
@ -186,7 +186,7 @@ export class Match {
|
|||
throw new Error('User not found for entity ' + entity.entityIndex);
|
||||
}
|
||||
|
||||
getPlayerByUserId(userId: number): Player {
|
||||
public getPlayerByUserId(userId: number): Player {
|
||||
for (const player of this.players) {
|
||||
if (player.user.userId === userId) {
|
||||
return player;
|
||||
|
|
@ -196,6 +196,6 @@ export class Match {
|
|||
}
|
||||
|
||||
get classBits() {
|
||||
return Math.ceil(Math.log(this.serverClasses.length) * Math.LOG2E)
|
||||
return Math.ceil(Math.log(this.serverClasses.length) * Math.LOG2E);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import {StringTable} from "./StringTable";
|
||||
import {Vector} from "./Vector";
|
||||
import {GameEvent, GameEventDefinitionMap} from "./GameEvent";
|
||||
import {PacketEntity} from "./PacketEntity";
|
||||
import {SendTable} from "./SendTable";
|
||||
import {ServerClass} from "./ServerClass";
|
||||
import {BitStream} from "bit-buffer";
|
||||
import {BitStream} from 'bit-buffer';
|
||||
import {GameEvent, GameEventDefinitionMap} from './GameEvent';
|
||||
import {PacketEntity} from './PacketEntity';
|
||||
import {SendTable} from './SendTable';
|
||||
import {ServerClass} from './ServerClass';
|
||||
import {StringTable} from './StringTable';
|
||||
import {Vector} from './Vector';
|
||||
|
||||
export interface StringTablePacket {
|
||||
packetType: 'stringTable';
|
||||
|
|
@ -35,11 +35,11 @@ export interface ClassInfoPacket {
|
|||
packetType: 'classInfo';
|
||||
number: number;
|
||||
create: boolean;
|
||||
entries: {
|
||||
entries: Array<{
|
||||
classId: number;
|
||||
className: string;
|
||||
dataTableName: string;
|
||||
}[]
|
||||
}>;
|
||||
}
|
||||
|
||||
export interface EntityMessagePacket {
|
||||
|
|
@ -66,7 +66,7 @@ export interface PacketEntitiesPacket {
|
|||
maxEntries: number;
|
||||
isDelta: boolean;
|
||||
delta: number;
|
||||
baseLine : number;
|
||||
baseLine: number;
|
||||
updatedEntries: number;
|
||||
length: number;
|
||||
updatedBaseLine: boolean;
|
||||
|
|
@ -113,7 +113,7 @@ export interface VoiceInitPacket {
|
|||
packetType: 'voiceInit';
|
||||
codec: string;
|
||||
quality: number;
|
||||
extraData: number
|
||||
extraData: number;
|
||||
}
|
||||
|
||||
export interface VoiceDataPacket {
|
||||
|
|
|
|||
|
|
@ -1,41 +1,40 @@
|
|||
import {ServerClass} from "./ServerClass";
|
||||
import {SendTable} from "./SendTable";
|
||||
import {SendProp} from "./SendProp";
|
||||
import {SendPropDefinition} from "./SendPropDefinition";
|
||||
import {SendProp} from './SendProp';
|
||||
import {SendPropDefinition} from './SendPropDefinition';
|
||||
import {ServerClass} from './ServerClass';
|
||||
|
||||
export enum PVS {
|
||||
PRESERVE = 0,
|
||||
ENTER = 1,
|
||||
LEAVE = 2,
|
||||
DELETE = 4
|
||||
ENTER = 1,
|
||||
LEAVE = 2,
|
||||
DELETE = 4,
|
||||
}
|
||||
|
||||
export class PacketEntity {
|
||||
pvs: PVS;
|
||||
serverClass: ServerClass;
|
||||
entityIndex: number;
|
||||
props: SendProp[];
|
||||
inPVS: boolean;
|
||||
serialNumber?: number;
|
||||
public serverClass: ServerClass;
|
||||
public entityIndex: number;
|
||||
public props: SendProp[];
|
||||
public inPVS: boolean;
|
||||
public pvs: PVS;
|
||||
public serialNumber?: number;
|
||||
|
||||
constructor(serverClass: ServerClass, entityIndex: number, pvs: PVS) {
|
||||
this.serverClass = serverClass;
|
||||
this.entityIndex = entityIndex;
|
||||
this.props = [];
|
||||
this.inPVS = false;
|
||||
this.pvs = pvs;
|
||||
this.props = [];
|
||||
this.inPVS = false;
|
||||
this.pvs = pvs;
|
||||
}
|
||||
|
||||
getPropByDefinition(definition: SendPropDefinition) {
|
||||
for (let i = 0; i < this.props.length; i++) {
|
||||
if (this.props[i].definition === definition) {
|
||||
return this.props[i];
|
||||
public getPropByDefinition(definition: SendPropDefinition) {
|
||||
for (const prop of this.props) {
|
||||
if (prop.definition === definition) {
|
||||
return prop;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
getProperty(originTable: string, name: string) {
|
||||
public getProperty(originTable: string, name: string) {
|
||||
for (const prop of this.props) {
|
||||
if (prop.definition.ownerTableName === originTable && prop.definition.name === name) {
|
||||
return prop;
|
||||
|
|
@ -44,7 +43,7 @@ export class PacketEntity {
|
|||
throw new Error(`Property not found in entity (${originTable}.${name})`);
|
||||
}
|
||||
|
||||
clone(): PacketEntity {
|
||||
public clone(): PacketEntity {
|
||||
const result = new PacketEntity(this.serverClass, this.entityIndex, this.pvs);
|
||||
for (const prop of this.props) {
|
||||
result.props.push(prop.clone());
|
||||
|
|
@ -52,4 +51,3 @@ export class PacketEntity {
|
|||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,36 +1,36 @@
|
|||
import {UserInfo} from "./UserInfo";
|
||||
import {Vector} from "./Vector";
|
||||
import {PlayerCondition} from "./PlayerCondition";
|
||||
import {Weapon} from "./Weapon";
|
||||
import {Match} from "./Match";
|
||||
import {Match} from './Match';
|
||||
import {PlayerCondition} from './PlayerCondition';
|
||||
import {UserInfo} from './UserInfo';
|
||||
import {Vector} from './Vector';
|
||||
import {Weapon} from './Weapon';
|
||||
|
||||
export enum LifeState {
|
||||
ALIVE = 0,
|
||||
DYING = 1,
|
||||
DEATH = 2,
|
||||
RESPAWNABLE = 3
|
||||
ALIVE = 0,
|
||||
DYING = 1,
|
||||
DEATH = 2,
|
||||
RESPAWNABLE = 3,
|
||||
}
|
||||
|
||||
export class Player {
|
||||
match: Match;
|
||||
user: UserInfo;
|
||||
position: Vector = new Vector(0, 0, 0);
|
||||
health: number = 0;
|
||||
maxHealth: number = 0;
|
||||
classId: number = 0;
|
||||
team: number = 0;
|
||||
viewAngle: number = 0;
|
||||
weaponIds: number[] = [];
|
||||
ammo: number[] = [];
|
||||
lifeState: LifeState = LifeState.DEATH;
|
||||
activeWeapon: number = 0;
|
||||
public match: Match;
|
||||
public user: UserInfo;
|
||||
public position: Vector = new Vector(0, 0, 0);
|
||||
public health: number = 0;
|
||||
public maxHealth: number = 0;
|
||||
public classId: number = 0;
|
||||
public team: number = 0;
|
||||
public viewAngle: number = 0;
|
||||
public weaponIds: number[] = [];
|
||||
public ammo: number[] = [];
|
||||
public lifeState: LifeState = LifeState.DEATH;
|
||||
public activeWeapon: number = 0;
|
||||
|
||||
constructor(match: Match, userInfo: UserInfo) {
|
||||
this.match = match;
|
||||
this.user = userInfo;
|
||||
this.user = userInfo;
|
||||
}
|
||||
|
||||
get weapons(): Weapon[] {
|
||||
return this.weaponIds.map(id => this.match.weaponMap[this.match.outerMap[id]]);
|
||||
return this.weaponIds.map((id) => this.match.weaponMap[this.match.outerMap[id]]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
import {SendPropDefinition} from "./SendPropDefinition";
|
||||
import {Vector} from "./Vector";
|
||||
import {SendPropDefinition} from './SendPropDefinition';
|
||||
import {Vector} from './Vector';
|
||||
|
||||
export class SendProp {
|
||||
definition: SendPropDefinition;
|
||||
value: SendPropValue|null;
|
||||
public definition: SendPropDefinition;
|
||||
public value: SendPropValue|null;
|
||||
|
||||
constructor(definition: SendPropDefinition) {
|
||||
this.definition = definition;
|
||||
this.value = null;
|
||||
}
|
||||
|
||||
clone():SendProp {
|
||||
public clone(): SendProp {
|
||||
const prop = new SendProp(this.definition);
|
||||
prop.value = this.value;
|
||||
return prop;
|
||||
|
|
|
|||
|
|
@ -1,49 +1,50 @@
|
|||
import {SendTable} from "./SendTable";
|
||||
import {SendTable} from './SendTable';
|
||||
|
||||
export class SendPropDefinition {
|
||||
type: SendPropType;
|
||||
name: string;
|
||||
flags: number;
|
||||
excludeDTName: string|null;
|
||||
lowValue: number;
|
||||
highValue: number;
|
||||
bitCount: number;
|
||||
table: SendTable|null;
|
||||
numElements: number;
|
||||
arrayProperty: SendPropDefinition|null;
|
||||
ownerTableName: string;
|
||||
public type: SendPropType;
|
||||
public name: string;
|
||||
public flags: number;
|
||||
public excludeDTName: string | null;
|
||||
public lowValue: number;
|
||||
public highValue: number;
|
||||
public bitCount: number;
|
||||
public table: SendTable | null;
|
||||
public numElements: number;
|
||||
public arrayProperty: SendPropDefinition | null;
|
||||
public ownerTableName: string;
|
||||
|
||||
constructor(type, name, flags, ownerTableName) {
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
this.flags = flags;
|
||||
this.excludeDTName = null;
|
||||
this.lowValue = 0;
|
||||
this.highValue = 0;
|
||||
this.bitCount = 0;
|
||||
this.table = null;
|
||||
this.numElements = 0;
|
||||
this.arrayProperty = null;
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
this.flags = flags;
|
||||
this.excludeDTName = null;
|
||||
this.lowValue = 0;
|
||||
this.highValue = 0;
|
||||
this.bitCount = 0;
|
||||
this.table = null;
|
||||
this.numElements = 0;
|
||||
this.arrayProperty = null;
|
||||
this.ownerTableName = ownerTableName;
|
||||
}
|
||||
|
||||
hasFlag(flag: SendPropFlag) {
|
||||
return (this.flags & flag) != 0;
|
||||
public hasFlag(flag: SendPropFlag) {
|
||||
return (this.flags & flag) !== 0;
|
||||
}
|
||||
|
||||
isExcludeProp() {
|
||||
public isExcludeProp() {
|
||||
return this.hasFlag(SendPropFlag.SPROP_EXCLUDE);
|
||||
}
|
||||
|
||||
inspect() {
|
||||
let data: any = {
|
||||
public inspect() {
|
||||
const data: any = {
|
||||
fromTable: this.ownerTableName,
|
||||
name: this.name,
|
||||
type: SendPropType[this.type],
|
||||
flags: SendPropDefinition.formatFlags(this.flags),
|
||||
bitCount: this.bitCount
|
||||
name: this.name,
|
||||
type: SendPropType[this.type],
|
||||
flags: this.flags,
|
||||
bitCount: this.bitCount,
|
||||
};
|
||||
if (this.type === SendPropType.DPT_Float) {
|
||||
data.lowValue = this.lowValue;
|
||||
data.lowValue = this.lowValue;
|
||||
data.highValue = this.highValue;
|
||||
}
|
||||
if (this.type === SendPropType.DPT_DataTable && this.table) {
|
||||
|
|
@ -52,19 +53,6 @@ export class SendPropDefinition {
|
|||
|
||||
return data;
|
||||
}
|
||||
|
||||
static formatFlags(flags: number) {
|
||||
let names: string[] = [];
|
||||
for (const name in SendPropFlag) {
|
||||
const flagValue = <SendPropFlag|string>SendPropFlag[name];
|
||||
if (typeof flagValue === 'number') {
|
||||
if (flags & flagValue) {
|
||||
names.push(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
return names;
|
||||
}
|
||||
}
|
||||
|
||||
export enum SendPropType {
|
||||
|
|
@ -75,32 +63,32 @@ export enum SendPropType {
|
|||
DPT_String,
|
||||
DPT_Array,
|
||||
DPT_DataTable,
|
||||
DPT_NUMSendPropTypes
|
||||
DPT_NUMSendPropTypes,
|
||||
}
|
||||
|
||||
|
||||
export enum SendPropFlag {
|
||||
SPROP_UNSIGNED = (1 << 0),// Unsigned integer data.
|
||||
SPROP_COORD = (1 << 1),// If this is set, the float/vector is treated like a world coordinate.
|
||||
// Note that the bit count is ignored in this case.
|
||||
SPROP_NOSCALE = (1 << 2),// For floating point, don't scale into range, just take value as is.
|
||||
SPROP_ROUNDDOWN = (1 << 3),// For floating point, limit high value to range minus one bit unit
|
||||
SPROP_ROUNDUP = (1 << 4),// For floating point, limit low value to range minus one bit unit
|
||||
SPROP_NORMAL = (1 << 5),// If this is set, the vector is treated like a normal (only valid for vectors)
|
||||
SPROP_EXCLUDE = (1 << 6),// This is an exclude prop (not excludED, but it points at another prop to be excluded).
|
||||
SPROP_XYZE = (1 << 7),// Use XYZ/Exponent encoding for vectors.
|
||||
SPROP_INSIDEARRAY = (1 << 8),// This tells us that the property is inside an array, so it shouldn't be put into the
|
||||
// flattened property list. Its array will point at it when it needs to.
|
||||
SPROP_PROXY_ALWAYS_YES = (1 << 9),// Set for datatable props using one of the default datatable proxies like
|
||||
// SendProxy_DataTableToDataTable that always send the data to all clients.
|
||||
SPROP_CHANGES_OFTEN = (1 << 10),// this is an often changed field, moved to head of sendtable so it gets a small index
|
||||
SPROP_IS_A_VECTOR_ELEM = (1 << 11),// Set automatically if SPROP_VECTORELEM is used.
|
||||
SPROP_COLLAPSIBLE = (1 << 12),// Set automatically if it's a datatable with an offset of 0 that doesn't change the pointer
|
||||
// (ie: for all automatically-chained base classes).
|
||||
// In this case, it can get rid of this SendPropDataTable altogether and spare the
|
||||
// trouble of walking the hierarchy more than necessary.
|
||||
SPROP_COORD_MP = (1 << 13),// Like SPROP_COORD, but special handling for multiplayer games
|
||||
SPROP_COORD_MP_LOWPRECISION = (1 << 14),// Like SPROP_COORD, but special handling for multiplayer games where the fractional component only gets a 3 bits instead of 5
|
||||
SPROP_COORD_MP_INTEGRAL = (1 << 15),// SPROP_COORD_MP, but coordinates are rounded to integral boundaries
|
||||
SPROP_VARINT = (1 << 5)
|
||||
SPROP_UNSIGNED = (1 << 0), // Unsigned integer data.
|
||||
SPROP_COORD = (1 << 1), // If this is set, the float/vector is treated like a world coordinate.
|
||||
// Note that the bit count is ignored in this case.
|
||||
SPROP_NOSCALE = (1 << 2), // For floating point, don't scale into range, just take value as is.
|
||||
SPROP_ROUNDDOWN = (1 << 3), // For floating point, limit high value to range minus one bit unit
|
||||
SPROP_ROUNDUP = (1 << 4), // For floating point, limit low value to range minus one bit unit
|
||||
SPROP_NORMAL = (1 << 5), // If this is set, the vector is treated like a normal (only valid for vectors)
|
||||
SPROP_EXCLUDE = (1 << 6), // This is an exclude prop (not excludED, but it points at another prop to be excluded).
|
||||
SPROP_XYZE = (1 << 7), // Use XYZ/Exponent encoding for vectors.
|
||||
SPROP_INSIDEARRAY = (1 << 8), // This tells us that the property is inside an array, so it shouldn't be put into the
|
||||
// flattened property list. Its array will point at it when it needs to.
|
||||
SPROP_PROXY_ALWAYS_YES = (1 << 9), // Set for datatable props using one of the default datatable proxies like
|
||||
// SendProxy_DataTableToDataTable that always send the data to all clients.
|
||||
SPROP_CHANGES_OFTEN = (1 << 10), // this is an often changed field, moved to head of sendtable so it gets a small index
|
||||
SPROP_IS_A_VECTOR_ELEM = (1 << 11), // Set automatically if SPROP_VECTORELEM is used.
|
||||
SPROP_COLLAPSIBLE = (1 << 12), // Set automatically if it's a datatable with an offset of 0 that doesn't change the pointer
|
||||
// (ie: for all automatically-chained base classes).
|
||||
// In this case, it can get rid of this SendPropDataTable altogether and spare the
|
||||
// trouble of walking the hierarchy more than necessary.
|
||||
SPROP_COORD_MP = (1 << 13), // Like SPROP_COORD, but special handling for multiplayer games
|
||||
SPROP_COORD_MP_LOWPRECISION = (1 << 14), // Like SPROP_COORD, but special handling for multiplayer games
|
||||
// where the fractional component only gets a 3 bits instead of 5
|
||||
SPROP_COORD_MP_INTEGRAL = (1 << 15), // SPROP_COORD_MP, but coordinates are rounded to integral boundaries
|
||||
SPROP_VARINT = (1 << 5),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,55 +1,35 @@
|
|||
import {SendPropDefinition, SendPropType, SendPropFlag} from './SendPropDefinition';
|
||||
import {SendPropDefinition, SendPropFlag, SendPropType} from './SendPropDefinition';
|
||||
|
||||
export class SendTable {
|
||||
name: string;
|
||||
props: SendPropDefinition[];
|
||||
private _flattenedProps: SendPropDefinition[];
|
||||
public name: string;
|
||||
public props: SendPropDefinition[];
|
||||
private cachedFlattenedProps: SendPropDefinition[];
|
||||
|
||||
constructor(name) {
|
||||
this.name = name;
|
||||
this.props = [];
|
||||
this._flattenedProps = [];
|
||||
this.cachedFlattenedProps = [];
|
||||
}
|
||||
|
||||
addProp(prop) {
|
||||
public addProp(prop) {
|
||||
this.props.push(prop);
|
||||
}
|
||||
|
||||
private flatten() {
|
||||
let excludes: SendPropDefinition[] = this.excludes;
|
||||
let props: SendPropDefinition[] = [];
|
||||
this.getAllProps(excludes, props);
|
||||
|
||||
// sort often changed props before the others
|
||||
let start = 0;
|
||||
for (let i = 0; i < props.length; i++) {
|
||||
if (props[i].hasFlag(SendPropFlag.SPROP_CHANGES_OFTEN)) {
|
||||
if (i != start) {
|
||||
const temp = props[i];
|
||||
props[i] = props[start];
|
||||
props[start] = temp;
|
||||
}
|
||||
start++;
|
||||
}
|
||||
}
|
||||
this._flattenedProps = props;
|
||||
}
|
||||
|
||||
getAllProps(excludes: SendPropDefinition[], props: SendPropDefinition[]) {
|
||||
let localProps = [];
|
||||
public getAllProps(excludes: SendPropDefinition[], props: SendPropDefinition[]) {
|
||||
const localProps = [];
|
||||
this.getAllPropsIteratorProps(excludes, localProps, props);
|
||||
for (const localProp of localProps) {
|
||||
props.push(localProp);
|
||||
}
|
||||
}
|
||||
|
||||
getAllPropsIteratorProps(excludes: SendPropDefinition[], props: SendPropDefinition[], childProps: SendPropDefinition[]) {
|
||||
public getAllPropsIteratorProps(excludes: SendPropDefinition[], props: SendPropDefinition[], childProps: SendPropDefinition[]) {
|
||||
for (const prop of this.props) {
|
||||
if (prop.hasFlag(SendPropFlag.SPROP_EXCLUDE) || excludes.indexOf(prop) !== -1) {
|
||||
continue;
|
||||
}
|
||||
if (excludes.filter((exclude) => {
|
||||
return exclude.name == prop.name && exclude.excludeDTName == prop.ownerTableName;
|
||||
return exclude.name === prop.name && exclude.excludeDTName === prop.ownerTableName;
|
||||
}).length > 0) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -67,10 +47,10 @@ export class SendTable {
|
|||
}
|
||||
|
||||
get flattenedProps() {
|
||||
if (this._flattenedProps.length === 0) {
|
||||
if (this.cachedFlattenedProps.length === 0) {
|
||||
this.flatten();
|
||||
}
|
||||
return this._flattenedProps;
|
||||
return this.cachedFlattenedProps;
|
||||
}
|
||||
|
||||
get excludes() {
|
||||
|
|
@ -84,7 +64,24 @@ export class SendTable {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private flatten() {
|
||||
const excludes: SendPropDefinition[] = this.excludes;
|
||||
const props: SendPropDefinition[] = [];
|
||||
this.getAllProps(excludes, props);
|
||||
|
||||
// sort often changed props before the others
|
||||
let start = 0;
|
||||
for (let i = 0; i < props.length; i++) {
|
||||
if (props[i].hasFlag(SendPropFlag.SPROP_CHANGES_OFTEN)) {
|
||||
if (i !== start) {
|
||||
const temp = props[i];
|
||||
props[i] = props[start];
|
||||
props[start] = temp;
|
||||
}
|
||||
start++;
|
||||
}
|
||||
}
|
||||
this.cachedFlattenedProps = props;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
export class ServerClass {
|
||||
id: number;
|
||||
name: string;
|
||||
dataTable: string;
|
||||
public id: number;
|
||||
public name: string;
|
||||
public dataTable: string;
|
||||
|
||||
constructor(id:number, name:string, dataTable:string) {
|
||||
constructor(id: number, name: string, dataTable: string) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.dataTable = dataTable;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import {BitStream} from "bit-buffer";
|
||||
import {BitStream} from 'bit-buffer';
|
||||
export interface StringTable {
|
||||
name: string;
|
||||
entries: StringTableEntry[],
|
||||
entries: StringTableEntry[];
|
||||
maxEntries: number;
|
||||
fixedUserDataSize?: number;
|
||||
fixedUserDataSizeBits?: number;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
export interface UserInfo {
|
||||
name: string
|
||||
name: string;
|
||||
userId: number;
|
||||
steamId: string;
|
||||
entityId: number;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
export class Vector {
|
||||
x: number;
|
||||
y: number;
|
||||
z: number;
|
||||
public x: number;
|
||||
public y: number;
|
||||
public z: number;
|
||||
|
||||
constructor(x, y, z) {
|
||||
this.x = x;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import {Vector} from "./Vector";
|
||||
import {Vector} from './Vector';
|
||||
export interface World {
|
||||
boundaryMin: Vector;
|
||||
boundaryMax: Vector;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue