pw-js-world 0.0.4 → 0.0.5-dev.24aedef
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/{dist → cm}/Block.d.ts +3 -3
- package/cm/Block.js +161 -0
- package/cm/BufferReader.js +673 -0
- package/cm/Constants.js +9 -0
- package/{dist → cm}/Helper.d.ts +4 -4
- package/cm/Helper.js +494 -0
- package/{dist → cm}/Player.d.ts +1 -1
- package/cm/Player.js +115 -0
- package/cm/index.js +18 -0
- package/esm/Block.d.ts +117 -0
- package/{dist → esm}/Block.js +3 -3
- package/esm/BufferReader.d.ts +324 -0
- package/{dist → esm}/BufferReader.js +8 -13
- package/esm/Constants.d.ts +4 -0
- package/esm/Helper.d.ts +115 -0
- package/{dist → esm}/Helper.js +5 -5
- package/{lib/Player.ts → esm/Player.d.ts} +16 -111
- package/{lib/index.ts → esm/index.d.ts} +0 -6
- package/{dist → esm}/index.js +3 -2
- package/{lib → esm}/types/index.d.ts +2 -2
- package/package.json +6 -7
- package/tsconfig-cm.json +8 -0
- package/tsconfig-esm.json +8 -0
- package/dist/types/index.d.ts +0 -49
- package/esm.mjs +0 -33
- package/lib/Block.ts +0 -217
- package/lib/BufferReader.ts +0 -770
- package/lib/Constants.ts +0 -4
- package/lib/Helper.ts +0 -593
- /package/{dist → cm}/BufferReader.d.ts +0 -0
- /package/{dist → cm}/Constants.d.ts +0 -0
- /package/{dist → cm}/index.d.ts +0 -0
- /package/{dist → esm}/Constants.js +0 -0
- /package/{dist → esm}/Player.js +0 -0
package/package.json
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pw-js-world",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5-dev.24aedef",
|
|
4
4
|
"description": "An optional package for PW-JS-Api, aims to serve world purposes.",
|
|
5
|
-
"main": "lib/index.ts",
|
|
6
5
|
"exports": {
|
|
7
|
-
"
|
|
8
|
-
"import": "./esm.
|
|
9
|
-
"require": "./
|
|
10
|
-
"types": "./dist/index.d.ts"
|
|
6
|
+
"types": "./esm/index.js",
|
|
7
|
+
"import": "./esm/index.js",
|
|
8
|
+
"require": "./cm/index.js"
|
|
11
9
|
},
|
|
12
10
|
"keywords": [
|
|
13
11
|
"PixelWalker",
|
|
@@ -36,6 +34,7 @@
|
|
|
36
34
|
},
|
|
37
35
|
"scripts": {
|
|
38
36
|
"test": "bun test/index.ts",
|
|
39
|
-
"build": "
|
|
37
|
+
"build:ts": "tsc -p tsconfig-cm.json & tsc -p tsconfig-esm.json",
|
|
38
|
+
"build": "rimraf cm esm && npm run build:ts && ncp lib/types esm/types"
|
|
40
39
|
}
|
|
41
40
|
}
|
package/tsconfig-cm.json
ADDED
package/dist/types/index.d.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
// I cba so all of the typings will go here
|
|
2
|
-
|
|
3
|
-
import Block from "../Block";
|
|
4
|
-
import Player, { IPlayerEffect, IPlayerRights } from "../Player";
|
|
5
|
-
|
|
6
|
-
type Point = { x: number, y: number };
|
|
7
|
-
|
|
8
|
-
export interface SendableBlockPacket {
|
|
9
|
-
/**
|
|
10
|
-
* If true, just leave one position
|
|
11
|
-
*/
|
|
12
|
-
isFillOperation: boolean;
|
|
13
|
-
blockId: number;
|
|
14
|
-
layer: number;
|
|
15
|
-
/**
|
|
16
|
-
* Note: (I THINK) 250 positions limit.
|
|
17
|
-
*/
|
|
18
|
-
positions: Point[];
|
|
19
|
-
extraFields?: Uint8Array;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export type BlockArg = (string | number | bigint | boolean | Buffer);
|
|
23
|
-
|
|
24
|
-
export type PWGameHook = {
|
|
25
|
-
worldBlockPlacedPacket: { player: Player, oldBlocks: Block[], newBlocks: Block[] },
|
|
26
|
-
playerJoinedPacket: { player: Player },
|
|
27
|
-
playerLeftPacket: { player: Player },
|
|
28
|
-
playerInitPacket: { player: Player },
|
|
29
|
-
playerFacePacket: { player: Player, oldFace: number },
|
|
30
|
-
playerModModePacket: { player: Player, oldState: boolean },
|
|
31
|
-
playerGodModePacket: { player: Player, oldState: boolean },
|
|
32
|
-
playerAddEffectPacket: { player: Player, effect: IPlayerEffect },
|
|
33
|
-
playerRemoveEffectPacket: { player: Player, effect: IPlayerEffect },
|
|
34
|
-
playerResetEffectsPacket: { player: Player, effects: IPlayerEffect[] },
|
|
35
|
-
playerMovedPacket: { player: Player },
|
|
36
|
-
playerResetPacket: { player: Player },
|
|
37
|
-
playerRespawnPacket: { player: Player },
|
|
38
|
-
playerUpdateRightsPacket: { player: Player, rights: IPlayerRights },
|
|
39
|
-
playerTeamUpdatePacket: { player: Player, oldTeam: number },
|
|
40
|
-
playerCountersUpdatePacket: { player: Player, oldState: { coinsBlue: number, coinsGold: number, deaths: number } },
|
|
41
|
-
playerTeleportedPacket: { player: Player },
|
|
42
|
-
globalSwitchChangedPacket: { player: Player },
|
|
43
|
-
globalSwitchResetPacket: { player: Player },
|
|
44
|
-
playerLocalSwitchChangedPacket: { player: Player },
|
|
45
|
-
playerLocalSwitchResetPacket: { player: Player },
|
|
46
|
-
playerChatPacket: { player: Player },
|
|
47
|
-
playerDirectMessagePacket: { player: Player },
|
|
48
|
-
playerTouchBlockPacket: { player: Player },
|
|
49
|
-
};
|
package/esm.mjs
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
// TODO: clean this code to make it easier to get named exports.
|
|
2
|
-
let PWGameWorldHelper = (await import("./dist/Helper.js")).default;
|
|
3
|
-
let Block = (await import("./dist/Block.js")).default;
|
|
4
|
-
let BufferReader = (await import("./dist/BufferReader.js"));
|
|
5
|
-
|
|
6
|
-
let ComponentTypeHeader = BufferReader.ComponentTypeHeader;
|
|
7
|
-
|
|
8
|
-
BufferReader = BufferReader.default;
|
|
9
|
-
|
|
10
|
-
let Player = (await import("./dist/Player.js"));
|
|
11
|
-
|
|
12
|
-
let PlayerEffect = Player.PlayerEffect;
|
|
13
|
-
|
|
14
|
-
Player = Player.default;
|
|
15
|
-
|
|
16
|
-
if ("default" in PWGameWorldHelper) PWGameWorldHelper = PWGameWorldHelper.default;
|
|
17
|
-
if ("default" in Block) Block = Block.default;
|
|
18
|
-
if ("default" in BufferReader) BufferReader = BufferReader.default;
|
|
19
|
-
if ("default" in Player) Player = Player.default;
|
|
20
|
-
|
|
21
|
-
const Constants = (await import("./dist/Constants.js")).default;
|
|
22
|
-
|
|
23
|
-
export default {
|
|
24
|
-
PWGameWorldHelper, Block, BufferReader,
|
|
25
|
-
Player, Constants, ComponentTypeHeader,
|
|
26
|
-
PlayerEffect
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export {
|
|
30
|
-
PWGameWorldHelper, Block, BufferReader,
|
|
31
|
-
Player, Constants, ComponentTypeHeader,
|
|
32
|
-
PlayerEffect
|
|
33
|
-
};
|
package/lib/Block.ts
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import { BlockNames } from "pw-js-api";
|
|
2
|
-
import type { BlockArg, Point, SendableBlockPacket } from "./types";
|
|
3
|
-
import BufferReader, { ComponentTypeHeader } from "./BufferReader";
|
|
4
|
-
import { LayerType } from "./Constants";
|
|
5
|
-
|
|
6
|
-
export default class Block {
|
|
7
|
-
bId: number;
|
|
8
|
-
args: BlockArg[] = [];
|
|
9
|
-
|
|
10
|
-
constructor(bId: number | keyof typeof BlockNames, args?: BlockArg[]) {
|
|
11
|
-
if (typeof bId === "number") this.bId = bId;
|
|
12
|
-
else {
|
|
13
|
-
this.bId = BlockNames[bId];
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (args) this.args = args;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* I mean... Just use .args.length !== 0 to see if it has args.
|
|
21
|
-
*
|
|
22
|
-
* But anyway, this will return true if there is at least one args, otherwise false.
|
|
23
|
-
*/
|
|
24
|
-
hasArgs() : boolean {
|
|
25
|
-
return this.args.length !== 0;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* For helper.
|
|
30
|
-
*
|
|
31
|
-
* This is in Block class for organisation.
|
|
32
|
-
*
|
|
33
|
-
* This will deserialise by using the reader to get the block ID then retrieve the args, if applicable.
|
|
34
|
-
*/
|
|
35
|
-
static deserialize(reader: BufferReader) : Block {
|
|
36
|
-
return new Block(reader.readUInt32LE()).deserializeArgs(reader);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
protected deserializeArgs(reader: BufferReader, flag = false) : this {
|
|
40
|
-
const format: ComponentTypeHeader[] = (BlockArgsHeadings as any)[this.name];
|
|
41
|
-
|
|
42
|
-
for (let i = 0; i < (format?.length ?? 0); i++) {
|
|
43
|
-
if (flag) {
|
|
44
|
-
reader.expectUInt8(format[i]);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
this.args[i] = reader.read(format[i], !flag);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return this;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* For helper.
|
|
55
|
-
*
|
|
56
|
-
* This is in Block class for organisation.
|
|
57
|
-
*/
|
|
58
|
-
static deserializeArgs(blockId: number, reader: BufferReader, flag = false) : BlockArg[] {
|
|
59
|
-
const format: ComponentTypeHeader[] = (BlockArgsHeadings as any)[BlockNames[blockId]];
|
|
60
|
-
|
|
61
|
-
const args = [];
|
|
62
|
-
|
|
63
|
-
for (let i = 0; i < (format?.length ?? 0); i++) {
|
|
64
|
-
if (flag) {
|
|
65
|
-
reader.expectUInt8(format[i]);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
args[i] = reader.read(format[i], !flag);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return args;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Serializes the block into a buffer. This is used to convert
|
|
76
|
-
* the block into a binary format that can be sent over the game
|
|
77
|
-
* server. As this is static, block id and args are required.
|
|
78
|
-
*
|
|
79
|
-
* - Little Endian
|
|
80
|
-
* - With Id
|
|
81
|
-
* - Type Byte omitted
|
|
82
|
-
*/
|
|
83
|
-
public static serializeArgs(bId: number, args: BlockArg[]): Buffer;
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Serializes the block into a buffer. This is used to convert
|
|
87
|
-
* the block into a binary format that can be sent over the game
|
|
88
|
-
* server. As this is static, block id and args are required.
|
|
89
|
-
*
|
|
90
|
-
* - Big Endian
|
|
91
|
-
* - No Id
|
|
92
|
-
* - Type Byte included
|
|
93
|
-
*/
|
|
94
|
-
public static serializeArgs(bId: number, args: BlockArg[], options: { endian: "big"; writeId: false; readTypeByte: true }): Buffer;
|
|
95
|
-
|
|
96
|
-
public static serializeArgs(bId: number, args: BlockArg[], options?: { endian: "little" | "big"; writeId: boolean; readTypeByte: boolean }): Buffer {
|
|
97
|
-
options ||= {
|
|
98
|
-
endian: "little",
|
|
99
|
-
writeId: true,
|
|
100
|
-
readTypeByte: false,
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
const buffer: Buffer[] = [];
|
|
104
|
-
|
|
105
|
-
if (options.writeId) {
|
|
106
|
-
const idBuffer = Buffer.alloc(4);
|
|
107
|
-
idBuffer.writeUInt32LE(bId);
|
|
108
|
-
buffer.push(idBuffer);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const blockData:ComponentTypeHeader[] = (BlockArgsHeadings as any)[BlockNames[bId]] ?? [];
|
|
112
|
-
|
|
113
|
-
for (let i = 0, len = blockData.length; i < len; i++) {
|
|
114
|
-
const entry = BufferReader.Dynamic(i, args[i]);
|
|
115
|
-
buffer.push(entry);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return Buffer.concat(buffer);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
*
|
|
123
|
-
* @param pos List of points (X and Y)
|
|
124
|
-
*/
|
|
125
|
-
toPacket(pos: Point[], layer: LayerType) : SendableBlockPacket;
|
|
126
|
-
toPacket(x: number, y: number, layer: LayerType) : SendableBlockPacket;
|
|
127
|
-
toPacket(pos: Point[] | number, y: number, layer?: LayerType) : SendableBlockPacket {
|
|
128
|
-
if (typeof pos === "number") {
|
|
129
|
-
pos = [{
|
|
130
|
-
x: pos, y
|
|
131
|
-
}];
|
|
132
|
-
|
|
133
|
-
layer = layer ?? 0;
|
|
134
|
-
} else layer = y ?? 0;
|
|
135
|
-
|
|
136
|
-
return {
|
|
137
|
-
isFillOperation: false,
|
|
138
|
-
blockId: this.bId,
|
|
139
|
-
layer,
|
|
140
|
-
positions: pos,
|
|
141
|
-
extraFields: Block.serializeArgs(this.bId, this.args, { endian: "big", writeId: false, readTypeByte: true })
|
|
142
|
-
} satisfies SendableBlockPacket;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* This will return the block name in UPPER_CASE form.
|
|
147
|
-
*
|
|
148
|
-
* For eg EFFECTS_INVULNERABILITY.
|
|
149
|
-
*/
|
|
150
|
-
get name() : keyof typeof BlockNames {
|
|
151
|
-
return BlockNames[this.bId] as keyof typeof BlockNames;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Returns a copy of the block.
|
|
156
|
-
*/
|
|
157
|
-
clone(obj?: false) : Block;
|
|
158
|
-
clone(obj: true) : { bId: number, args: BlockArg[], name: string }
|
|
159
|
-
clone(obj = false) {
|
|
160
|
-
if (obj === true) return { bId: this.bId, args: this.args, name: this.name };
|
|
161
|
-
|
|
162
|
-
return new Block(this.bId, this.args);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* This mapping contains definitions of block data which require additional
|
|
168
|
-
* arguments to be sent or received with.
|
|
169
|
-
*/
|
|
170
|
-
export const BlockArgsHeadings = {
|
|
171
|
-
COIN_GOLD_DOOR: [ComponentTypeHeader.Int32],
|
|
172
|
-
COIN_BLUE_DOOR: [ComponentTypeHeader.Int32],
|
|
173
|
-
COIN_GOLD_GATE: [ComponentTypeHeader.Int32],
|
|
174
|
-
COIN_BLUE_GATE: [ComponentTypeHeader.Int32],
|
|
175
|
-
|
|
176
|
-
EFFECTS_JUMP_HEIGHT: [ComponentTypeHeader.Int32],
|
|
177
|
-
EFFECTS_FLY: [ComponentTypeHeader.Boolean],
|
|
178
|
-
EFFECTS_SPEED: [ComponentTypeHeader.Int32],
|
|
179
|
-
EFFECTS_INVULNERABILITY: [ComponentTypeHeader.Boolean],
|
|
180
|
-
EFFECTS_CURSE: [ComponentTypeHeader.Int32],
|
|
181
|
-
EFFECTS_ZOMBIE: [ComponentTypeHeader.Int32],
|
|
182
|
-
EFFECTS_GRAVITYFORCE: [ComponentTypeHeader.Int32],
|
|
183
|
-
EFFECTS_MULTI_JUMP: [ComponentTypeHeader.Int32],
|
|
184
|
-
// gravity effects no data
|
|
185
|
-
// effects off
|
|
186
|
-
// effects zombie
|
|
187
|
-
|
|
188
|
-
TOOL_PORTAL_WORLD_SPAWN: [ComponentTypeHeader.Int32],
|
|
189
|
-
|
|
190
|
-
SIGN_NORMAL: [ComponentTypeHeader.String],
|
|
191
|
-
SIGN_RED: [ComponentTypeHeader.String],
|
|
192
|
-
SIGN_GREEN: [ComponentTypeHeader.String],
|
|
193
|
-
SIGN_BLUE: [ComponentTypeHeader.String],
|
|
194
|
-
SIGN_GOLD: [ComponentTypeHeader.String],
|
|
195
|
-
|
|
196
|
-
PORTAL: [ComponentTypeHeader.Int32, ComponentTypeHeader.Int32, ComponentTypeHeader.Int32],
|
|
197
|
-
PORTAL_INVISIBLE: [ComponentTypeHeader.Int32, ComponentTypeHeader.Int32, ComponentTypeHeader.Int32],
|
|
198
|
-
PORTAL_WORLD: [ComponentTypeHeader.String, ComponentTypeHeader.Int32],
|
|
199
|
-
|
|
200
|
-
SWITCH_LOCAL_TOGGLE: [ComponentTypeHeader.Int32],
|
|
201
|
-
SWITCH_LOCAL_ACTIVATOR: [ComponentTypeHeader.Int32, ComponentTypeHeader.Boolean],
|
|
202
|
-
SWITCH_LOCAL_RESETTER: [ComponentTypeHeader.Boolean],
|
|
203
|
-
SWITCH_LOCAL_DOOR: [ComponentTypeHeader.Int32],
|
|
204
|
-
SWITCH_LOCAL_GATE: [ComponentTypeHeader.Int32],
|
|
205
|
-
SWITCH_GLOBAL_TOGGLE: [ComponentTypeHeader.Int32],
|
|
206
|
-
SWITCH_GLOBAL_ACTIVATOR: [ComponentTypeHeader.Int32, ComponentTypeHeader.Boolean],
|
|
207
|
-
SWITCH_GLOBAL_RESETTER: [ComponentTypeHeader.Boolean],
|
|
208
|
-
SWITCH_GLOBAL_DOOR: [ComponentTypeHeader.Int32],
|
|
209
|
-
SWITCH_GLOBAL_GATE: [ComponentTypeHeader.Int32],
|
|
210
|
-
|
|
211
|
-
HAZARD_DEATH_DOOR: [ComponentTypeHeader.Int32],
|
|
212
|
-
HAZARD_DEATH_GATE: [ComponentTypeHeader.Int32],
|
|
213
|
-
|
|
214
|
-
NOTE_DRUM: [ComponentTypeHeader.ByteArray],
|
|
215
|
-
NOTE_PIANO: [ComponentTypeHeader.ByteArray],
|
|
216
|
-
NOTE_GUITAR: [ComponentTypeHeader.ByteArray],
|
|
217
|
-
} as const;
|