mirror of
https://github.com/demostf/demo.js
synced 2026-06-03 16:44:12 +02:00
initial typescript conversions
This commit is contained in:
parent
564e8995c7
commit
06860cc3fe
12 changed files with 96 additions and 16 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,2 +1,4 @@
|
|||
node_modules
|
||||
build
|
||||
*.dem
|
||||
*.txt
|
||||
|
|
|
|||
12
Makefile
Normal file
12
Makefile
Normal 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 $@
|
||||
|
|
@ -14,6 +14,7 @@
|
|||
"typedarray-to-buffer": "^3.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^6.0.52",
|
||||
"babel-preset-es2015-node6": "^0.4.0"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +1,26 @@
|
|||
import {ServerClass} from "./ServerClass";
|
||||
import {SendTable} from "./SendTable";
|
||||
import {SendProp} from "./SendProp";
|
||||
import {SendPropDefinition} from "./SendPropDefinition";
|
||||
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.sendTable = sentTable;
|
||||
this.sendTable = sendTable;
|
||||
this.entityIndex = entityIndex;
|
||||
this.serialNumber = serialNumber;
|
||||
this.props = [];
|
||||
this.inPVS = false;
|
||||
}
|
||||
|
||||
getPropByDefinition(definition) {
|
||||
for (let i = 0; i < this.props; i++) {
|
||||
getPropByDefinition(definition: SendPropDefinition) {
|
||||
for (let i = 0; i < this.props.length; i++) {
|
||||
if (this.props[i].definition === definition) {
|
||||
return this.props[i];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,17 @@
|
|||
import clone from 'clone';
|
||||
import * as clone from 'clone';
|
||||
import {SendPropDefinition} from "./SendPropDefinition";
|
||||
|
||||
export class SentProp {
|
||||
constructor(definition) {
|
||||
export class SendProp {
|
||||
definition: SendPropDefinition;
|
||||
value: any;
|
||||
|
||||
constructor(definition: SendPropDefinition) {
|
||||
this.definition = definition;
|
||||
this.value = null;
|
||||
}
|
||||
|
||||
clone() {
|
||||
const prop = new SentProp(this.definition);
|
||||
const prop = new SendProp(this.definition);
|
||||
prop.value = clone(this.value);
|
||||
return prop;
|
||||
}
|
||||
|
|
|
|||
13
src/Data/ServerClass.ts
Normal file
13
src/Data/ServerClass.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
import {SendTable} from './Data/SendTable';
|
||||
import {SendPropDefinition} from './Data/SendPropDefinition';
|
||||
import {ServerClass} from './Data/ServerClass';
|
||||
|
||||
var DataTableParser = function (type, tick, stream, length, match) {
|
||||
this.type = type;
|
||||
|
|
@ -104,10 +105,4 @@ DataTableParser.prototype.parse = function () {
|
|||
return tables;
|
||||
};
|
||||
|
||||
var ServerClass = function (id, name, dataTable) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.dataTable = dataTable;
|
||||
};
|
||||
|
||||
module.exports = DataTableParser;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import {SendPropParser} from '../../Parser/SendPropParser';
|
||||
import {Entity} from '../../Data/Entity';
|
||||
import {SentProp} from '../../Data/SendProp';
|
||||
import {SendProp} from '../../Data/SendProp';
|
||||
|
||||
var PVS = {
|
||||
PRESERVE: 0,
|
||||
|
|
@ -169,7 +169,7 @@ var applyEntityUpdate = function (entity, stream) {
|
|||
if (existingProp) {
|
||||
prop = existingProp;
|
||||
} else {
|
||||
prop = new SentProp(propDefinition);
|
||||
prop = new SendProp(propDefinition);
|
||||
}
|
||||
prop.value = SendPropParser.decode(propDefinition, stream);
|
||||
console.log(prop);
|
||||
|
|
|
|||
5
typings.json
Normal file
5
typings.json
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"devDependencies": {
|
||||
"clone": "registry:dt/clone#0.1.11+20160428043022"
|
||||
}
|
||||
}
|
||||
1
typings/index.d.ts
vendored
Normal file
1
typings/index.d.ts
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
/// <reference path="modules/clone/index.d.ts" />
|
||||
28
typings/modules/clone/index.d.ts
vendored
Normal file
28
typings/modules/clone/index.d.ts
vendored
Normal 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
|
||||
}
|
||||
8
typings/modules/clone/typings.json
Normal file
8
typings/modules/clone/typings.json
Normal 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"
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue