teeworlds 2.1.3 → 2.1.5

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.
@@ -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.ts CHANGED
@@ -352,4 +352,4 @@ class Snapshot {
352
352
  return items;
353
353
  }}
354
354
  // module.exports = MsgPacker;
355
- export {Snapshot};
355
+ export {Snapshot};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teeworlds",
3
- "version": "2.1.3",
3
+ "version": "2.1.5",
4
4
  "description": "Library for (ingame) teeworlds bots.",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
package/lib/MsgPacker.js DELETED
@@ -1,53 +0,0 @@
1
- "use strict";
2
- var MsgPacker = /** @class */ (function () {
3
- function MsgPacker(msg, sys) {
4
- this.result = Buffer.from([2 * msg + (sys ? 1 : 0)]); // booleans turn into int automatically.
5
- this.sys = sys;
6
- }
7
- MsgPacker.prototype.AddString = function (str) {
8
- this.result = Buffer.concat([this.result, Buffer.from(str), Buffer.from([0x00])]);
9
- };
10
- MsgPacker.prototype.AddBuffer = function (buffer) {
11
- this.result = Buffer.concat([this.result, buffer]);
12
- };
13
- MsgPacker.prototype.AddInt = function (i) {
14
- var result = [];
15
- var pDst = (i >> 25) & 0x40;
16
- var i = i ^ (i >> 31);
17
- pDst |= i & 0x3f;
18
- i >>= 6;
19
- if (i) {
20
- pDst |= 0x80;
21
- result.push(pDst);
22
- while (true) {
23
- pDst++;
24
- pDst = i & (0x7f);
25
- i >>= 7;
26
- pDst |= (Number(i != 0)) << 7;
27
- result.push(pDst);
28
- if (!i)
29
- break;
30
- }
31
- }
32
- else
33
- result.push(pDst);
34
- // ... i'll just stop trying to understand.
35
- this.result = Buffer.concat([this.result, Buffer.from(result)]);
36
- };
37
- Object.defineProperty(MsgPacker.prototype, "size", {
38
- get: function () {
39
- return this.result.byteLength;
40
- },
41
- enumerable: false,
42
- configurable: true
43
- });
44
- Object.defineProperty(MsgPacker.prototype, "buffer", {
45
- get: function () {
46
- return this.result;
47
- },
48
- enumerable: false,
49
- configurable: true
50
- });
51
- return MsgPacker;
52
- }());
53
- module.exports = MsgPacker;
@@ -1,56 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MsgUnpacker = exports.unpackString = exports.unpackInt = void 0;
4
- var decoder = new TextDecoder('utf-8');
5
- function unpackInt(pSrc) {
6
- var result = 0;
7
- var len = 1;
8
- var iter = pSrc[Symbol.iterator]();
9
- var src = iter.next();
10
- src = src.value;
11
- var sign = ((src >> 6) & 1);
12
- result |= (src & 63);
13
- for (var i = 0; i < 4; i++) {
14
- if ((src & 128) === 0)
15
- break;
16
- src = iter.next();
17
- src = src.value;
18
- len++;
19
- result |= ((src & 127)) << (6 + 7 * i);
20
- }
21
- result ^= -sign;
22
- return { result: result, remaining: Array.from(iter) };
23
- }
24
- exports.unpackInt = unpackInt;
25
- function unpackString(pSrc) {
26
- var result = pSrc.slice(0, pSrc.indexOf(0));
27
- pSrc = pSrc.slice(pSrc.indexOf(0), pSrc.length);
28
- return { result: decoder.decode(new Uint8Array(result)), remaining: pSrc };
29
- }
30
- exports.unpackString = unpackString;
31
- var MsgUnpacker = /** @class */ (function () {
32
- function MsgUnpacker(pSrc) {
33
- this.remaining = pSrc;
34
- }
35
- MsgUnpacker.prototype.unpackInt = function (_unpacked) {
36
- if (_unpacked === void 0) { _unpacked = false; }
37
- var unpacked;
38
- if (!_unpacked) {
39
- unpacked = unpackInt(this.remaining);
40
- this.remaining = unpacked.remaining;
41
- }
42
- else {
43
- unpacked = { result: this.remaining[0] };
44
- this.remaining = this.remaining.slice(1);
45
- }
46
- return unpacked.result;
47
- };
48
- MsgUnpacker.prototype.unpackString = function () {
49
- var unpacked = unpackString(this.remaining);
50
- this.remaining = unpacked.remaining;
51
- return unpacked.result;
52
- };
53
- return MsgUnpacker;
54
- }());
55
- exports.MsgUnpacker = MsgUnpacker;
56
- // export = {MsgUnpacker, unpackInt, unpackString}