pw-js-world 0.3.4 → 0.3.5-dev.c3ed5c5
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/Helper.d.ts +119 -0
- package/cm/index.js +26 -0
- package/package.json +1 -1
package/cm/Helper.d.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
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[][]];
|
|
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
|
+
}
|
package/cm/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LayerType = exports.DeserialisedStructure = exports.StructureHelper = exports.Util = exports.createBlockPackets = exports.createBlockPacket = exports.PlayerCounters = exports.PlayerEffect = exports.Player = exports.Block = exports.BufferReader = exports.ComponentTypeHeader = exports.PWGameWorldHelper = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
var Helper_js_1 = require("./Helper.js");
|
|
6
|
+
Object.defineProperty(exports, "PWGameWorldHelper", { enumerable: true, get: function () { return tslib_1.__importDefault(Helper_js_1).default; } });
|
|
7
|
+
var BufferReader_js_1 = require("./BufferReader.js");
|
|
8
|
+
Object.defineProperty(exports, "ComponentTypeHeader", { enumerable: true, get: function () { return BufferReader_js_1.ComponentTypeHeader; } });
|
|
9
|
+
Object.defineProperty(exports, "BufferReader", { enumerable: true, get: function () { return tslib_1.__importDefault(BufferReader_js_1).default; } });
|
|
10
|
+
var Block_js_1 = require("./Block.js");
|
|
11
|
+
Object.defineProperty(exports, "Block", { enumerable: true, get: function () { return tslib_1.__importDefault(Block_js_1).default; } });
|
|
12
|
+
var Player_js_1 = require("./Player.js");
|
|
13
|
+
Object.defineProperty(exports, "Player", { enumerable: true, get: function () { return tslib_1.__importDefault(Player_js_1).default; } });
|
|
14
|
+
Object.defineProperty(exports, "PlayerEffect", { enumerable: true, get: function () { return Player_js_1.PlayerEffect; } });
|
|
15
|
+
Object.defineProperty(exports, "PlayerCounters", { enumerable: true, get: function () { return Player_js_1.PlayerCounters; } });
|
|
16
|
+
var Misc_js_1 = require("./util/Misc.js");
|
|
17
|
+
Object.defineProperty(exports, "createBlockPacket", { enumerable: true, get: function () { return Misc_js_1.createBlockPacket; } });
|
|
18
|
+
Object.defineProperty(exports, "createBlockPackets", { enumerable: true, get: function () { return Misc_js_1.createBlockPackets; } });
|
|
19
|
+
exports.Util = tslib_1.__importStar(require("./util/Misc.js"));
|
|
20
|
+
var Structure_js_1 = require("./Structure.js");
|
|
21
|
+
Object.defineProperty(exports, "StructureHelper", { enumerable: true, get: function () { return tslib_1.__importDefault(Structure_js_1).default; } });
|
|
22
|
+
Object.defineProperty(exports, "DeserialisedStructure", { enumerable: true, get: function () { return Structure_js_1.DeserialisedStructure; } });
|
|
23
|
+
var Constants_js_1 = require("./Constants.js");
|
|
24
|
+
Object.defineProperty(exports, "LayerType", { enumerable: true, get: function () { return Constants_js_1.LayerType; } });
|
|
25
|
+
// import * from "./Helper";
|
|
26
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9saWIvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7OztBQUNBLHlDQUEyRDtBQUFsRCx1SUFBQSxPQUFPLE9BQXFCO0FBRXJDLHFEQUFpRjtBQUF4RSxzSEFBQSxtQkFBbUIsT0FBQTtBQUFFLHdJQUFBLE9BQU8sT0FBZ0I7QUFFckQsdUNBQThDO0FBQXJDLDBIQUFBLE9BQU8sT0FBUztBQUV6Qix5Q0FBNEo7QUFBbkosNEhBQUEsT0FBTyxPQUFVO0FBQUUseUdBQUEsWUFBWSxPQUFBO0FBQUUsMkdBQUEsY0FBYyxPQUFBO0FBRXhELDBDQUF1RTtBQUE5RCw0R0FBQSxpQkFBaUIsT0FBQTtBQUFFLDZHQUFBLGtCQUFrQixPQUFBO0FBQzlDLCtEQUF1QztBQUV2QywrQ0FBMkg7QUFBbEgsd0lBQUEsT0FBTyxPQUFtQjtBQUFFLHFIQUFBLHFCQUFxQixPQUFBO0FBRTFELCtDQUEyQztBQUFsQyx5R0FBQSxTQUFTLE9BQUE7QUFFbEIsNEJBQTRCIn0=
|