pw-js-world 0.0.1
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/LICENSE +21 -0
- package/README.md +67 -0
- package/bun.lockb +0 -0
- package/dist/Block.d.ts +117 -0
- package/dist/Block.js +156 -0
- package/dist/BufferReader.d.ts +324 -0
- package/dist/BufferReader.js +674 -0
- package/dist/Constants.d.ts +4 -0
- package/dist/Constants.js +6 -0
- package/dist/Helper.d.ts +200 -0
- package/dist/Helper.js +482 -0
- package/dist/Player.d.ts +222 -0
- package/dist/Player.js +110 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5 -0
- package/dist/types/index.d.ts +19 -0
- package/esm.mjs +19 -0
- package/lib/Block.ts +217 -0
- package/lib/BufferReader.ts +770 -0
- package/lib/Constants.ts +4 -0
- package/lib/Helper.ts +603 -0
- package/lib/Player.ts +317 -0
- package/lib/index.ts +8 -0
- package/lib/types/index.d.ts +19 -0
- package/package.json +40 -0
- package/test/index.ts +96 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export var LayerType;
|
|
2
|
+
(function (LayerType) {
|
|
3
|
+
LayerType[LayerType["Background"] = 0] = "Background";
|
|
4
|
+
LayerType[LayerType["Foreground"] = 1] = "Foreground";
|
|
5
|
+
})(LayerType || (LayerType = {}));
|
|
6
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ29uc3RhbnRzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vbGliL0NvbnN0YW50cy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxNQUFNLENBQU4sSUFBWSxTQUdYO0FBSEQsV0FBWSxTQUFTO0lBQ2pCLHFEQUFVLENBQUE7SUFDVixxREFBVSxDQUFBO0FBQ2QsQ0FBQyxFQUhXLFNBQVMsS0FBVCxTQUFTLFFBR3BCIn0=
|
package/dist/Helper.d.ts
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { BlockNames, Hook } from "pw-js-api";
|
|
2
|
+
import type { WorldMeta } from "../node_modules/pw-js-api/dist/gen/world_pb";
|
|
3
|
+
import Block from "./Block";
|
|
4
|
+
import Player, { IPlayerEffect, IPlayerRights } from "./Player";
|
|
5
|
+
import { LayerType } from "./Constants";
|
|
6
|
+
import type { BlockArg, Point, SendableBlockPacket } from "./types";
|
|
7
|
+
/**
|
|
8
|
+
* To use this helper, you must first create an instance of this,
|
|
9
|
+
*
|
|
10
|
+
* then: <PWGameClient>.addCallback("raw", helper.onRawPacketRecv)
|
|
11
|
+
*/
|
|
12
|
+
export default class PWGameWorldHelper {
|
|
13
|
+
/**
|
|
14
|
+
* Arrays of blocks (by layer, x, y)
|
|
15
|
+
*/
|
|
16
|
+
blocks: [Block[][], Block[][]];
|
|
17
|
+
players: Map<number, Player>;
|
|
18
|
+
globalSwitches: boolean[];
|
|
19
|
+
private _meta?;
|
|
20
|
+
private _width;
|
|
21
|
+
private _height;
|
|
22
|
+
private _init;
|
|
23
|
+
private _selfPlayerId;
|
|
24
|
+
/**
|
|
25
|
+
* The current world's width.
|
|
26
|
+
*
|
|
27
|
+
* If you didn't put the hook before init, this may throw error.
|
|
28
|
+
*/
|
|
29
|
+
get width(): number;
|
|
30
|
+
/**
|
|
31
|
+
* The current world's height.
|
|
32
|
+
*
|
|
33
|
+
* If you didn't put the hook before init, this may throw error.
|
|
34
|
+
*/
|
|
35
|
+
get height(): number;
|
|
36
|
+
/**
|
|
37
|
+
* The current world's metadata.
|
|
38
|
+
*
|
|
39
|
+
* If you didn't put the hook before init, this may throw error.
|
|
40
|
+
*/
|
|
41
|
+
get meta(): WorldMeta | null;
|
|
42
|
+
/**
|
|
43
|
+
* If this helper is ready. When it's false, the helper will not return anything for any of the packets.
|
|
44
|
+
*/
|
|
45
|
+
get initialised(): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* The bot's player object.
|
|
48
|
+
*
|
|
49
|
+
* If you didn't put the hook before init, this may throw error.
|
|
50
|
+
*/
|
|
51
|
+
get botPlayer(): Player;
|
|
52
|
+
/**
|
|
53
|
+
* The bot's player id in the world.
|
|
54
|
+
*
|
|
55
|
+
* If you didn't put the hook before init, this may throw error.
|
|
56
|
+
*/
|
|
57
|
+
get botPlayerId(): number;
|
|
58
|
+
/**
|
|
59
|
+
* This must go in .use() of the main PW-JS-API Game Client class.
|
|
60
|
+
*
|
|
61
|
+
* <PWGameClient>.use(<PWGameWorldHelper>.receiveHook)
|
|
62
|
+
*
|
|
63
|
+
* DO NOT PUT () AFTER RECEIVEHOOK
|
|
64
|
+
*/
|
|
65
|
+
receiveHook: Hook<{
|
|
66
|
+
worldBlockPlacedPacket: {
|
|
67
|
+
player: Player;
|
|
68
|
+
oldBlocks: Block[];
|
|
69
|
+
newBlocks: Block[];
|
|
70
|
+
};
|
|
71
|
+
playerJoinedPacket: {
|
|
72
|
+
player: Player;
|
|
73
|
+
};
|
|
74
|
+
playerLeftPacket: {
|
|
75
|
+
player: Player;
|
|
76
|
+
};
|
|
77
|
+
playerInitPacket: {
|
|
78
|
+
player: Player;
|
|
79
|
+
};
|
|
80
|
+
playerFacePacket: {
|
|
81
|
+
player: Player;
|
|
82
|
+
oldFace: number;
|
|
83
|
+
};
|
|
84
|
+
playerModModePacket: {
|
|
85
|
+
player: Player;
|
|
86
|
+
oldState: boolean;
|
|
87
|
+
};
|
|
88
|
+
playerGodModePacket: {
|
|
89
|
+
player: Player;
|
|
90
|
+
oldState: boolean;
|
|
91
|
+
};
|
|
92
|
+
playerAddEffectPacket: {
|
|
93
|
+
player: Player;
|
|
94
|
+
effect: IPlayerEffect;
|
|
95
|
+
};
|
|
96
|
+
playerRemoveEffectPacket: {
|
|
97
|
+
player: Player;
|
|
98
|
+
effect: IPlayerEffect;
|
|
99
|
+
};
|
|
100
|
+
playerResetEffectsPacket: {
|
|
101
|
+
player: Player;
|
|
102
|
+
effects: IPlayerEffect[];
|
|
103
|
+
};
|
|
104
|
+
playerMovedPacket: {
|
|
105
|
+
player: Player;
|
|
106
|
+
};
|
|
107
|
+
playerResetPacket: {
|
|
108
|
+
player: Player;
|
|
109
|
+
};
|
|
110
|
+
playerRespawnPacket: {
|
|
111
|
+
player: Player;
|
|
112
|
+
};
|
|
113
|
+
playerUpdateRightsPacket: {
|
|
114
|
+
player: Player;
|
|
115
|
+
rights: IPlayerRights;
|
|
116
|
+
};
|
|
117
|
+
playerTeamUpdatePacket: {
|
|
118
|
+
player: Player;
|
|
119
|
+
oldTeam: number;
|
|
120
|
+
};
|
|
121
|
+
playerCountersUpdatePacket: {
|
|
122
|
+
player: Player;
|
|
123
|
+
oldState: {
|
|
124
|
+
coinsBlue: number;
|
|
125
|
+
coinsGold: number;
|
|
126
|
+
deaths: number;
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
playerTeleportedPacket: {
|
|
130
|
+
player: Player;
|
|
131
|
+
};
|
|
132
|
+
globalSwitchChangedPacket: {
|
|
133
|
+
player: Player;
|
|
134
|
+
};
|
|
135
|
+
globalSwitchResetPacket: {
|
|
136
|
+
player: Player;
|
|
137
|
+
};
|
|
138
|
+
playerLocalSwitchChangedPacket: {
|
|
139
|
+
player: Player;
|
|
140
|
+
};
|
|
141
|
+
playerLocalSwitchResetPacket: {
|
|
142
|
+
player: Player;
|
|
143
|
+
};
|
|
144
|
+
playerChatPacket: {
|
|
145
|
+
player: Player;
|
|
146
|
+
};
|
|
147
|
+
playerDirectMessagePacket: {
|
|
148
|
+
player: Player;
|
|
149
|
+
};
|
|
150
|
+
playerTouchBlockPacket: {
|
|
151
|
+
player: Player;
|
|
152
|
+
};
|
|
153
|
+
}>;
|
|
154
|
+
/**
|
|
155
|
+
* Internal function.
|
|
156
|
+
*/
|
|
157
|
+
private initialise;
|
|
158
|
+
/**
|
|
159
|
+
* Internal function.
|
|
160
|
+
*/
|
|
161
|
+
private deserialize;
|
|
162
|
+
private convertSwitchState;
|
|
163
|
+
/**
|
|
164
|
+
* Internal function, this triggers when the world gets cleared.
|
|
165
|
+
*
|
|
166
|
+
* Clears the blocks map and promptly fill it with empty except the border which becomes basci gray.
|
|
167
|
+
*/
|
|
168
|
+
private clear;
|
|
169
|
+
/**
|
|
170
|
+
* Gets the block at the position.
|
|
171
|
+
*/
|
|
172
|
+
getBlockAt(x: number, y: number, l: number): Block;
|
|
173
|
+
/**
|
|
174
|
+
* Player ID.
|
|
175
|
+
*
|
|
176
|
+
* The main bot player is excluded from the criteria.
|
|
177
|
+
*/
|
|
178
|
+
getPlayer(id: number, isAccount?: false): Player | undefined;
|
|
179
|
+
/**
|
|
180
|
+
* Username is case insensitive.
|
|
181
|
+
*
|
|
182
|
+
* The main bot player is excluded from the criteria.
|
|
183
|
+
*/
|
|
184
|
+
getPlayer(username: string, isAccount?: false): Player | undefined;
|
|
185
|
+
/**
|
|
186
|
+
* The ID of the account (must have second parameter set to true)
|
|
187
|
+
*
|
|
188
|
+
* The main bot player is excluded from the criteria.
|
|
189
|
+
*/
|
|
190
|
+
getPlayer(accountId: string, isAccount: true): Player | undefined;
|
|
191
|
+
/**
|
|
192
|
+
* Returns the list of current players in the world.
|
|
193
|
+
*/
|
|
194
|
+
getPlayers(): Player[];
|
|
195
|
+
/**
|
|
196
|
+
* For now this is slightly limited, but this will ONLY create a sendable packet which you must then send it yourself.
|
|
197
|
+
*/
|
|
198
|
+
createBlockPacket(blockId: number | BlockNames | keyof typeof BlockNames, layer: LayerType, pos: Point | Point[], ...args: BlockArg[]): SendableBlockPacket;
|
|
199
|
+
createBlockPacket(block: Block, layer: LayerType, pos: Point | Point[]): SendableBlockPacket;
|
|
200
|
+
}
|