teeworlds 2.4.3 → 2.4.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,200 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.SnapshotWrapper = void 0;
19
+ var stream_1 = require("stream");
20
+ var items;
21
+ (function (items) {
22
+ items[items["OBJ_EX"] = 0] = "OBJ_EX";
23
+ items[items["OBJ_PLAYER_INPUT"] = 1] = "OBJ_PLAYER_INPUT";
24
+ items[items["OBJ_PROJECTILE"] = 2] = "OBJ_PROJECTILE";
25
+ items[items["OBJ_LASER"] = 3] = "OBJ_LASER";
26
+ items[items["OBJ_PICKUP"] = 4] = "OBJ_PICKUP";
27
+ items[items["OBJ_FLAG"] = 5] = "OBJ_FLAG";
28
+ items[items["OBJ_GAME_INFO"] = 6] = "OBJ_GAME_INFO";
29
+ items[items["OBJ_GAME_DATA"] = 7] = "OBJ_GAME_DATA";
30
+ items[items["OBJ_CHARACTER_CORE"] = 8] = "OBJ_CHARACTER_CORE";
31
+ items[items["OBJ_CHARACTER"] = 9] = "OBJ_CHARACTER";
32
+ items[items["OBJ_PLAYER_INFO"] = 10] = "OBJ_PLAYER_INFO";
33
+ items[items["OBJ_CLIENT_INFO"] = 11] = "OBJ_CLIENT_INFO";
34
+ items[items["OBJ_SPECTATOR_INFO"] = 12] = "OBJ_SPECTATOR_INFO";
35
+ items[items["EVENT_COMMON"] = 13] = "EVENT_COMMON";
36
+ items[items["EVENT_EXPLOSION"] = 14] = "EVENT_EXPLOSION";
37
+ items[items["EVENT_SPAWN"] = 15] = "EVENT_SPAWN";
38
+ items[items["EVENT_HAMMERHIT"] = 16] = "EVENT_HAMMERHIT";
39
+ items[items["EVENT_DEATH"] = 17] = "EVENT_DEATH";
40
+ items[items["EVENT_SOUND_GLOBAL"] = 18] = "EVENT_SOUND_GLOBAL";
41
+ items[items["EVENT_SOUND_WORLD"] = 19] = "EVENT_SOUND_WORLD";
42
+ items[items["EVENT_DAMAGE_INDICATOR"] = 20] = "EVENT_DAMAGE_INDICATOR";
43
+ })(items || (items = {}));
44
+ var SnapshotWrapper = /** @class */ (function (_super) {
45
+ __extends(SnapshotWrapper, _super);
46
+ function SnapshotWrapper(_client) {
47
+ var _this =
48
+ // this.SendMsgEx = callback;
49
+ _super.call(this) || this;
50
+ _this._client = _client;
51
+ return _this;
52
+ }
53
+ SnapshotWrapper.prototype.getParsed = function (type_id, id) {
54
+ var _a;
55
+ return (_a = this._client.rawSnapUnpacker.deltas.find(function (delta) { return delta.type_id == type_id && delta.id == id; })) === null || _a === void 0 ? void 0 : _a.parsed;
56
+ };
57
+ SnapshotWrapper.prototype.getAll = function (type_id) {
58
+ var _all = [];
59
+ this._client.rawSnapUnpacker.deltas.forEach(function (delta) {
60
+ if (delta.type_id == type_id)
61
+ _all.push(delta.parsed);
62
+ });
63
+ return _all;
64
+ // return this._client.rawSnapUnpacker.deltas.filter(delta => delta.type_id == type_id && delta.id == id).map(a => a.parsed);
65
+ };
66
+ SnapshotWrapper.prototype.getObjPlayerInput = function (player_id) {
67
+ return this.getParsed(items.OBJ_PLAYER_INPUT, player_id);
68
+ };
69
+ Object.defineProperty(SnapshotWrapper.prototype, "AllObjPlayerInput", {
70
+ get: function () {
71
+ return this.getAll(items.OBJ_PLAYER_INPUT);
72
+ },
73
+ enumerable: false,
74
+ configurable: true
75
+ });
76
+ SnapshotWrapper.prototype.getObjProjectile = function (id) {
77
+ return this.getParsed(items.OBJ_PROJECTILE, id);
78
+ };
79
+ Object.defineProperty(SnapshotWrapper.prototype, "AllProjectiles", {
80
+ get: function () {
81
+ return this.getAll(items.OBJ_PROJECTILE);
82
+ },
83
+ enumerable: false,
84
+ configurable: true
85
+ });
86
+ SnapshotWrapper.prototype.getObjLaser = function (id) {
87
+ return this.getParsed(items.OBJ_LASER, id);
88
+ };
89
+ Object.defineProperty(SnapshotWrapper.prototype, "AllObjLaser", {
90
+ get: function () {
91
+ return this.getAll(items.OBJ_LASER);
92
+ },
93
+ enumerable: false,
94
+ configurable: true
95
+ });
96
+ SnapshotWrapper.prototype.getObjPickup = function (id) {
97
+ return this.getParsed(items.OBJ_PICKUP, id);
98
+ };
99
+ Object.defineProperty(SnapshotWrapper.prototype, "AllObjPickup", {
100
+ get: function () {
101
+ return this.getAll(items.OBJ_PICKUP);
102
+ },
103
+ enumerable: false,
104
+ configurable: true
105
+ });
106
+ SnapshotWrapper.prototype.getObjFlag = function (id) {
107
+ return this.getParsed(items.OBJ_FLAG, id);
108
+ };
109
+ Object.defineProperty(SnapshotWrapper.prototype, "AllObjFlag", {
110
+ get: function () {
111
+ return this.getAll(items.OBJ_FLAG);
112
+ },
113
+ enumerable: false,
114
+ configurable: true
115
+ });
116
+ SnapshotWrapper.prototype.getObjGameInfo = function (id) {
117
+ return this.getParsed(items.OBJ_GAME_INFO, id);
118
+ };
119
+ Object.defineProperty(SnapshotWrapper.prototype, "AllObjGameInfo", {
120
+ get: function () {
121
+ return this.getAll(items.OBJ_GAME_INFO);
122
+ },
123
+ enumerable: false,
124
+ configurable: true
125
+ });
126
+ SnapshotWrapper.prototype.getObjGameData = function (id) {
127
+ return this.getParsed(items.OBJ_GAME_DATA, id);
128
+ };
129
+ Object.defineProperty(SnapshotWrapper.prototype, "AllObjGameData", {
130
+ get: function () {
131
+ return this.getAll(items.OBJ_GAME_DATA);
132
+ },
133
+ enumerable: false,
134
+ configurable: true
135
+ });
136
+ /** NOTICE: x & y positions always differ from the positions in the ingame debug menu. If you want the debug menu positions, you can calculate them like this: Math.round((myChar.character_core.x / 32) * 100)/100 */
137
+ SnapshotWrapper.prototype.getObjCharacterCore = function (player_id) {
138
+ return this.getParsed(items.OBJ_CHARACTER_CORE, player_id);
139
+ };
140
+ Object.defineProperty(SnapshotWrapper.prototype, "AllObjCharacterCore", {
141
+ /** NOTICE: x & y positions always differ from the positions in the ingame debug menu. If you want the debug menu positions, you can calculate them like this: Math.round((myChar.character_core.x / 32) * 100)/100 */
142
+ get: function () {
143
+ return this.getAll(items.OBJ_CHARACTER_CORE);
144
+ },
145
+ enumerable: false,
146
+ configurable: true
147
+ });
148
+ /** NOTICE: x & y positions always differ from the positions in the ingame debug menu. If you want the debug menu positions, you can calculate them like this: Math.round((myChar.character_core.x / 32) * 100)/100 */
149
+ SnapshotWrapper.prototype.getObjCharacter = function (player_id) {
150
+ return this.getParsed(items.OBJ_CHARACTER, player_id);
151
+ };
152
+ Object.defineProperty(SnapshotWrapper.prototype, "AllObjCharacter", {
153
+ /** NOTICE: x & y positions always differ from the positions in the ingame debug menu. If you want the debug menu positions, you can calculate them like this: Math.round((myChar.character_core.x / 32) * 100)/100 */
154
+ get: function () {
155
+ return this.getAll(items.OBJ_CHARACTER);
156
+ },
157
+ enumerable: false,
158
+ configurable: true
159
+ });
160
+ SnapshotWrapper.prototype.getObjPlayerInfo = function (player_id) {
161
+ return this.getParsed(items.OBJ_PLAYER_INFO, player_id);
162
+ };
163
+ Object.defineProperty(SnapshotWrapper.prototype, "AllObjPlayerInfo", {
164
+ get: function () {
165
+ return this.getAll(items.OBJ_PLAYER_INFO);
166
+ },
167
+ enumerable: false,
168
+ configurable: true
169
+ });
170
+ SnapshotWrapper.prototype.getObjClientInfo = function (player_id) {
171
+ return this.getParsed(items.OBJ_CLIENT_INFO, player_id);
172
+ };
173
+ Object.defineProperty(SnapshotWrapper.prototype, "AllObjClientInfo", {
174
+ get: function () {
175
+ return this.getAll(items.OBJ_CLIENT_INFO);
176
+ },
177
+ enumerable: false,
178
+ configurable: true
179
+ });
180
+ SnapshotWrapper.prototype.getObjSpectatorInfo = function (player_id) {
181
+ return this.getParsed(items.OBJ_SPECTATOR_INFO, player_id);
182
+ };
183
+ Object.defineProperty(SnapshotWrapper.prototype, "AllObjSpectatorInfo", {
184
+ get: function () {
185
+ return this.getAll(items.OBJ_SPECTATOR_INFO);
186
+ },
187
+ enumerable: false,
188
+ configurable: true
189
+ });
190
+ Object.defineProperty(SnapshotWrapper.prototype, "OwnID", {
191
+ get: function () {
192
+ var _a;
193
+ return (_a = this.AllObjPlayerInfo.find(function (parsed) { return parsed.local; })) === null || _a === void 0 ? void 0 : _a.client_id;
194
+ },
195
+ enumerable: false,
196
+ configurable: true
197
+ });
198
+ return SnapshotWrapper;
199
+ }(stream_1.EventEmitter));
200
+ exports.SnapshotWrapper = SnapshotWrapper;
@@ -0,0 +1,174 @@
1
+
2
+ import { Client } from "../client";
3
+ import { EventEmitter } from "stream";
4
+ import { PlayerInput, PlayerInfo, Projectile, Laser, Pickup, Flag, GameInfo, GameData, CharacterCore, Character, ClientInfo, SpectatorInfo, Common, Explosion, Spawn, HammerHit, Death, SoundGlobal, SoundWorld, DamageInd } from "../snapshots";
5
+
6
+ enum items {
7
+ OBJ_EX,
8
+ OBJ_PLAYER_INPUT,
9
+ OBJ_PROJECTILE,
10
+ OBJ_LASER,
11
+ OBJ_PICKUP,
12
+ OBJ_FLAG,
13
+ OBJ_GAME_INFO,
14
+ OBJ_GAME_DATA,
15
+ OBJ_CHARACTER_CORE,
16
+ OBJ_CHARACTER,
17
+ OBJ_PLAYER_INFO,
18
+ OBJ_CLIENT_INFO,
19
+ OBJ_SPECTATOR_INFO,
20
+ EVENT_COMMON,
21
+ EVENT_EXPLOSION,
22
+ EVENT_SPAWN,
23
+ EVENT_HAMMERHIT,
24
+ EVENT_DEATH,
25
+ EVENT_SOUND_GLOBAL,
26
+ EVENT_SOUND_WORLD,
27
+ EVENT_DAMAGE_INDICATOR
28
+ }
29
+ export declare interface SnapshotWrapper {
30
+
31
+
32
+ // on(event: 'connected', listener: () => void): this;
33
+ // on(event: 'disconnect', listener: (reason: string) => void): this;
34
+
35
+ // on(event: 'emote', listener: (message: iEmoticon) => void): this;
36
+ // on(event: 'message', listener: (message: iMessage) => void): this;
37
+ // on(event: 'broadcast', listener: (message: string) => void): this;
38
+ // on(event: 'kill', listener: (kill: iKillMsg) => void): this;
39
+ // on(event: 'motd', listener: (message: string) => void): this;
40
+
41
+ on(event: 'common', listener: (common: Common) => void): this;
42
+ on(event: 'explosion', listener: (explosion: Explosion) => void): this;
43
+ on(event: 'spawn', listener: (spawn: Spawn) => void): this;
44
+ on(event: 'hammerhit', listener: (hammerhit: HammerHit) => void): this;
45
+ on(event: 'death', listener: (death: Death) => void): this;
46
+ on(event: 'sound_global', listener: (sound_global: SoundGlobal) => void): this;
47
+ on(event: 'sound_world', listener: (sound_world: SoundWorld) => void): this;
48
+ on(event: 'damage_indicator', listener: (damage_indicator: DamageInd) => void): this;
49
+
50
+ }
51
+
52
+ export class SnapshotWrapper extends EventEmitter {
53
+ private _client: Client;
54
+ constructor(_client: Client) {
55
+ // this.SendMsgEx = callback;
56
+ super();
57
+ this._client = _client;
58
+ }
59
+
60
+ private getParsed<T>(type_id: number, id: number) {
61
+ return this._client.rawSnapUnpacker.deltas.find(delta => delta.type_id == type_id && delta.id == id)?.parsed as unknown as T;
62
+ }
63
+
64
+ private getAll<T>(type_id: number): T[] {
65
+ let _all: T[] = [];
66
+
67
+ this._client.rawSnapUnpacker.deltas.forEach(delta => {
68
+ if (delta.type_id == type_id)
69
+ _all.push(delta.parsed as T);
70
+ })
71
+
72
+
73
+ return _all;
74
+ // return this._client.rawSnapUnpacker.deltas.filter(delta => delta.type_id == type_id && delta.id == id).map(a => a.parsed);
75
+ }
76
+
77
+ getObjPlayerInput(player_id: number): PlayerInput | undefined {
78
+ return this.getParsed(items.OBJ_PLAYER_INPUT, player_id);
79
+ }
80
+
81
+ get AllObjPlayerInput(): PlayerInput[] {
82
+ return this.getAll(items.OBJ_PLAYER_INPUT);
83
+ }
84
+
85
+ getObjProjectile(id: number): Projectile | undefined {
86
+ return this.getParsed(items.OBJ_PROJECTILE, id);
87
+ }
88
+ get AllProjectiles(): Projectile[] {
89
+ return this.getAll(items.OBJ_PROJECTILE);
90
+ }
91
+
92
+ getObjLaser(id: number): Laser | undefined {
93
+ return this.getParsed(items.OBJ_LASER, id);
94
+ }
95
+ get AllObjLaser(): Laser[] {
96
+ return this.getAll(items.OBJ_LASER);
97
+ }
98
+
99
+ getObjPickup(id: number): Pickup | undefined {
100
+ return this.getParsed(items.OBJ_PICKUP, id);
101
+ }
102
+ get AllObjPickup(): Pickup[] {
103
+ return this.getAll(items.OBJ_PICKUP);
104
+ }
105
+
106
+ getObjFlag(id: number): Flag | undefined {
107
+ return this.getParsed(items.OBJ_FLAG, id);
108
+ }
109
+ get AllObjFlag(): Flag[] {
110
+ return this.getAll(items.OBJ_FLAG);
111
+ }
112
+
113
+ getObjGameInfo(id: number): GameInfo | undefined {
114
+ return this.getParsed(items.OBJ_GAME_INFO, id);
115
+ }
116
+ get AllObjGameInfo(): GameInfo[] {
117
+ return this.getAll(items.OBJ_GAME_INFO);
118
+ }
119
+
120
+ getObjGameData(id: number): GameData | undefined {
121
+ return this.getParsed(items.OBJ_GAME_DATA, id);
122
+ }
123
+ get AllObjGameData(): GameData[] {
124
+ return this.getAll(items.OBJ_GAME_DATA);
125
+ }
126
+
127
+ /** NOTICE: x & y positions always differ from the positions in the ingame debug menu. If you want the debug menu positions, you can calculate them like this: Math.round((myChar.character_core.x / 32) * 100)/100 */
128
+ getObjCharacterCore(player_id: number): CharacterCore | undefined {
129
+ return this.getParsed(items.OBJ_CHARACTER_CORE, player_id);
130
+ }
131
+ /** NOTICE: x & y positions always differ from the positions in the ingame debug menu. If you want the debug menu positions, you can calculate them like this: Math.round((myChar.character_core.x / 32) * 100)/100 */
132
+ get AllObjCharacterCore(): CharacterCore[] {
133
+ return this.getAll(items.OBJ_CHARACTER_CORE);
134
+ }
135
+
136
+ /** NOTICE: x & y positions always differ from the positions in the ingame debug menu. If you want the debug menu positions, you can calculate them like this: Math.round((myChar.character_core.x / 32) * 100)/100 */
137
+ getObjCharacter(player_id: number): Character | undefined {
138
+ return this.getParsed(items.OBJ_CHARACTER, player_id);
139
+ }
140
+ /** NOTICE: x & y positions always differ from the positions in the ingame debug menu. If you want the debug menu positions, you can calculate them like this: Math.round((myChar.character_core.x / 32) * 100)/100 */
141
+ get AllObjCharacter(): Character[] {
142
+
143
+ return this.getAll(items.OBJ_CHARACTER);
144
+ }
145
+
146
+ getObjPlayerInfo(player_id: number): PlayerInfo | undefined {
147
+ return this.getParsed(items.OBJ_PLAYER_INFO, player_id);
148
+ }
149
+ get AllObjPlayerInfo(): PlayerInfo[] {
150
+ return this.getAll(items.OBJ_PLAYER_INFO);
151
+ }
152
+
153
+ getObjClientInfo(player_id: number): ClientInfo | undefined {
154
+ return this.getParsed(items.OBJ_CLIENT_INFO, player_id);
155
+ }
156
+ get AllObjClientInfo(): ClientInfo[] {
157
+ return this.getAll(items.OBJ_CLIENT_INFO);
158
+ }
159
+
160
+ getObjSpectatorInfo(player_id: number): SpectatorInfo | undefined {
161
+ return this.getParsed(items.OBJ_SPECTATOR_INFO, player_id);
162
+ }
163
+ get AllObjSpectatorInfo(): SpectatorInfo[] {
164
+ return this.getAll(items.OBJ_SPECTATOR_INFO);
165
+ }
166
+
167
+
168
+ get OwnID(): number | undefined {
169
+ return this.AllObjPlayerInfo.find(parsed => parsed.local)?.client_id;
170
+ }
171
+
172
+
173
+
174
+ }