pw-js-world 0.4.3-dev.d102cb4 → 0.4.4-dev.22e78f4

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/cm/Block.d.ts DELETED
@@ -1,119 +0,0 @@
1
- import type { BlockArg, Point, SendableBlockPacket } from "./types/index.js";
2
- import BufferReader, { ComponentTypeHeader } from "./BufferReader.js";
3
- import { LayerType } from "./Constants.js";
4
- import { type BlockKeys } from "pw-js-api";
5
- export default class Block {
6
- bId: number;
7
- args: BlockArg[];
8
- constructor(bId: number | BlockKeys | string, args?: BlockArg[]);
9
- /**
10
- * I mean... Just use .args.length !== 0 to see if it has args.
11
- *
12
- * But anyway, this will return true if there is at least one args, otherwise false.
13
- */
14
- hasArgs(): boolean;
15
- /**
16
- * For helper.
17
- *
18
- * This is in Block class for organisation.
19
- *
20
- * This will deserialise by using the reader to get the block ID then retrieve the args, if applicable.
21
- */
22
- static deserialize(reader: BufferReader): Block;
23
- protected deserializeArgs(reader: BufferReader, flag?: boolean): this;
24
- /**
25
- * For helper.
26
- *
27
- * This is in Block class for organisation.
28
- */
29
- static deserializeArgs(reader: BufferReader): BlockArg[];
30
- /**
31
- * Serializes the block into a buffer. This is used to convert
32
- * the block into a binary format that can be sent over the game
33
- * server. As this is static, block id and args are required.
34
- *
35
- * - Little Endian
36
- * - With Id
37
- * - Type Byte omitted
38
- */
39
- static serializeArgs(bId: number, args: BlockArg[]): Buffer;
40
- /**
41
- * Serializes the block into a buffer. This is used to convert
42
- * the block into a binary format that can be sent over the game
43
- * server. As this is static, block id and args are required.
44
- *
45
- * - Big Endian
46
- * - No Id
47
- * - Type Byte included
48
- */
49
- static serializeArgs(bId: number, args: BlockArg[], options: {
50
- endian: "big";
51
- writeId: false;
52
- readTypeByte: true;
53
- }): Buffer;
54
- static serializeArgs(bId: number, args: BlockArg[], options: {
55
- endian: "little";
56
- writeId: false;
57
- readTypeByte: true;
58
- }): Buffer;
59
- /**
60
- *
61
- * @param pos List of points (X and Y)
62
- */
63
- toPacket(pos: Point[], layer: LayerType): SendableBlockPacket;
64
- toPacket(x: number, y: number, layer: LayerType): SendableBlockPacket;
65
- /**
66
- * This will return the block name in UPPER_CASE form.
67
- *
68
- * For eg EFFECTS_INVULNERABILITY.
69
- *
70
- * @throws {MissingBlockError}
71
- * If the ID of this block is not known.
72
- */
73
- get name(): string;
74
- /**
75
- * Returns a copy of the block.
76
- */
77
- clone(obj?: false): Block;
78
- clone(obj: true): {
79
- bId: number;
80
- args: BlockArg[];
81
- name: string;
82
- };
83
- /**
84
- * This can be convenient as it will always return the ID if it exists, and it will throw an error if it doesn't.
85
- *
86
- * This expects the name sent to be in full upper capital form though.
87
- *
88
- * @throws {MissingBlockError}
89
- * If the connection is unknown, this can be because you're trying to use this function when Api#getListBlocks has never been invoked, or the object is missing.
90
- */
91
- static getIdByName(paletteId: string): number;
92
- /**
93
- * This will return the corresponding palette id by the ID of that block.
94
- *
95
- * The name sent will be in full upper capital if it exists.
96
- *
97
- * @throws {MissingBlockError}
98
- * If the connection is unknown, this can be because you're trying to use this function when Api#getListBlocks has never been invoked, or the object is missing.
99
- */
100
- static getPaletteIdById(blockId: number): string;
101
- /**
102
- * Returns the arg types for that block by given block ID.
103
- *
104
- * If a block don't have args, it will return an empty array.
105
- *
106
- * If the block don't exist, it may throw an exception.
107
- */
108
- static getArgTypesByBlockId(blockId: number): ComponentTypeHeader[];
109
- /**
110
- * Returns the arg types for that block by given palette ID (full upper case).
111
- *
112
- * For eg "EMPTY" or "SIGN_GOLD"
113
- *
114
- * If a block don't have args, it will return an empty array.
115
- *
116
- * If the block don't exist, it may throw an exception.
117
- */
118
- static getArgTypesByPaletteId(paletteId: string): ComponentTypeHeader[];
119
- }
package/cm/Block.js DELETED
@@ -1,183 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const BufferReader_js_1 = tslib_1.__importDefault(require("./BufferReader.js"));
5
- const pw_js_api_1 = require("pw-js-api");
6
- const Error_js_1 = require("./util/Error.js");
7
- class Block {
8
- constructor(bId, args) {
9
- this.args = [];
10
- if (typeof bId === "number")
11
- this.bId = bId;
12
- else {
13
- this.bId = Block.getIdByName(bId);
14
- }
15
- if (args)
16
- this.args = args;
17
- }
18
- /**
19
- * I mean... Just use .args.length !== 0 to see if it has args.
20
- *
21
- * But anyway, this will return true if there is at least one args, otherwise false.
22
- */
23
- hasArgs() {
24
- return this.args.length !== 0;
25
- }
26
- /**
27
- * For helper.
28
- *
29
- * This is in Block class for organisation.
30
- *
31
- * This will deserialise by using the reader to get the block ID then retrieve the args, if applicable.
32
- */
33
- static deserialize(reader) {
34
- return new Block(reader.readUInt32LE()).deserializeArgs(reader);
35
- }
36
- deserializeArgs(reader, flag = false) {
37
- var _a;
38
- const format = Block.getArgTypesByBlockId(this.bId); //(BlockArgsHeadings as any)[this.name];
39
- for (let i = 0; i < ((_a = format === null || format === void 0 ? void 0 : format.length) !== null && _a !== void 0 ? _a : 0); i++) {
40
- if (flag) {
41
- reader.expectUInt8(format[i]);
42
- }
43
- this.args[i] = reader.read(format[i], !flag);
44
- }
45
- return this;
46
- }
47
- /**
48
- * For helper.
49
- *
50
- * This is in Block class for organisation.
51
- */
52
- static deserializeArgs(reader) {
53
- // const args =
54
- return reader.deserialize();
55
- // for (let i = 0; i < (format?.length ?? 0); i++) {
56
- // if (flag) {
57
- // reader.expectUInt8(format[i]);
58
- // }
59
- // args[i] = reader.read(format[i], !flag);
60
- // }
61
- // return args;
62
- }
63
- static serializeArgs(bId, args, options) {
64
- options || (options = {
65
- endian: "little",
66
- writeId: true,
67
- readTypeByte: false,
68
- });
69
- const buffer = [];
70
- if (options.writeId) {
71
- const idBuffer = Buffer.alloc(4);
72
- idBuffer.writeUInt32LE(bId);
73
- buffer.push(idBuffer);
74
- }
75
- const blockData = Block.getArgTypesByBlockId(bId);
76
- for (let i = 0, len = blockData.length; i < len; i++) {
77
- const entry = BufferReader_js_1.default.Dynamic(blockData[i], args[i]);
78
- buffer.push(entry);
79
- }
80
- return Buffer.concat(buffer);
81
- }
82
- toPacket(pos, y, layer) {
83
- if (typeof pos === "number") {
84
- pos = [{
85
- x: pos, y
86
- }];
87
- layer = layer !== null && layer !== void 0 ? layer : 0;
88
- }
89
- else
90
- layer = y !== null && y !== void 0 ? y : 0;
91
- return {
92
- isFillOperation: false,
93
- blockId: this.bId,
94
- layer,
95
- positions: pos,
96
- extraFields: Block.serializeArgs(this.bId, this.args, { endian: "big", writeId: false, readTypeByte: true })
97
- };
98
- }
99
- /**
100
- * This will return the block name in UPPER_CASE form.
101
- *
102
- * For eg EFFECTS_INVULNERABILITY.
103
- *
104
- * @throws {MissingBlockError}
105
- * If the ID of this block is not known.
106
- */
107
- get name() {
108
- var _a;
109
- const block = (_a = pw_js_api_1.PWApiClient.listBlocks) === null || _a === void 0 ? void 0 : _a[this.bId];
110
- if (block === undefined)
111
- throw new Error_js_1.MissingBlockError("Current block data is missing, run Api#listBlocks first?", this.bId);
112
- return block.PaletteId.toUpperCase();
113
- }
114
- clone(obj = false) {
115
- if (obj === true)
116
- return { bId: this.bId, args: this.args, name: this.name };
117
- return new Block(this.bId, this.args);
118
- }
119
- /**
120
- * This can be convenient as it will always return the ID if it exists, and it will throw an error if it doesn't.
121
- *
122
- * This expects the name sent to be in full upper capital form though.
123
- *
124
- * @throws {MissingBlockError}
125
- * If the connection is unknown, this can be because you're trying to use this function when Api#getListBlocks has never been invoked, or the object is missing.
126
- */
127
- static getIdByName(paletteId) {
128
- var _a;
129
- const block = (_a = pw_js_api_1.PWApiClient.listBlocksObj) === null || _a === void 0 ? void 0 : _a[paletteId];
130
- if (block === undefined)
131
- throw new Error_js_1.MissingBlockError("Current block data is missing, run Api#listBlocks first?", paletteId);
132
- return block.Id;
133
- }
134
- /**
135
- * This will return the corresponding palette id by the ID of that block.
136
- *
137
- * The name sent will be in full upper capital if it exists.
138
- *
139
- * @throws {MissingBlockError}
140
- * If the connection is unknown, this can be because you're trying to use this function when Api#getListBlocks has never been invoked, or the object is missing.
141
- */
142
- static getPaletteIdById(blockId) {
143
- var _a;
144
- const block = (_a = pw_js_api_1.PWApiClient.listBlocks) === null || _a === void 0 ? void 0 : _a[blockId];
145
- if (block === undefined)
146
- throw new Error_js_1.MissingBlockError("Current block data is missing, run Api#listBlocks first?", blockId);
147
- return block.PaletteId.toUpperCase();
148
- }
149
- /**
150
- * Returns the arg types for that block by given block ID.
151
- *
152
- * If a block don't have args, it will return an empty array.
153
- *
154
- * If the block don't exist, it may throw an exception.
155
- */
156
- static getArgTypesByBlockId(blockId) {
157
- var _a, _b;
158
- return (_b = (_a = pw_js_api_1.PWApiClient.listBlocks) === null || _a === void 0 ? void 0 : _a[blockId].BlockDataArgs) !== null && _b !== void 0 ? _b : [];
159
- // const block = PWApiClient.listBlocks?.[blockId];
160
- // return block ? MissingBlockData[block?.PaletteId.toUpperCase()] ?? (block.BlockDataArgs) as ComponentTypeHeader[] ?? [] : [];
161
- }
162
- /**
163
- * Returns the arg types for that block by given palette ID (full upper case).
164
- *
165
- * For eg "EMPTY" or "SIGN_GOLD"
166
- *
167
- * If a block don't have args, it will return an empty array.
168
- *
169
- * If the block don't exist, it may throw an exception.
170
- */
171
- static getArgTypesByPaletteId(paletteId) {
172
- var _a, _b;
173
- return (_b = (_a = pw_js_api_1.PWApiClient.listBlocksObj) === null || _a === void 0 ? void 0 : _a[paletteId].BlockDataArgs) !== null && _b !== void 0 ? _b : [];
174
- //MissingBlockData[paletteId] ?? (PWApiClient.listBlocksObj?.[paletteId].BlockDataArgs) as ComponentTypeHeader[] ?? []
175
- }
176
- }
177
- exports.default = Block;
178
- // Temporary fix as some blocks currently have incorrect args
179
- // const MissingBlockData = {
180
- // SWITCH_LOCAL_ACTIVATOR: [ComponentTypeHeader.Int32, ComponentTypeHeader.Byte],
181
- // SWITCH_GLOBAL_ACTIVATOR: [ComponentTypeHeader.Int32, ComponentTypeHeader.Byte],
182
- // } as Record<string, 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QXNIO0lBQzFILENBQUM7Q0FDSjtBQW5PRCx3QkFtT0M7QUFFRCw2REFBNkQ7QUFDN0QsNkJBQTZCO0FBQzdCLHFGQUFxRjtBQUNyRixzRkFBc0Y7QUFDdEYsOENBQThDIn0=
package/cm/Helper.d.ts DELETED
@@ -1,119 +0,0 @@
1
- import { type Hook } from "pw-js-api";
2
- import type { ProtoGen } from "pw-js-api";
3
- import Block from "./Block.js";
4
- import Player from "./Player.js";
5
- import { LayerType } from "./Constants.js";
6
- import type { Point, PWGameHook } from "./types/index.js";
7
- import { DeserialisedStructure } from "./Structure.js";
8
- /**
9
- * To use this helper, you must first create an instance of this,
10
- *
11
- * then: <PWGameClient>.addCallback("raw", helper.onRawPacketRecv)
12
- */
13
- export default class PWGameWorldHelper {
14
- /**
15
- * Arrays of blocks (by layer, x, y)
16
- */
17
- blocks: [Block[][], Block[][], Block[][]];
18
- players: Map<number, Player>;
19
- globalSwitches: boolean[];
20
- private _meta?;
21
- private _width;
22
- private _height;
23
- private _init;
24
- private _selfPlayerId;
25
- /**
26
- * The current world's width.
27
- *
28
- * If you didn't put the hook before init, this may throw error.
29
- */
30
- get width(): number;
31
- /**
32
- * The current world's height.
33
- *
34
- * If you didn't put the hook before init, this may throw error.
35
- */
36
- get height(): number;
37
- /**
38
- * The current world's metadata.
39
- *
40
- * If you didn't put the hook before init, this may throw error.
41
- */
42
- get meta(): ProtoGen.WorldMeta | null;
43
- /**
44
- * If this helper is ready. When it's false, the helper will not return anything for any of the packets.
45
- */
46
- get initialised(): boolean;
47
- /**
48
- * The bot's player object.
49
- *
50
- * If you didn't put the hook before init, this may throw error.
51
- */
52
- get botPlayer(): Player;
53
- /**
54
- * The bot's player id in the world.
55
- *
56
- * If you didn't put the hook before init, this may throw error.
57
- */
58
- get botPlayerId(): number;
59
- /**
60
- * This must go in .use() of the main PW-JS-API Game Client class.
61
- *
62
- * <PWGameClient>.use(<PWGameWorldHelper>.receiveHook)
63
- *
64
- * DO NOT PUT () AFTER RECEIVEHOOK
65
- */
66
- receiveHook: Hook<PWGameHook>;
67
- /**
68
- * Internal function.
69
- */
70
- private initialise;
71
- /**
72
- * Internal function.
73
- */
74
- private deserialize;
75
- private convertSwitchState;
76
- /**
77
- * Internal function, this triggers when the world gets cleared.
78
- *
79
- * Clears the blocks map and promptly fill it with empty except the border which becomes basci gray.
80
- */
81
- private clear;
82
- /**
83
- * Gets the block at the position.
84
- *
85
- * Difference between this and using this.blocks directly is that this function will validate the positions and the layer.
86
- */
87
- getBlockAt(pos: Point, l: LayerType): Block;
88
- getBlockAt(x: number | Point, y: number, l: LayerType): Block;
89
- /**
90
- * Player ID.
91
- *
92
- * The main bot player is excluded from the criteria.
93
- */
94
- getPlayer(id: number, isAccount?: false): Player | undefined;
95
- /**
96
- * Username is case insensitive.
97
- *
98
- * The main bot player is excluded from the criteria.
99
- */
100
- getPlayer(username: string, isAccount?: false): Player | undefined;
101
- /**
102
- * The ID of the account (must have second parameter set to true)
103
- *
104
- * The main bot player is excluded from the criteria.
105
- */
106
- getPlayer(accountId: string, isAccount: true): Player | undefined;
107
- /**
108
- * Returns the list of current players in the world.
109
- */
110
- getPlayers(): Player[];
111
- /**
112
- * This will return a DeserialisedStructure which will allow you to easily save to a file if you wish.
113
- *
114
- * The blocks are cloned and thus you're free to modify the blocks in the structure without the risk of it affecting this helper's blocks.
115
- *
116
- * NOTE: endX and endY are also included!
117
- */
118
- sectionBlocks(startX: number, startY: number, endX: number, endY: number): DeserialisedStructure;
119
- }