dredless 0.2.0 → 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/README.md +65 -48
- package/dist/browser/dredless.global.js +12047 -0
- package/dist/browser/dredless.global.js.map +7 -0
- package/docs/API_REFERENCE.md +2481 -2481
- package/docs/BROWSER_API.md +98 -98
- package/docs/NODE_API.md +359 -359
- package/package.json +40 -35
- package/src/browser-global.js +3 -0
- package/src/browser.d.ts +212 -212
- package/src/browser.js +133 -133
- package/src/client/core.js +1202 -1202
- package/src/client/domains/index.js +1818 -1818
- package/src/client/index.d.ts +2 -2
- package/src/client/index.js +1 -1
- package/src/compression/lz4.d.ts +1 -1
- package/src/compression/lz4.js +112 -112
- package/src/constants.js +74 -74
- package/src/crypto/chacha-native.d.ts +9 -9
- package/src/crypto/chacha-native.js +48 -48
- package/src/crypto/chacha.d.ts +25 -25
- package/src/crypto/chacha.js +274 -274
- package/src/events.js +39 -39
- package/src/index.d.ts +2277 -2277
- package/src/index.js +125 -125
- package/src/network/browser-session.js +291 -291
- package/src/network/connection.d.ts +1 -1
- package/src/network/connection.js +31 -31
- package/src/network/cookies.js +85 -85
- package/src/network/http.js +34 -34
- package/src/network/index.d.ts +4 -4
- package/src/network/index.js +4 -4
- package/src/network/servers.d.ts +7 -7
- package/src/network/servers.js +133 -133
- package/src/network/session.d.ts +7 -7
- package/src/network/session.js +320 -320
- package/src/network/ships.d.ts +12 -12
- package/src/network/ships.js +73 -73
- package/src/node.d.ts +2 -2
- package/src/node.js +8 -8
- package/src/protocol/codec/binary.d.ts +3 -3
- package/src/protocol/codec/binary.js +52 -52
- package/src/protocol/codec/msgpack.d.ts +3 -3
- package/src/protocol/codec/msgpack.js +555 -555
- package/src/protocol/inbound/frame.d.ts +1 -1
- package/src/protocol/inbound/frame.js +8 -8
- package/src/protocol/inbound/world-payload.d.ts +3 -3
- package/src/protocol/inbound/world-payload.js +21 -21
- package/src/protocol/index.d.ts +11 -11
- package/src/protocol/index.js +19 -19
- package/src/protocol/outbound/blueprint.d.ts +22 -22
- package/src/protocol/outbound/blueprint.js +36 -36
- package/src/protocol/outbound/commands.d.ts +3 -3
- package/src/protocol/outbound/commands.js +149 -149
- package/src/protocol/outbound/comms.d.ts +28 -28
- package/src/protocol/outbound/comms.js +40 -40
- package/src/protocol/outbound/inventory.d.ts +64 -64
- package/src/protocol/outbound/inventory.js +147 -147
- package/src/protocol/outbound/ship-management.d.ts +84 -84
- package/src/protocol/outbound/ship-management.js +221 -221
- package/src/protocol/outbound/sign.d.ts +18 -18
- package/src/protocol/outbound/sign.js +45 -45
- package/src/protocol/outbound/ui-config.d.ts +157 -157
- package/src/protocol/outbound/ui-config.js +578 -578
- package/src/runtime.js +36 -36
- package/src/state/generator-maze.d.ts +32 -32
- package/src/state/generator-maze.js +370 -370
- package/src/state/index.d.ts +3 -3
- package/src/state/index.js +3 -3
- package/src/state/items.js +20 -20
- package/src/state/model/decoder.js +1554 -1554
- package/src/state/model/index.d.ts +33 -33
- package/src/state/model/index.js +2 -2
- package/src/state/model/loader-config.js +1020 -1020
- package/src/state/model/reader.js +69 -69
- package/src/state/model/state.js +1257 -1257
- package/src/state/overworld.js +72 -72
- package/src/state/tilesets.js +53 -53
- package/src/state/world/index.d.ts +29 -29
- package/src/state/world/index.js +180 -180
- package/src/state/world/state.js +297 -297
package/src/network/ships.js
CHANGED
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
import {DEFAULT_BASE_URL} from "../constants.js";
|
|
2
|
-
import {asNumber} from "../runtime.js";
|
|
3
|
-
import {HttpClient} from "./http.js";
|
|
4
|
-
|
|
5
|
-
export function createShipSpec(name = "", color = "") {
|
|
6
|
-
return {type: "new", name: String(name ?? ""), color: String(color ?? "")};
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function createInviteShipSpec(code) {
|
|
10
|
-
return {type: "invite", code: String(code ?? "")};
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function shipRef(ship) {
|
|
14
|
-
if (ship == null) return null;
|
|
15
|
-
if (typeof ship !== "object") return {type: "join_or_load", id: ship};
|
|
16
|
-
if (ship.type) return ship;
|
|
17
|
-
const id = ship.id ?? ship.hexCode ?? ship.hex_code;
|
|
18
|
-
if (id != null) return {type: "join_or_load", id};
|
|
19
|
-
return ship;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export const normalizeShipSpec = shipRef;
|
|
23
|
-
|
|
24
|
-
export function normalizeShip(raw, key = null) {
|
|
25
|
-
if (!raw || typeof raw !== "object") return null;
|
|
26
|
-
const id = Number(raw.id ?? key);
|
|
27
|
-
return {
|
|
28
|
-
id: Number.isFinite(id) ? id : null,
|
|
29
|
-
hexCode: raw.hex_code || raw.hexCode || raw.id || key || null,
|
|
30
|
-
name: raw.team_name || "Unknown Ship",
|
|
31
|
-
iconUrl: raw.icon_path || null,
|
|
32
|
-
playerCount: asNumber(raw.player_count, 0),
|
|
33
|
-
owned: Boolean(raw.owned),
|
|
34
|
-
saved: Boolean(raw.saved),
|
|
35
|
-
color: raw.color || "",
|
|
36
|
-
time: asNumber(raw.time, null)
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function extractShips(data) {
|
|
41
|
-
if (Array.isArray(data)) return data.map((ship, index) => [ship?.id || String(index), ship]);
|
|
42
|
-
if (Array.isArray(data?.ships)) return data.ships.map((ship, index) => [ship?.id || String(index), ship]);
|
|
43
|
-
if (data?.ships && typeof data.ships === "object") return Object.entries(data.ships);
|
|
44
|
-
return [];
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export async function fetchShips(session, server, baseUrl = session?.baseUrl || DEFAULT_BASE_URL) {
|
|
48
|
-
const data = await fetchShipList(session, server, baseUrl);
|
|
49
|
-
return Array.isArray(data) ? data : Array.isArray(data?.ships) ? data.ships : [];
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export async function fetchShipList(session, server, baseUrl = session?.baseUrl || DEFAULT_BASE_URL) {
|
|
53
|
-
if (!session) throw new Error("fetchShipList requires a session");
|
|
54
|
-
const serverId = Number(server && typeof server === "object" ? server.index ?? server.id : server ?? session.geoServer ?? 0);
|
|
55
|
-
const data = await new HttpClient({baseUrl, session}).json(`shiplist?server=${serverId}`, {
|
|
56
|
-
headers: {accept: "application/json"}
|
|
57
|
-
});
|
|
58
|
-
const ships = normalizeShipList(data);
|
|
59
|
-
if (Array.isArray(data)) return {ships};
|
|
60
|
-
if (data && typeof data === "object") {
|
|
61
|
-
return {
|
|
62
|
-
playerCount: asNumber(data.player_count, 0),
|
|
63
|
-
maxPlayerCount: asNumber(data.max_player_count, 0),
|
|
64
|
-
isMuted: Boolean(data.is_muted),
|
|
65
|
-
ships
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
return {ships};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function normalizeShipList(data) {
|
|
72
|
-
return extractShips(data).map(([key, raw]) => normalizeShip(raw, key)).filter(Boolean);
|
|
73
|
-
}
|
|
1
|
+
import {DEFAULT_BASE_URL} from "../constants.js";
|
|
2
|
+
import {asNumber} from "../runtime.js";
|
|
3
|
+
import {HttpClient} from "./http.js";
|
|
4
|
+
|
|
5
|
+
export function createShipSpec(name = "", color = "") {
|
|
6
|
+
return {type: "new", name: String(name ?? ""), color: String(color ?? "")};
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function createInviteShipSpec(code) {
|
|
10
|
+
return {type: "invite", code: String(code ?? "")};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function shipRef(ship) {
|
|
14
|
+
if (ship == null) return null;
|
|
15
|
+
if (typeof ship !== "object") return {type: "join_or_load", id: ship};
|
|
16
|
+
if (ship.type) return ship;
|
|
17
|
+
const id = ship.id ?? ship.hexCode ?? ship.hex_code;
|
|
18
|
+
if (id != null) return {type: "join_or_load", id};
|
|
19
|
+
return ship;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const normalizeShipSpec = shipRef;
|
|
23
|
+
|
|
24
|
+
export function normalizeShip(raw, key = null) {
|
|
25
|
+
if (!raw || typeof raw !== "object") return null;
|
|
26
|
+
const id = Number(raw.id ?? key);
|
|
27
|
+
return {
|
|
28
|
+
id: Number.isFinite(id) ? id : null,
|
|
29
|
+
hexCode: raw.hex_code || raw.hexCode || raw.id || key || null,
|
|
30
|
+
name: raw.team_name || "Unknown Ship",
|
|
31
|
+
iconUrl: raw.icon_path || null,
|
|
32
|
+
playerCount: asNumber(raw.player_count, 0),
|
|
33
|
+
owned: Boolean(raw.owned),
|
|
34
|
+
saved: Boolean(raw.saved),
|
|
35
|
+
color: raw.color || "",
|
|
36
|
+
time: asNumber(raw.time, null)
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function extractShips(data) {
|
|
41
|
+
if (Array.isArray(data)) return data.map((ship, index) => [ship?.id || String(index), ship]);
|
|
42
|
+
if (Array.isArray(data?.ships)) return data.ships.map((ship, index) => [ship?.id || String(index), ship]);
|
|
43
|
+
if (data?.ships && typeof data.ships === "object") return Object.entries(data.ships);
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function fetchShips(session, server, baseUrl = session?.baseUrl || DEFAULT_BASE_URL) {
|
|
48
|
+
const data = await fetchShipList(session, server, baseUrl);
|
|
49
|
+
return Array.isArray(data) ? data : Array.isArray(data?.ships) ? data.ships : [];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export async function fetchShipList(session, server, baseUrl = session?.baseUrl || DEFAULT_BASE_URL) {
|
|
53
|
+
if (!session) throw new Error("fetchShipList requires a session");
|
|
54
|
+
const serverId = Number(server && typeof server === "object" ? server.index ?? server.id : server ?? session.geoServer ?? 0);
|
|
55
|
+
const data = await new HttpClient({baseUrl, session}).json(`shiplist?server=${serverId}`, {
|
|
56
|
+
headers: {accept: "application/json"}
|
|
57
|
+
});
|
|
58
|
+
const ships = normalizeShipList(data);
|
|
59
|
+
if (Array.isArray(data)) return {ships};
|
|
60
|
+
if (data && typeof data === "object") {
|
|
61
|
+
return {
|
|
62
|
+
playerCount: asNumber(data.player_count, 0),
|
|
63
|
+
maxPlayerCount: asNumber(data.max_player_count, 0),
|
|
64
|
+
isMuted: Boolean(data.is_muted),
|
|
65
|
+
ships
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return {ships};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function normalizeShipList(data) {
|
|
72
|
+
return extractShips(data).map(([key, raw]) => normalizeShip(raw, key)).filter(Boolean);
|
|
73
|
+
}
|
package/src/node.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./index.js";
|
|
2
|
-
export {default} from "./index.js";
|
|
1
|
+
export * from "./index.js";
|
|
2
|
+
export {default} from "./index.js";
|
package/src/node.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {enableNativeChaCha20} from "./crypto/chacha-native.js";
|
|
2
|
-
|
|
3
|
-
// Node resolves the package root through this entry, so opting into the native
|
|
4
|
-
// ChaCha20 backend here keeps `node:crypto` out of the browser build.
|
|
5
|
-
enableNativeChaCha20();
|
|
6
|
-
|
|
7
|
-
export * from "./index.js";
|
|
8
|
-
export {default} from "./index.js";
|
|
1
|
+
import {enableNativeChaCha20} from "./crypto/chacha-native.js";
|
|
2
|
+
|
|
3
|
+
// Node resolves the package root through this entry, so opting into the native
|
|
4
|
+
// ChaCha20 backend here keeps `node:crypto` out of the browser build.
|
|
5
|
+
enableNativeChaCha20();
|
|
6
|
+
|
|
7
|
+
export * from "./index.js";
|
|
8
|
+
export {default} from "./index.js";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export function toUint8Array(value: Uint8Array | ArrayBuffer | number[]): Uint8Array;
|
|
2
|
-
export function concatBytes(...values: Array<Uint8Array | ArrayBuffer | number[]>): Uint8Array;
|
|
3
|
-
export function valuesEqual(a: unknown, b: unknown): boolean;
|
|
1
|
+
export function toUint8Array(value: Uint8Array | ArrayBuffer | number[]): Uint8Array;
|
|
2
|
+
export function concatBytes(...values: Array<Uint8Array | ArrayBuffer | number[]>): Uint8Array;
|
|
3
|
+
export function valuesEqual(a: unknown, b: unknown): boolean;
|
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
import {encoder} from "../../constants.js";
|
|
2
|
-
|
|
3
|
-
function objectTag(value) {
|
|
4
|
-
return Object.prototype.toString.call(value);
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
function isArrayBufferLike(value) {
|
|
8
|
-
const tag = objectTag(value);
|
|
9
|
-
return tag === "[object ArrayBuffer]" || tag === "[object SharedArrayBuffer]";
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function toUint8Array(value) {
|
|
13
|
-
if (value instanceof Uint8Array) return value;
|
|
14
|
-
if (isArrayBufferLike(value)) return new Uint8Array(value);
|
|
15
|
-
if (ArrayBuffer.isView(value)) {
|
|
16
|
-
return new Uint8Array(value.buffer.slice(value.byteOffset, value.byteOffset + value.byteLength));
|
|
17
|
-
}
|
|
18
|
-
if (Array.isArray(value)) return Uint8Array.from(value);
|
|
19
|
-
if (typeof value === "string") return encoder.encode(value);
|
|
20
|
-
throw new Error(`Unsupported binary value: ${objectTag(value)}`);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function concatBytes(parts) {
|
|
24
|
-
const total = parts.reduce((sum, part) => sum + part.length, 0);
|
|
25
|
-
const out = new Uint8Array(total);
|
|
26
|
-
let offset = 0;
|
|
27
|
-
for (const part of parts) {
|
|
28
|
-
out.set(part, offset);
|
|
29
|
-
offset += part.length;
|
|
30
|
-
}
|
|
31
|
-
return out;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function valuesEqual(a, b) {
|
|
35
|
-
if (a === b) return true;
|
|
36
|
-
if (a == null || b == null) return a == null && b == null;
|
|
37
|
-
if (typeof a !== "object" || typeof b !== "object") return false;
|
|
38
|
-
const aKeys = Object.keys(a);
|
|
39
|
-
const bKeys = Object.keys(b);
|
|
40
|
-
if (aKeys.length !== bKeys.length) return false;
|
|
41
|
-
for (const key of aKeys) {
|
|
42
|
-
if (!valuesEqual(a[key], b[key])) return false;
|
|
43
|
-
}
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
export {
|
|
49
|
-
toUint8Array,
|
|
50
|
-
concatBytes,
|
|
51
|
-
valuesEqual
|
|
52
|
-
};
|
|
1
|
+
import {encoder} from "../../constants.js";
|
|
2
|
+
|
|
3
|
+
function objectTag(value) {
|
|
4
|
+
return Object.prototype.toString.call(value);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function isArrayBufferLike(value) {
|
|
8
|
+
const tag = objectTag(value);
|
|
9
|
+
return tag === "[object ArrayBuffer]" || tag === "[object SharedArrayBuffer]";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function toUint8Array(value) {
|
|
13
|
+
if (value instanceof Uint8Array) return value;
|
|
14
|
+
if (isArrayBufferLike(value)) return new Uint8Array(value);
|
|
15
|
+
if (ArrayBuffer.isView(value)) {
|
|
16
|
+
return new Uint8Array(value.buffer.slice(value.byteOffset, value.byteOffset + value.byteLength));
|
|
17
|
+
}
|
|
18
|
+
if (Array.isArray(value)) return Uint8Array.from(value);
|
|
19
|
+
if (typeof value === "string") return encoder.encode(value);
|
|
20
|
+
throw new Error(`Unsupported binary value: ${objectTag(value)}`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function concatBytes(parts) {
|
|
24
|
+
const total = parts.reduce((sum, part) => sum + part.length, 0);
|
|
25
|
+
const out = new Uint8Array(total);
|
|
26
|
+
let offset = 0;
|
|
27
|
+
for (const part of parts) {
|
|
28
|
+
out.set(part, offset);
|
|
29
|
+
offset += part.length;
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function valuesEqual(a, b) {
|
|
35
|
+
if (a === b) return true;
|
|
36
|
+
if (a == null || b == null) return a == null && b == null;
|
|
37
|
+
if (typeof a !== "object" || typeof b !== "object") return false;
|
|
38
|
+
const aKeys = Object.keys(a);
|
|
39
|
+
const bKeys = Object.keys(b);
|
|
40
|
+
if (aKeys.length !== bKeys.length) return false;
|
|
41
|
+
for (const key of aKeys) {
|
|
42
|
+
if (!valuesEqual(a[key], b[key])) return false;
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
export {
|
|
49
|
+
toUint8Array,
|
|
50
|
+
concatBytes,
|
|
51
|
+
valuesEqual
|
|
52
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export function decodeMsgpack(bytes: Uint8Array | ArrayBuffer | number[]): unknown;
|
|
2
|
-
|
|
3
|
-
export function encodeMsgpack(value: unknown): Uint8Array;
|
|
1
|
+
export function decodeMsgpack(bytes: Uint8Array | ArrayBuffer | number[]): unknown;
|
|
2
|
+
|
|
3
|
+
export function encodeMsgpack(value: unknown): Uint8Array;
|