1
0
Fork 0
mirror of https://github.com/demostf/demo.js synced 2026-06-04 00:54:14 +02:00

initial typescript conversions

This commit is contained in:
Robin Appelman 2016-12-18 15:36:39 +01:00
commit 06860cc3fe
12 changed files with 96 additions and 16 deletions

2
.gitignore vendored
View file

@ -1,2 +1,4 @@
node_modules
build build
*.dem *.dem
*.txt

12
Makefile Normal file
View file

@ -0,0 +1,12 @@
TS_JS := $(TS_SRC:.ts=.js)
.PHONY: all tsc
all: $(TS_JS)
$(TS_JS): %.js: %.ts js.stub
$(TSLINT) $<
js.stub: $(TS_SRC)
$(TSC) $^
@touch $@

View file

@ -14,6 +14,7 @@
"typedarray-to-buffer": "^3.1.2" "typedarray-to-buffer": "^3.1.2"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^6.0.52",
"babel-preset-es2015-node6": "^0.4.0" "babel-preset-es2015-node6": "^0.4.0"
} }
} }

View file

@ -1,15 +1,26 @@
import {ServerClass} from "./ServerClass";
import {SendTable} from "./SendTable";
import {SendProp} from "./SendProp";
import {SendPropDefinition} from "./SendPropDefinition";
export class Entity { export class Entity {
constructor(serverClass, sentTable, entityIndex, serialNumber) { serverClass: ServerClass;
sendTable: SendTable;
entityIndex: number;
serialNumber: number;
props: SendProp[];
inPVS: boolean;
constructor(serverClass: ServerClass, sendTable: SendTable, entityIndex: number, serialNumber: number) {
this.serverClass = serverClass; this.serverClass = serverClass;
this.sendTable = sentTable; this.sendTable = sendTable;
this.entityIndex = entityIndex; this.entityIndex = entityIndex;
this.serialNumber = serialNumber; this.serialNumber = serialNumber;
this.props = []; this.props = [];
this.inPVS = false; this.inPVS = false;
} }
getPropByDefinition(definition) { getPropByDefinition(definition: SendPropDefinition) {
for (let i = 0; i < this.props; i++) { for (let i = 0; i < this.props.length; i++) {
if (this.props[i].definition === definition) { if (this.props[i].definition === definition) {
return this.props[i]; return this.props[i];
} }

View file

@ -1,13 +1,17 @@
import clone from 'clone'; import * as clone from 'clone';
import {SendPropDefinition} from "./SendPropDefinition";
export class SentProp { export class SendProp {
constructor(definition) { definition: SendPropDefinition;
value: any;
constructor(definition: SendPropDefinition) {
this.definition = definition; this.definition = definition;
this.value = null; this.value = null;
} }
clone() { clone() {
const prop = new SentProp(this.definition); const prop = new SendProp(this.definition);
prop.value = clone(this.value); prop.value = clone(this.value);
return prop; return prop;
} }

13
src/Data/ServerClass.ts Normal file
View file

@ -0,0 +1,13 @@
import {SendTable} from "./SendTable";
export class ServerClass {
id: number;
name: string;
dataTable: SendTable;
constructor(id, name, dataTable) {
this.id = id;
this.name = name;
this.dataTable = dataTable;
}
}

View file

@ -1,5 +1,6 @@
import {SendTable} from './Data/SendTable'; import {SendTable} from './Data/SendTable';
import {SendPropDefinition} from './Data/SendPropDefinition'; import {SendPropDefinition} from './Data/SendPropDefinition';
import {ServerClass} from './Data/ServerClass';
var DataTableParser = function (type, tick, stream, length, match) { var DataTableParser = function (type, tick, stream, length, match) {
this.type = type; this.type = type;
@ -104,10 +105,4 @@ DataTableParser.prototype.parse = function () {
return tables; return tables;
}; };
var ServerClass = function (id, name, dataTable) {
this.id = id;
this.name = name;
this.dataTable = dataTable;
};
module.exports = DataTableParser; module.exports = DataTableParser;

View file

@ -1,6 +1,6 @@
import {SendPropParser} from '../../Parser/SendPropParser'; import {SendPropParser} from '../../Parser/SendPropParser';
import {Entity} from '../../Data/Entity'; import {Entity} from '../../Data/Entity';
import {SentProp} from '../../Data/SendProp'; import {SendProp} from '../../Data/SendProp';
var PVS = { var PVS = {
PRESERVE: 0, PRESERVE: 0,
@ -169,7 +169,7 @@ var applyEntityUpdate = function (entity, stream) {
if (existingProp) { if (existingProp) {
prop = existingProp; prop = existingProp;
} else { } else {
prop = new SentProp(propDefinition); prop = new SendProp(propDefinition);
} }
prop.value = SendPropParser.decode(propDefinition, stream); prop.value = SendPropParser.decode(propDefinition, stream);
console.log(prop); console.log(prop);

5
typings.json Normal file
View file

@ -0,0 +1,5 @@
{
"devDependencies": {
"clone": "registry:dt/clone#0.1.11+20160428043022"
}
}

1
typings/index.d.ts vendored Normal file
View file

@ -0,0 +1 @@
/// <reference path="modules/clone/index.d.ts" />

28
typings/modules/clone/index.d.ts vendored Normal file
View file

@ -0,0 +1,28 @@
// Generated by typings
// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/337587de8c13868283993bfacdcdd1a0f3291e7f/clone/index.d.ts
declare module 'clone' {
// Type definitions for clone 0.1.11
// Project: https://github.com/pvorb/node-clone
// Definitions by: Kieran Simpson <https://github.com/kierans/DefinitelyTyped>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/**
* See clone JS source for API docs
*/
/**
* @param val the value that you want to clone, any type allowed
* @param circular Call clone with circular set to false if you are certain that obj contains no circular references. This will give better performance if needed. There is no error if undefined or null is passed as obj.
* @param depth to wich the object is to be cloned (optional, defaults to infinity)
*/
function clone<T>(val: T, circular?: boolean, depth?: number): T;
namespace clone {
/**
* @param obj the object that you want to clone
*/
function clonePrototype<T>(obj: T): T;
}
export = clone
}

View file

@ -0,0 +1,8 @@
{
"resolution": "main",
"tree": {
"src": "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/337587de8c13868283993bfacdcdd1a0f3291e7f/clone/index.d.ts",
"raw": "registry:dt/clone#0.1.11+20160428043022",
"typings": "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/337587de8c13868283993bfacdcdd1a0f3291e7f/clone/index.d.ts"
}
}