teeworlds 2.1.3 → 2.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +16 -9
- package/index.ts +5 -9
- package/lib/MsgPacker.js +4 -3
- package/lib/MsgPacker.ts +2 -6
- package/lib/MsgUnpacker.js +0 -3
- package/lib/MsgUnpacker.ts +1 -6
- package/lib/client.js +359 -280
- package/lib/client.ts +381 -200
- package/lib/movement.js +54 -0
- package/lib/movement.ts +63 -0
- package/lib/snapshot.js +6 -14
- package/lib/snapshot.ts +9 -15
- package/package.json +1 -1
package/lib/movement.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
;
|
|
4
|
+
var Movement = /** @class */ (function () {
|
|
5
|
+
function Movement() {
|
|
6
|
+
this.input = { m_Direction: 0, m_Fire: 0, m_Hook: 0, m_Jump: 0, m_NextWeapon: 0, m_PlayerFlags: 1, m_PrevWeapon: 0, m_TargetX: 0, m_TargetY: 0, m_WantedWeapon: 1 };
|
|
7
|
+
}
|
|
8
|
+
Movement.prototype.RunLeft = function () {
|
|
9
|
+
this.input.m_Direction = -1;
|
|
10
|
+
};
|
|
11
|
+
Movement.prototype.RunRight = function () {
|
|
12
|
+
this.input.m_Direction = 1;
|
|
13
|
+
};
|
|
14
|
+
Movement.prototype.RunStop = function () {
|
|
15
|
+
this.input.m_Direction = 0;
|
|
16
|
+
};
|
|
17
|
+
Movement.prototype.Jump = function (state) {
|
|
18
|
+
if (state === void 0) { state = true; }
|
|
19
|
+
this.input.m_Jump = state ? 1 : 0;
|
|
20
|
+
};
|
|
21
|
+
Movement.prototype.Fire = function () {
|
|
22
|
+
this.input.m_Fire = 1;
|
|
23
|
+
};
|
|
24
|
+
Movement.prototype.Hook = function (state) {
|
|
25
|
+
if (state === void 0) { state = true; }
|
|
26
|
+
this.input.m_Hook = state ? 1 : 0;
|
|
27
|
+
};
|
|
28
|
+
Movement.prototype.NextWeapon = function () {
|
|
29
|
+
this.input.m_NextWeapon = 1;
|
|
30
|
+
this.WantedWeapon(0);
|
|
31
|
+
};
|
|
32
|
+
Movement.prototype.PrevWeapon = function () {
|
|
33
|
+
this.input.m_PrevWeapon = 1;
|
|
34
|
+
this.WantedWeapon(0);
|
|
35
|
+
};
|
|
36
|
+
Movement.prototype.WantedWeapon = function (weapon) {
|
|
37
|
+
this.input.m_WantedWeapon = weapon;
|
|
38
|
+
};
|
|
39
|
+
Movement.prototype.SetAim = function (x, y) {
|
|
40
|
+
this.input.m_TargetX = x;
|
|
41
|
+
this.input.m_TargetY = y;
|
|
42
|
+
};
|
|
43
|
+
Movement.prototype.Reset = function () {
|
|
44
|
+
this.input.m_Direction = 0;
|
|
45
|
+
this.input.m_Jump = 0;
|
|
46
|
+
this.input.m_Fire = 0;
|
|
47
|
+
this.input.m_Hook = 0;
|
|
48
|
+
this.input.m_PlayerFlags = 0;
|
|
49
|
+
this.input.m_NextWeapon = 0;
|
|
50
|
+
this.input.m_PrevWeapon = 0;
|
|
51
|
+
};
|
|
52
|
+
return Movement;
|
|
53
|
+
}());
|
|
54
|
+
exports.default = Movement;
|
package/lib/movement.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
interface NetObj_PlayerInput {
|
|
2
|
+
m_Direction: number,
|
|
3
|
+
m_TargetX: number,
|
|
4
|
+
m_TargetY: number,
|
|
5
|
+
m_Jump: number,
|
|
6
|
+
m_Fire: number,
|
|
7
|
+
m_Hook: number,
|
|
8
|
+
m_PlayerFlags: number,
|
|
9
|
+
m_WantedWeapon: number,
|
|
10
|
+
m_NextWeapon: number,
|
|
11
|
+
m_PrevWeapon: number
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
class Movement {
|
|
15
|
+
input: NetObj_PlayerInput;
|
|
16
|
+
constructor() {
|
|
17
|
+
this.input = {m_Direction: 0, m_Fire: 0, m_Hook: 0, m_Jump: 0, m_NextWeapon: 0, m_PlayerFlags: 1, m_PrevWeapon: 0, m_TargetX: 0, m_TargetY: 0, m_WantedWeapon: 1} as NetObj_PlayerInput;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
RunLeft() {
|
|
21
|
+
this.input.m_Direction = -1;
|
|
22
|
+
}
|
|
23
|
+
RunRight() {
|
|
24
|
+
this.input.m_Direction = 1;
|
|
25
|
+
}
|
|
26
|
+
RunStop() {
|
|
27
|
+
this.input.m_Direction = 0;
|
|
28
|
+
}
|
|
29
|
+
Jump(state = true) {
|
|
30
|
+
this.input.m_Jump = state ? 1 : 0;
|
|
31
|
+
}
|
|
32
|
+
Fire() {
|
|
33
|
+
this.input.m_Fire = 1;
|
|
34
|
+
}
|
|
35
|
+
Hook(state = true) {
|
|
36
|
+
this.input.m_Hook = state ? 1 : 0;
|
|
37
|
+
}
|
|
38
|
+
NextWeapon() {
|
|
39
|
+
this.input.m_NextWeapon = 1;
|
|
40
|
+
this.WantedWeapon(0);
|
|
41
|
+
}
|
|
42
|
+
PrevWeapon() {
|
|
43
|
+
this.input.m_PrevWeapon = 1;
|
|
44
|
+
this.WantedWeapon(0);
|
|
45
|
+
}
|
|
46
|
+
WantedWeapon(weapon: number) {
|
|
47
|
+
this.input.m_WantedWeapon = weapon;
|
|
48
|
+
}
|
|
49
|
+
SetAim(x: number, y: number) {
|
|
50
|
+
this.input.m_TargetX = x;
|
|
51
|
+
this.input.m_TargetY = y;
|
|
52
|
+
}
|
|
53
|
+
Reset() {
|
|
54
|
+
this.input.m_Direction = 0;
|
|
55
|
+
this.input.m_Jump = 0;
|
|
56
|
+
this.input.m_Fire = 0;
|
|
57
|
+
this.input.m_Hook = 0;
|
|
58
|
+
this.input.m_PlayerFlags = 0;
|
|
59
|
+
this.input.m_NextWeapon = 0;
|
|
60
|
+
this.input.m_PrevWeapon = 0;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export default Movement;
|
package/lib/snapshot.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Snapshot = void 0;
|
|
3
|
+
exports.Snapshot = exports.items = exports.itemAppendix = void 0;
|
|
4
4
|
var MsgUnpacker_1 = require("./MsgUnpacker");
|
|
5
5
|
var decoder = new TextDecoder('utf-8');
|
|
6
|
-
|
|
6
|
+
exports.itemAppendix = [
|
|
7
7
|
{ "type_id": 0, "size": 0, "name": "obj_ex" },
|
|
8
8
|
{ "type_id": 1, "size": 10, "name": "obj_player_input" },
|
|
9
9
|
{ "type_id": 2, "size": 6, "name": "obj_projectile" },
|
|
@@ -49,7 +49,7 @@ var items;
|
|
|
49
49
|
items[items["EVENT_SOUND_GLOBAL"] = 18] = "EVENT_SOUND_GLOBAL";
|
|
50
50
|
items[items["EVENT_SOUND_WORLD"] = 19] = "EVENT_SOUND_WORLD";
|
|
51
51
|
items[items["EVENT_DAMAGE_INDICATOR"] = 20] = "EVENT_DAMAGE_INDICATOR";
|
|
52
|
-
})(items || (items = {}));
|
|
52
|
+
})(items = exports.items || (exports.items = {}));
|
|
53
53
|
var Snapshot = /** @class */ (function () {
|
|
54
54
|
function Snapshot() {
|
|
55
55
|
}
|
|
@@ -69,7 +69,7 @@ var Snapshot = /** @class */ (function () {
|
|
|
69
69
|
}
|
|
70
70
|
pIntz.splice(-1, 1);
|
|
71
71
|
pStr = decoder.decode(new Uint8Array(pIntz));
|
|
72
|
-
pStr = pStr.replace(/\
|
|
72
|
+
pStr = pStr.replace(/\0.*/g, ''); // Remove content from first null char to end.
|
|
73
73
|
return pStr;
|
|
74
74
|
};
|
|
75
75
|
Snapshot.prototype.parseItem = function (data, Type) {
|
|
@@ -290,18 +290,13 @@ var Snapshot = /** @class */ (function () {
|
|
|
290
290
|
};
|
|
291
291
|
Snapshot.prototype.unpackSnapshot = function (snap, lost) {
|
|
292
292
|
if (lost === void 0) { lost = 0; }
|
|
293
|
-
// var size = unpackInt(snap).result;
|
|
294
293
|
var unpacker = new MsgUnpacker_1.MsgUnpacker(snap);
|
|
295
|
-
// snap = unpackInt(snap).remaining; // size
|
|
296
294
|
/* key = (((type_id) << 16) | (id))
|
|
297
295
|
* key_to_id = ((key) & 0xffff)
|
|
298
296
|
* key_to_type_id = ((key >> 16) & 0xffff)
|
|
299
297
|
* https://github.com/heinrich5991/libtw2/blob/master/snapshot/src/
|
|
300
298
|
* https://github.com/heinrich5991/libtw2/blob/master/doc/snapshot.md
|
|
301
299
|
*/
|
|
302
|
-
// snap = unpackInt(snap).remaining;
|
|
303
|
-
// console.log(unpackInt(snap).result, "tick?") // key?
|
|
304
|
-
// snap = unpackInt(snap).remaining;
|
|
305
300
|
var num_removed_items = unpacker.unpackInt();
|
|
306
301
|
var num_item_deltas = unpacker.unpackInt();
|
|
307
302
|
unpacker.unpackInt(); // _zero padding
|
|
@@ -326,8 +321,8 @@ var Snapshot = /** @class */ (function () {
|
|
|
326
321
|
var id = unpacker.unpackInt();
|
|
327
322
|
var key = (((type_id) << 16) | (id));
|
|
328
323
|
var _size = void 0;
|
|
329
|
-
if (type_id > 0 && type_id < itemAppendix.length) {
|
|
330
|
-
_size = itemAppendix[type_id].size;
|
|
324
|
+
if (type_id > 0 && type_id < exports.itemAppendix.length) {
|
|
325
|
+
_size = exports.itemAppendix[type_id].size;
|
|
331
326
|
}
|
|
332
327
|
else
|
|
333
328
|
_size = unpacker.unpackInt();
|
|
@@ -336,10 +331,7 @@ var Snapshot = /** @class */ (function () {
|
|
|
336
331
|
if (unpacker.remaining.length > 0)
|
|
337
332
|
data.push(unpacker.unpackInt());
|
|
338
333
|
}
|
|
339
|
-
// console.log(type_id, id, _size, data);
|
|
340
334
|
var parsed = this.parseItem(data, type_id);
|
|
341
|
-
// console.log(data)
|
|
342
|
-
// console.log('')
|
|
343
335
|
items.items.push({ data: data, parsed: parsed, type_id: type_id, id: id, key: key });
|
|
344
336
|
}
|
|
345
337
|
return items;
|
package/lib/snapshot.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MsgUnpacker } from "./MsgUnpacker";
|
|
2
2
|
var decoder = new TextDecoder('utf-8');
|
|
3
3
|
|
|
4
|
-
const itemAppendix: {"type_id": number, "size": number, "name": string}[] = [
|
|
4
|
+
export const itemAppendix: {"type_id": number, "size": number, "name": string}[] = [
|
|
5
5
|
{"type_id": 0, "size": 0, "name": "obj_ex"},
|
|
6
6
|
{"type_id": 1, "size": 10, "name": "obj_player_input"},
|
|
7
7
|
{"type_id": 2, "size": 6, "name": "obj_projectile"},
|
|
@@ -24,7 +24,8 @@ const itemAppendix: {"type_id": number, "size": number, "name": string}[] = [
|
|
|
24
24
|
{"type_id": 19, "size": 3, "name": "event_sound_world"},
|
|
25
25
|
{"type_id": 20, "size": 3, "name": "event_damage_indicator"}
|
|
26
26
|
]
|
|
27
|
-
|
|
27
|
+
|
|
28
|
+
export enum items {
|
|
28
29
|
OBJ_EX,
|
|
29
30
|
OBJ_PLAYER_INPUT,
|
|
30
31
|
OBJ_PROJECTILE,
|
|
@@ -47,9 +48,10 @@ enum items {
|
|
|
47
48
|
EVENT_SOUND_WORLD,
|
|
48
49
|
EVENT_DAMAGE_INDICATOR
|
|
49
50
|
}
|
|
50
|
-
type Item = PlayerInput | PlayerInfo | Projectile | Laser | Pickup | Flag | GameInfo | GameData | CharacterCore | Character | PlayerInfo | ClientInfo | SpectatorInfo | Common | Explosion | Spawn |HammerHit | Death | SoundGlobal | SoundWorld | DamageInd | DdnetCharacter;
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
export type Item = PlayerInput | PlayerInfo | Projectile | Laser | Pickup | Flag | GameInfo | GameData | CharacterCore | Character | PlayerInfo | ClientInfo | SpectatorInfo | Common | Explosion | Spawn |HammerHit | Death | SoundGlobal | SoundWorld | DamageInd | DdnetCharacter;
|
|
53
|
+
|
|
54
|
+
export class Snapshot {
|
|
53
55
|
private IntsToStr(pInts: number[]): string {
|
|
54
56
|
var pIntz: number[] = [];
|
|
55
57
|
var pStr = ''
|
|
@@ -65,7 +67,8 @@ class Snapshot {
|
|
|
65
67
|
}
|
|
66
68
|
pIntz.splice(-1, 1)
|
|
67
69
|
pStr = decoder.decode(new Uint8Array(pIntz));
|
|
68
|
-
|
|
70
|
+
|
|
71
|
+
pStr = pStr.replace(/\0.*/g, ''); // Remove content from first null char to end.
|
|
69
72
|
return pStr;
|
|
70
73
|
}
|
|
71
74
|
private parseItem(data: number[], Type: number): Item {
|
|
@@ -288,10 +291,8 @@ class Snapshot {
|
|
|
288
291
|
return _item;
|
|
289
292
|
}
|
|
290
293
|
unpackSnapshot(snap: number[], lost = 0) {
|
|
291
|
-
// var size = unpackInt(snap).result;
|
|
292
294
|
let unpacker = new MsgUnpacker(snap);
|
|
293
295
|
|
|
294
|
-
// snap = unpackInt(snap).remaining; // size
|
|
295
296
|
|
|
296
297
|
/* key = (((type_id) << 16) | (id))
|
|
297
298
|
* key_to_id = ((key) & 0xffff)
|
|
@@ -300,9 +301,6 @@ class Snapshot {
|
|
|
300
301
|
* https://github.com/heinrich5991/libtw2/blob/master/doc/snapshot.md
|
|
301
302
|
*/
|
|
302
303
|
|
|
303
|
-
// snap = unpackInt(snap).remaining;
|
|
304
|
-
// console.log(unpackInt(snap).result, "tick?") // key?
|
|
305
|
-
// snap = unpackInt(snap).remaining;
|
|
306
304
|
let num_removed_items = unpacker.unpackInt();
|
|
307
305
|
let num_item_deltas = unpacker.unpackInt();
|
|
308
306
|
unpacker.unpackInt(); // _zero padding
|
|
@@ -340,16 +338,12 @@ class Snapshot {
|
|
|
340
338
|
if (unpacker.remaining.length > 0)
|
|
341
339
|
data.push(unpacker.unpackInt());
|
|
342
340
|
}
|
|
343
|
-
|
|
341
|
+
|
|
344
342
|
let parsed = this.parseItem(data, type_id)
|
|
345
343
|
|
|
346
|
-
// console.log(data)
|
|
347
|
-
// console.log('')
|
|
348
344
|
items.items.push({data, parsed, type_id, id, key})
|
|
349
345
|
}
|
|
350
346
|
|
|
351
347
|
|
|
352
348
|
return items;
|
|
353
349
|
}}
|
|
354
|
-
// module.exports = MsgPacker;
|
|
355
|
-
export {Snapshot};
|