pw-js-world 0.2.1-dev.ee2fd11 → 0.3.0
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 +196 -0
- package/cm/Block.js +246 -0
- package/cm/BufferReader.d.ts +330 -0
- package/cm/BufferReader.js +691 -0
- package/cm/Constants.d.ts +4 -0
- package/cm/Constants.js +9 -0
- package/cm/Helper.d.ts +119 -0
- package/cm/Helper.js +510 -0
- package/cm/Player.d.ts +255 -0
- package/cm/Player.js +154 -0
- package/cm/Structure.d.ts +103 -0
- package/cm/Structure.js +208 -0
- package/cm/index.d.ts +9 -0
- package/cm/index.js +24 -0
- package/cm/util/Error.d.ts +7 -0
- package/cm/util/Error.js +11 -0
- package/{esm/Util.d.ts → cm/util/Misc.d.ts} +5 -6
- package/cm/util/Misc.js +100 -0
- package/esm/Block.d.ts +15 -3
- package/esm/Block.js +28 -5
- package/esm/Helper.d.ts +1 -1
- package/esm/Helper.js +8 -5
- package/esm/Player.js +2 -2
- package/esm/Structure.d.ts +1 -2
- package/esm/Structure.js +2 -2
- package/esm/index.d.ts +2 -2
- package/esm/index.js +3 -3
- package/esm/util/Error.d.ts +7 -0
- package/esm/util/Error.js +7 -0
- package/esm/util/Misc.d.ts +22 -0
- package/esm/util/Misc.js +91 -0
- package/package.json +2 -2
- package/esm/Util.js +0 -91
- package/esm/types/excluded.d.ts +0 -10
package/cm/Player.d.ts
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import type { ProtoGen } from "pw-js-api";
|
|
2
|
+
import type { Point } from "./types/index.js";
|
|
3
|
+
export interface IPlayer {
|
|
4
|
+
/**
|
|
5
|
+
* ID of the player.
|
|
6
|
+
*/
|
|
7
|
+
playerId: number;
|
|
8
|
+
/**
|
|
9
|
+
* ID of the player's account.
|
|
10
|
+
*/
|
|
11
|
+
accountId: string;
|
|
12
|
+
/**
|
|
13
|
+
* Name of the player.
|
|
14
|
+
*/
|
|
15
|
+
username: string;
|
|
16
|
+
/**
|
|
17
|
+
* ID of the player's equipped smiley.
|
|
18
|
+
*/
|
|
19
|
+
face: number;
|
|
20
|
+
/**
|
|
21
|
+
* String, could be an admin or developer.
|
|
22
|
+
*/
|
|
23
|
+
role: string;
|
|
24
|
+
/**
|
|
25
|
+
* If player is bot user's friend.
|
|
26
|
+
*/
|
|
27
|
+
isFriend: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Position of the user.
|
|
30
|
+
*
|
|
31
|
+
* Note: This helper does not simulate physics so positions will always be inaccurate.
|
|
32
|
+
*/
|
|
33
|
+
position?: Point;
|
|
34
|
+
/**
|
|
35
|
+
* If player is the world owner.
|
|
36
|
+
*/
|
|
37
|
+
isWorldOwner: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Rights
|
|
40
|
+
*/
|
|
41
|
+
rights: IPlayerRights;
|
|
42
|
+
/**
|
|
43
|
+
* current world state.
|
|
44
|
+
*/
|
|
45
|
+
states: IPlayerWorldState;
|
|
46
|
+
/**
|
|
47
|
+
* List of active effects the player has.
|
|
48
|
+
*/
|
|
49
|
+
effects: PlayerEffect[];
|
|
50
|
+
/**
|
|
51
|
+
* If this player is the bot.
|
|
52
|
+
*/
|
|
53
|
+
isMe: boolean;
|
|
54
|
+
}
|
|
55
|
+
export interface IPlayerRights {
|
|
56
|
+
/**
|
|
57
|
+
* If the player has edit rights.
|
|
58
|
+
*/
|
|
59
|
+
canEdit: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* If the player has god rights.
|
|
62
|
+
*/
|
|
63
|
+
canGod: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* If the player has the ability to toggle minimap.
|
|
66
|
+
*/
|
|
67
|
+
canToggleMinimap: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* If the player has the ability to change the world settings.
|
|
70
|
+
*/
|
|
71
|
+
canChangeWorldSettings: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* List of commands (string) the player can use.
|
|
74
|
+
*/
|
|
75
|
+
availableCommands: string[];
|
|
76
|
+
}
|
|
77
|
+
export interface IPlayerWorldState {
|
|
78
|
+
/**
|
|
79
|
+
* Number of gold coins the player has.
|
|
80
|
+
*/
|
|
81
|
+
coinsGold: number;
|
|
82
|
+
/**
|
|
83
|
+
* Number of blue coins the player has.
|
|
84
|
+
*/
|
|
85
|
+
coinsBlue: number;
|
|
86
|
+
/**
|
|
87
|
+
* Number of times the player died.
|
|
88
|
+
*/
|
|
89
|
+
deaths: number;
|
|
90
|
+
/**
|
|
91
|
+
* Coordinates of collected coins?
|
|
92
|
+
*/
|
|
93
|
+
collectedItems: Point[];
|
|
94
|
+
/**
|
|
95
|
+
* If player has gold crown on.
|
|
96
|
+
*/
|
|
97
|
+
hasGoldCrown: boolean;
|
|
98
|
+
/**
|
|
99
|
+
* If player has won the world.
|
|
100
|
+
*/
|
|
101
|
+
hasSilverCrown: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Zero indexed, map of the player's switch state.
|
|
104
|
+
*/
|
|
105
|
+
switches: boolean[];
|
|
106
|
+
/**
|
|
107
|
+
* If player is in god mode right now.
|
|
108
|
+
*/
|
|
109
|
+
godmode: boolean;
|
|
110
|
+
/**
|
|
111
|
+
* If player is in mod mode right now.
|
|
112
|
+
*/
|
|
113
|
+
modmode: boolean;
|
|
114
|
+
/**
|
|
115
|
+
* ID of the team the player is associated with right now.
|
|
116
|
+
*/
|
|
117
|
+
teamId: number;
|
|
118
|
+
/**
|
|
119
|
+
* Instance of counters associated with the player.
|
|
120
|
+
*/
|
|
121
|
+
counters: PlayerCounters;
|
|
122
|
+
}
|
|
123
|
+
export interface IPlayerEffect {
|
|
124
|
+
/**
|
|
125
|
+
* The ID of the effect.
|
|
126
|
+
*/
|
|
127
|
+
effectId: number;
|
|
128
|
+
/**
|
|
129
|
+
* If applicable, the duration of the effect.
|
|
130
|
+
*/
|
|
131
|
+
duration?: number;
|
|
132
|
+
/**
|
|
133
|
+
* If applicable, the strength of the effect. (For example speed or multi jump effect)
|
|
134
|
+
*/
|
|
135
|
+
strength?: number;
|
|
136
|
+
}
|
|
137
|
+
export default class Player {
|
|
138
|
+
/**
|
|
139
|
+
* ID of the player.
|
|
140
|
+
*/
|
|
141
|
+
playerId: number;
|
|
142
|
+
/**
|
|
143
|
+
* ID of the player's account.
|
|
144
|
+
*/
|
|
145
|
+
accountId: string;
|
|
146
|
+
/**
|
|
147
|
+
* Name of the player.
|
|
148
|
+
*/
|
|
149
|
+
username: string;
|
|
150
|
+
/**
|
|
151
|
+
* ID of the player's equipped smiley.
|
|
152
|
+
*/
|
|
153
|
+
face: number;
|
|
154
|
+
/**
|
|
155
|
+
* String, could be an admin or developer.
|
|
156
|
+
*/
|
|
157
|
+
role: string;
|
|
158
|
+
/**
|
|
159
|
+
* If player is bot user's friend.
|
|
160
|
+
*/
|
|
161
|
+
isFriend: boolean;
|
|
162
|
+
/**
|
|
163
|
+
* Position of the user.
|
|
164
|
+
*
|
|
165
|
+
* Note: This helper does not simulate physics so positions will always be inaccurate.
|
|
166
|
+
*/
|
|
167
|
+
position?: Point;
|
|
168
|
+
/**
|
|
169
|
+
* If player is the world owner.
|
|
170
|
+
*/
|
|
171
|
+
isWorldOwner: boolean;
|
|
172
|
+
/**
|
|
173
|
+
* Rights
|
|
174
|
+
*/
|
|
175
|
+
rights: IPlayerRights;
|
|
176
|
+
/**
|
|
177
|
+
* current world state.
|
|
178
|
+
*/
|
|
179
|
+
states: IPlayerWorldState;
|
|
180
|
+
/**
|
|
181
|
+
* List of active effects the player has.
|
|
182
|
+
*/
|
|
183
|
+
effects: PlayerEffect[];
|
|
184
|
+
/**
|
|
185
|
+
* If this player is the bot.
|
|
186
|
+
*/
|
|
187
|
+
isMe: boolean;
|
|
188
|
+
constructor(props: ProtoGen.PlayerProperties, states?: IPlayerWorldState | boolean);
|
|
189
|
+
/**
|
|
190
|
+
* This is destructive, this is only for on reset packet.
|
|
191
|
+
*/
|
|
192
|
+
resetState(): void;
|
|
193
|
+
/**
|
|
194
|
+
* Destructive.
|
|
195
|
+
*/
|
|
196
|
+
resetRights(): void;
|
|
197
|
+
}
|
|
198
|
+
export declare class PlayerEffect {
|
|
199
|
+
/**
|
|
200
|
+
* The ID of the effect.
|
|
201
|
+
*/
|
|
202
|
+
effectId: number;
|
|
203
|
+
/**
|
|
204
|
+
* If applicable, the duration of the effect.
|
|
205
|
+
*/
|
|
206
|
+
duration?: number;
|
|
207
|
+
/**
|
|
208
|
+
* If applicable, the strength of the effect. (For example speed or multi jump effect)
|
|
209
|
+
*/
|
|
210
|
+
strength?: number;
|
|
211
|
+
/**
|
|
212
|
+
* The time the effect occurred.
|
|
213
|
+
*/
|
|
214
|
+
triggeredAt: number;
|
|
215
|
+
constructor(effect: IPlayerEffect, triggeredAt?: number);
|
|
216
|
+
/**
|
|
217
|
+
* Note: If this effect is non timed, this will always return false.
|
|
218
|
+
*/
|
|
219
|
+
get hasExpired(): boolean;
|
|
220
|
+
/**
|
|
221
|
+
* Milliseconds showing how long before this expires.
|
|
222
|
+
*
|
|
223
|
+
* Note: If this effect is non timed, this will return infinity.
|
|
224
|
+
*/
|
|
225
|
+
get remaining(): number;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Index based
|
|
229
|
+
*/
|
|
230
|
+
declare enum CounterKeys {
|
|
231
|
+
WHITE = 0,
|
|
232
|
+
GRAY = 1,
|
|
233
|
+
BLACK = 2,
|
|
234
|
+
RED = 3,
|
|
235
|
+
ORANGE = 4,
|
|
236
|
+
YELLOW = 5,
|
|
237
|
+
GREEN = 6,
|
|
238
|
+
CYAN = 7,
|
|
239
|
+
BLUE = 8,
|
|
240
|
+
MAGENTA = 9
|
|
241
|
+
}
|
|
242
|
+
export declare class PlayerCounters {
|
|
243
|
+
readonly scores: number[];
|
|
244
|
+
constructor(scores?: number[]);
|
|
245
|
+
/**
|
|
246
|
+
* Returns the current score of the player's counter for that colour.
|
|
247
|
+
*
|
|
248
|
+
* Can be ID (counter id) or colour (use as predefined).
|
|
249
|
+
*
|
|
250
|
+
* If the colour given is unknown, it will error. Capitalisation is irrelevant.
|
|
251
|
+
*/
|
|
252
|
+
get(id: number): number | undefined;
|
|
253
|
+
get(id: keyof typeof CounterKeys): number | undefined;
|
|
254
|
+
}
|
|
255
|
+
export {};
|
package/cm/Player.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PlayerCounters = exports.PlayerEffect = void 0;
|
|
4
|
+
const Misc_js_1 = require("./util/Misc.js");
|
|
5
|
+
class Player {
|
|
6
|
+
constructor(props, states) {
|
|
7
|
+
/**
|
|
8
|
+
* List of active effects the player has.
|
|
9
|
+
*/
|
|
10
|
+
this.effects = [];
|
|
11
|
+
/**
|
|
12
|
+
* If this player is the bot.
|
|
13
|
+
*/
|
|
14
|
+
this.isMe = false;
|
|
15
|
+
this.accountId = props.accountId;
|
|
16
|
+
this.face = props.face;
|
|
17
|
+
this.isFriend = props.isFriend;
|
|
18
|
+
this.isWorldOwner = props.isWorldOwner;
|
|
19
|
+
this.playerId = props.playerId;
|
|
20
|
+
this.position = props.position ? {
|
|
21
|
+
x: props.position.x,
|
|
22
|
+
y: props.position.y
|
|
23
|
+
} : undefined;
|
|
24
|
+
if (!props.rights)
|
|
25
|
+
this.resetRights();
|
|
26
|
+
else
|
|
27
|
+
this.rights = {
|
|
28
|
+
availableCommands: props.rights.availableCommands,
|
|
29
|
+
canChangeWorldSettings: props.rights.canChangeWorldSettings,
|
|
30
|
+
canEdit: props.rights.canEdit,
|
|
31
|
+
canGod: props.rights.canGod,
|
|
32
|
+
canToggleMinimap: props.rights.canToggleMinimap,
|
|
33
|
+
};
|
|
34
|
+
this.role = props.role;
|
|
35
|
+
this.username = props.username;
|
|
36
|
+
if (typeof states === "boolean") {
|
|
37
|
+
this.isMe = states;
|
|
38
|
+
states = undefined;
|
|
39
|
+
}
|
|
40
|
+
if (!states) {
|
|
41
|
+
// Could be bot via init that don't get states.
|
|
42
|
+
this.resetState();
|
|
43
|
+
}
|
|
44
|
+
else
|
|
45
|
+
this.states = {
|
|
46
|
+
coinsBlue: states.coinsBlue,
|
|
47
|
+
coinsGold: states.coinsGold,
|
|
48
|
+
collectedItems: (0, Misc_js_1.map)(states.collectedItems, v => ({ x: v.x, y: v.y })),
|
|
49
|
+
deaths: states.deaths,
|
|
50
|
+
godmode: states.godmode,
|
|
51
|
+
hasGoldCrown: states.hasGoldCrown,
|
|
52
|
+
hasSilverCrown: states.hasSilverCrown,
|
|
53
|
+
modmode: states.modmode,
|
|
54
|
+
switches: states.switches,
|
|
55
|
+
teamId: states.teamId,
|
|
56
|
+
counters: states.counters
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* This is destructive, this is only for on reset packet.
|
|
61
|
+
*/
|
|
62
|
+
resetState() {
|
|
63
|
+
this.states = {
|
|
64
|
+
coinsBlue: 0,
|
|
65
|
+
coinsGold: 0,
|
|
66
|
+
collectedItems: [],
|
|
67
|
+
deaths: 0,
|
|
68
|
+
godmode: false,
|
|
69
|
+
hasGoldCrown: false,
|
|
70
|
+
hasSilverCrown: false,
|
|
71
|
+
modmode: false,
|
|
72
|
+
switches: new Array(1000).fill(false),
|
|
73
|
+
teamId: 0,
|
|
74
|
+
counters: new PlayerCounters()
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Destructive.
|
|
79
|
+
*/
|
|
80
|
+
resetRights() {
|
|
81
|
+
this.rights = {
|
|
82
|
+
availableCommands: [],
|
|
83
|
+
canChangeWorldSettings: false,
|
|
84
|
+
canEdit: false,
|
|
85
|
+
canGod: false,
|
|
86
|
+
canToggleMinimap: false
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.default = Player;
|
|
91
|
+
class PlayerEffect {
|
|
92
|
+
constructor(effect, triggeredAt) {
|
|
93
|
+
this.effectId = effect.effectId;
|
|
94
|
+
this.duration = effect.duration;
|
|
95
|
+
this.strength = effect.strength;
|
|
96
|
+
this.triggeredAt = triggeredAt !== null && triggeredAt !== void 0 ? triggeredAt : Date.now();
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Note: If this effect is non timed, this will always return false.
|
|
100
|
+
*/
|
|
101
|
+
get hasExpired() {
|
|
102
|
+
if (this.duration === undefined)
|
|
103
|
+
return false;
|
|
104
|
+
return Date.now() > (this.triggeredAt + this.duration);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Milliseconds showing how long before this expires.
|
|
108
|
+
*
|
|
109
|
+
* Note: If this effect is non timed, this will return infinity.
|
|
110
|
+
*/
|
|
111
|
+
get remaining() {
|
|
112
|
+
if (this.duration === undefined)
|
|
113
|
+
return Infinity;
|
|
114
|
+
return Math.max(0, Date.now() - (this.triggeredAt + this.duration));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.PlayerEffect = PlayerEffect;
|
|
118
|
+
/**
|
|
119
|
+
* Index based
|
|
120
|
+
*/
|
|
121
|
+
var CounterKeys;
|
|
122
|
+
(function (CounterKeys) {
|
|
123
|
+
CounterKeys[CounterKeys["WHITE"] = 0] = "WHITE";
|
|
124
|
+
CounterKeys[CounterKeys["GRAY"] = 1] = "GRAY";
|
|
125
|
+
CounterKeys[CounterKeys["BLACK"] = 2] = "BLACK";
|
|
126
|
+
CounterKeys[CounterKeys["RED"] = 3] = "RED";
|
|
127
|
+
CounterKeys[CounterKeys["ORANGE"] = 4] = "ORANGE";
|
|
128
|
+
CounterKeys[CounterKeys["YELLOW"] = 5] = "YELLOW";
|
|
129
|
+
CounterKeys[CounterKeys["GREEN"] = 6] = "GREEN";
|
|
130
|
+
CounterKeys[CounterKeys["CYAN"] = 7] = "CYAN";
|
|
131
|
+
CounterKeys[CounterKeys["BLUE"] = 8] = "BLUE";
|
|
132
|
+
CounterKeys[CounterKeys["MAGENTA"] = 9] = "MAGENTA";
|
|
133
|
+
})(CounterKeys || (CounterKeys = {}));
|
|
134
|
+
class PlayerCounters {
|
|
135
|
+
constructor(scores = []) {
|
|
136
|
+
var _a;
|
|
137
|
+
this.scores = [];
|
|
138
|
+
for (let i = 0; i < 10; i++) {
|
|
139
|
+
this.scores[i] = (_a = scores[i]) !== null && _a !== void 0 ? _a : 0;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
get(id) {
|
|
143
|
+
if (typeof id === "number")
|
|
144
|
+
return this.scores[id];
|
|
145
|
+
const index = CounterKeys[id.toUpperCase()];
|
|
146
|
+
if (index !== undefined) {
|
|
147
|
+
return this.scores[index];
|
|
148
|
+
}
|
|
149
|
+
else
|
|
150
|
+
throw Error("Unknown colour");
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
exports.PlayerCounters = PlayerCounters;
|
|
154
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUGxheWVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vbGliL1BsYXllci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFFQSw0Q0FBcUM7QUE4SXJDLE1BQXFCLE1BQU07SUFzRHZCLFlBQVksS0FBZ0MsRUFBRSxNQUFvQztRQVZsRjs7V0FFRztRQUNILFlBQU8sR0FBa0IsRUFBRSxDQUFDO1FBRTVCOztXQUVHO1FBQ0gsU0FBSSxHQUFZLEtBQUssQ0FBQztRQUdsQixJQUFJLENBQUMsU0FBUyxHQUFHLEtBQUssQ0FBQyxTQUFTLENBQUM7UUFDakMsSUFBSSxDQUFDLElBQUksR0FBRyxLQUFLLENBQUMsSUFBSSxDQUFDO1FBQ3ZCLElBQUksQ0FBQyxRQUFRLEdBQUcsS0FBSyxDQUFDLFFBQVEsQ0FBQztRQUMvQixJQUFJLENBQUMsWUFBWSxHQUFHLEtBQUssQ0FBQyxZQUFZLENBQUM7UUFDdkMsSUFBSSxDQUFDLFF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0FBQztRQUVuRCxNQUFNLEtBQUssR0FBRyxXQUFXLENBQUMsRUFBRSxDQUFDLFdBQVcsRUFBOEIsQ0FBQyxDQUFDO1FBRXhFLElBQUksS0FBSyxLQUFLLFNBQVMsRUFBRSxDQUFDO1lBQ3RCLE9BQU8sSUFBSSxDQUFDLE1BQU0sQ0FBQyxLQUFLLENBQUMsQ0FBQztRQUM5QixDQUFDOztZQUFNLE1BQU0sS0FBSyxDQUFDLGdCQUFnQixDQUFDLENBQUM7SUFDekMsQ0FBQztDQUNKO0FBNUJELHdDQTRCQyJ9
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import Block from "./Block";
|
|
2
|
+
import type { BlockArg } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* This is external to the main Helper, it will allow developers to use the structure without needing to use helper if they so wish.
|
|
5
|
+
*
|
|
6
|
+
* All of the functions are static!
|
|
7
|
+
*/
|
|
8
|
+
export default class StructureHelper {
|
|
9
|
+
/**
|
|
10
|
+
* NOTE: If you're reading a file, you must get it then pass it to read.
|
|
11
|
+
*
|
|
12
|
+
* This is for reading the structure itself, if you have just the blocks (and width/height), you must use deserialiseStructBlocks;
|
|
13
|
+
*
|
|
14
|
+
* @param data Buffer representing the JSON structure itself.
|
|
15
|
+
*/
|
|
16
|
+
static read(data: Buffer | Uint8Array | IStructure): DeserialisedStructure;
|
|
17
|
+
/**
|
|
18
|
+
* If width or height are not provided, the structure may be trimmed (empty blocks).
|
|
19
|
+
*
|
|
20
|
+
* This is ideal if you want the trimmed structure in that case.
|
|
21
|
+
*/
|
|
22
|
+
static deserialiseStructBlocks(struct: IStructureBlocks, width?: number, height?: number): {
|
|
23
|
+
blocks: [Block[][], Block[][]];
|
|
24
|
+
width: number;
|
|
25
|
+
height: number;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Represents the structure in its deserialised form, allows for modification
|
|
30
|
+
*/
|
|
31
|
+
export declare class DeserialisedStructure {
|
|
32
|
+
blocks: [Block[][], Block[][]];
|
|
33
|
+
width: number;
|
|
34
|
+
height: number;
|
|
35
|
+
constructor(blocks: [Block[][], Block[][]], struct: Omit<IStructure, "version" | "blocks">);
|
|
36
|
+
/**
|
|
37
|
+
* This will return a new object that meets IStructureBlocks interface.
|
|
38
|
+
*/
|
|
39
|
+
getSerialisedBlocks(): IStructureBlocks;
|
|
40
|
+
/**
|
|
41
|
+
* This will return the structure form, giving you the freedom to choose your own way of saving.
|
|
42
|
+
*/
|
|
43
|
+
toStruct(): IStructure;
|
|
44
|
+
/**
|
|
45
|
+
* Buffer form of the structure.
|
|
46
|
+
*/
|
|
47
|
+
toBuffer(): Buffer<ArrayBuffer>;
|
|
48
|
+
/**
|
|
49
|
+
* The JSON stringified of the structure.
|
|
50
|
+
*/
|
|
51
|
+
toJSONString(space?: number): string;
|
|
52
|
+
/**
|
|
53
|
+
* (This is for browser client or Bun)
|
|
54
|
+
*
|
|
55
|
+
* Blob form of the structure.
|
|
56
|
+
*/
|
|
57
|
+
toBlob(): Blob;
|
|
58
|
+
/**
|
|
59
|
+
* Uint8Array form of the structure.
|
|
60
|
+
*/
|
|
61
|
+
toBytes(): Uint8Array<ArrayBuffer>;
|
|
62
|
+
/**
|
|
63
|
+
* This will return a list of packets containing all of the blocks.
|
|
64
|
+
*/
|
|
65
|
+
toPackets(x: number, y: number): import("./types").SendableBlockPacket[];
|
|
66
|
+
}
|
|
67
|
+
export interface IStructure {
|
|
68
|
+
/**
|
|
69
|
+
* Version of the structure object, not the world.
|
|
70
|
+
*/
|
|
71
|
+
version: number;
|
|
72
|
+
/**
|
|
73
|
+
* The maximum width of the structure.
|
|
74
|
+
*/
|
|
75
|
+
width: number;
|
|
76
|
+
/**
|
|
77
|
+
* The maximum height of the structure.
|
|
78
|
+
*/
|
|
79
|
+
height: number;
|
|
80
|
+
/**
|
|
81
|
+
* Object containing the mappings and the blocks.
|
|
82
|
+
*/
|
|
83
|
+
blocks: IStructureBlocks;
|
|
84
|
+
}
|
|
85
|
+
interface IStructureBlocks {
|
|
86
|
+
/**
|
|
87
|
+
* Index starts at 0, this is the mapping of blocks (in block name ids in UPPER_CASE)
|
|
88
|
+
*/
|
|
89
|
+
mapping: string[];
|
|
90
|
+
/**
|
|
91
|
+
* Index starts at 0, this is the mapping of args (2nd elements and beyond in each block pos in blocks)
|
|
92
|
+
*/
|
|
93
|
+
args: BlockArg[];
|
|
94
|
+
/**
|
|
95
|
+
* If array, it's index corresponds to the mapping, the element will be array of locations and args indexed by layers (while impossible, it's for possible compatibility with mirrored blocks, foreground block in background layer etc)
|
|
96
|
+
*
|
|
97
|
+
* If argMapping exists in a block, it'll be an index that corresponds to the block's arguments in args array.
|
|
98
|
+
*
|
|
99
|
+
* If string, it's the encoded version of the object, use atob then JSON parse.
|
|
100
|
+
*/
|
|
101
|
+
blocks: [[x: number, y: number, ...argMapping: number[]][], [x: number, y: number, ...argMapping: number[]][]][];
|
|
102
|
+
}
|
|
103
|
+
export {};
|