dredless 0.2.1 → 0.3.1

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.
@@ -2117,6 +2117,23 @@ interface InventoryDragCommand {
2117
2117
 
2118
2118
  `normalizeInventoryEvent()` returns the normalized `InventoryState` shape documented under `client.inventory`.
2119
2119
 
2120
+ ### Chat helpers
2121
+
2122
+ Module: `dredless/protocol/chat` or root.
2123
+
2124
+ ```ts
2125
+ function buildChatMessage(message?: string): ChatMessage;
2126
+ ```
2127
+
2128
+ Ship chat uses protocol message type 2. It is separate from comms-station
2129
+ messages, which use type 3. The game handles ship chat through the same
2130
+ chat-command path used by its chat commands, so client.sendChatMessage() can
2131
+ send executable chat commands as well as ordinary chat text. For example:
2132
+
2133
+ ```js
2134
+ client.sendChatMessage("/help");
2135
+ ```
2136
+
2120
2137
  ### Comms helpers
2121
2138
 
2122
2139
  Module: `dredless/protocol/comms` or root.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dredless",
3
- "version": "0.2.1",
3
+ "version": "0.3.1",
4
4
  "description": "A fully-featured and from-scratch headless drednot.io client implementation written in pure js.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/certainhuman/dredless#readme",
@@ -20,6 +20,8 @@
20
20
  "type": "module",
21
21
  "main": "src/index.js",
22
22
  "types": "./src/index.d.ts",
23
+ "unpkg": "./dist/browser/dredless.global.js",
24
+ "jsdelivr": "./dist/browser/dredless.global.js",
23
25
  "exports": {
24
26
  ".": {
25
27
  "types": "./src/index.d.ts",
@@ -155,19 +157,22 @@
155
157
  "files": [
156
158
  "src",
157
159
  "docs",
158
- "README.md"
160
+ "README.md",
161
+ "dist"
159
162
  ],
160
163
  "publishConfig": {
161
164
  "access": "public"
162
165
  },
163
166
  "scripts": {
167
+ "build": "node scripts/build-browser.js",
164
168
  "check": "node scripts/check-syntax.js",
165
169
  "test": "node --test \"test/*.test.js\"",
166
170
  "pack:check": "npm pack --dry-run",
167
- "prepublishOnly": "npm run check && npm test",
171
+ "prepublishOnly": "npm run check && npm test && npm run build",
168
172
  "update:item-schema": "node scripts/update-item-schema.js"
169
173
  },
170
174
  "devDependencies": {
171
- "dsa-shipshape": "^0.1.2"
175
+ "dsa-shipshape": "^0.1.2",
176
+ "esbuild": "^0.28.2"
172
177
  }
173
178
  }
@@ -0,0 +1,3 @@
1
+ import DredlessBrowser from "./browser.js";
2
+
3
+ globalThis.Dredless = DredlessBrowser;
@@ -7,6 +7,7 @@ import {Connection} from "../network/connection.js";
7
7
  import {itemEquipmentSlotFromId} from "../state/items.js";
8
8
  import {WorldStore} from "../state/world/index.js";
9
9
  import {buildBlueprintPlacementMessage} from "../protocol/outbound/blueprint.js";
10
+ import {buildChatMessage} from "../protocol/outbound/chat.js";
10
11
  import {buildCommsMessage, normalizeCommsEvent} from "../protocol/outbound/comms.js";
11
12
  import {buildSignedCommandPacket} from "../protocol/outbound/commands.js";
12
13
  import {buildInventoryDragCommand, normalizeEquipmentSlot, normalizeInventoryEvent} from "../protocol/outbound/inventory.js";
@@ -286,6 +287,10 @@ export class DredlessClient extends EventBus {
286
287
  return this.sendMessage({type: 5, cmd, args});
287
288
  }
288
289
 
290
+ sendChatMessage(message = "") {
291
+ return this.sendMessage(buildChatMessage(message));
292
+ }
293
+
289
294
  sendCommsMessage(message = "") {
290
295
  return this.sendMessage(buildCommsMessage(message));
291
296
  }
package/src/index.d.ts CHANGED
@@ -132,6 +132,11 @@ export interface BlueprintPlacement {
132
132
  source: string;
133
133
  }
134
134
 
135
+ export interface ChatMessage {
136
+ type: 2;
137
+ msg: string;
138
+ }
139
+
135
140
  export interface BlueprintPlacementMessage {
136
141
  type: 9;
137
142
  x: number;
@@ -463,6 +468,8 @@ export class DredlessClient {
463
468
  close(code?: number, reason?: string): this;
464
469
 
465
470
  disconnect(code?: number, reason?: string): this;
471
+ sendChatMessage(message?: string): this;
472
+ sendCommsMessage(message?: string): this;
466
473
 
467
474
  currentShip(): ShipDomain | null;
468
475
 
@@ -2108,6 +2115,8 @@ export function decodeMsgpack(bytes: Uint8Array | ArrayBuffer | number[]): unkno
2108
2115
 
2109
2116
  export function encodeMsgpack(value: unknown): Uint8Array;
2110
2117
 
2118
+ export function buildChatMessage(message?: string): ChatMessage;
2119
+
2111
2120
  export function buildCommsMessage(message?: string): CommsMessage;
2112
2121
 
2113
2122
  export function normalizeCommsEvent(event: unknown): CommsEvent;
package/src/index.js CHANGED
@@ -5,6 +5,7 @@ export {WorldStore, WorldState} from "./state/world/index.js";
5
5
  export {FabricatorType, ModelState, decodeModelData} from "./state/model/index.js";
6
6
  export {generateGeneratorMaze, solveGeneratorMazeSeed, maybeSolveGeneratorMazeSeed} from "./state/generator-maze.js";
7
7
  export {buildBlueprintPlacementMessage} from "./protocol/outbound/blueprint.js";
8
+ export {buildChatMessage} from "./protocol/outbound/chat.js";
8
9
  export {decodeMsgpack, encodeMsgpack} from "./protocol/codec/msgpack.js";
9
10
  export {
10
11
  buildCommsMessage,
@@ -3,6 +3,7 @@ export * from "./codec/binary.js";
3
3
  export * from "./inbound/frame.js";
4
4
  export * from "./inbound/world-payload.js";
5
5
  export * from "./outbound/blueprint.js";
6
+ export * from "./outbound/chat.js";
6
7
  export * from "./outbound/comms.js";
7
8
  export * from "./outbound/commands.js";
8
9
  export * from "./outbound/inventory.js";
@@ -3,6 +3,7 @@ export {toUint8Array, concatBytes, valuesEqual} from "./codec/binary.js";
3
3
  export {decodeIncomingFrame} from "./inbound/frame.js";
4
4
  export {decodeWorldPayload, decodeModelPayload, decompressWorldChunk} from "./inbound/world-payload.js";
5
5
  export {buildBlueprintPlacementMessage} from "./outbound/blueprint.js";
6
+ export {buildChatMessage} from "./outbound/chat.js";
6
7
  export {buildCommsMessage, flattenRichText, normalizeCommsEvent} from "./outbound/comms.js";
7
8
  export {buildSignedCommandPacket} from "./outbound/commands.js";
8
9
  export {
@@ -0,0 +1,8 @@
1
+ export interface ChatMessage {
2
+ type: 2;
3
+ msg: string;
4
+ }
5
+
6
+ export function buildChatMessage(message?: string): ChatMessage;
7
+
8
+ export const CHAT_MESSAGE_TYPE: 2;
@@ -0,0 +1,13 @@
1
+ const CHAT_MESSAGE_TYPE = 2;
2
+
3
+ function buildChatMessage(message = "") {
4
+ return {
5
+ type: CHAT_MESSAGE_TYPE,
6
+ msg: String(message)
7
+ };
8
+ }
9
+
10
+ export {
11
+ CHAT_MESSAGE_TYPE,
12
+ buildChatMessage
13
+ };