dredless 0.7.0 → 1.0.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.
Files changed (40) hide show
  1. package/README.md +22 -58
  2. package/dist/browser/dredless.global.js +794 -98
  3. package/dist/browser/dredless.global.js.map +4 -4
  4. package/docs/ACCOUNT.md +146 -0
  5. package/docs/API_REFERENCE.md +63 -2563
  6. package/docs/BROWSER_API.md +151 -70
  7. package/docs/CLIENT.md +183 -0
  8. package/docs/EVENTS.md +136 -0
  9. package/docs/GETTING_STARTED.md +135 -0
  10. package/docs/MACHINES.md +351 -0
  11. package/docs/MANAGEMENT.md +285 -0
  12. package/docs/NODE_API.md +120 -318
  13. package/docs/PLAYER_INVENTORY.md +235 -0
  14. package/docs/PROTOCOL.md +227 -0
  15. package/docs/README.md +44 -0
  16. package/docs/TROUBLESHOOTING.md +91 -0
  17. package/docs/WORLD_STATE.md +183 -0
  18. package/package.json +1 -2
  19. package/src/browser.d.ts +31 -1
  20. package/src/browser.js +10 -0
  21. package/src/client/core.js +302 -15
  22. package/src/client/domains/index.js +57 -7
  23. package/src/client/index.d.ts +1 -1
  24. package/src/index.d.ts +299 -13
  25. package/src/index.js +10 -0
  26. package/src/network/account.js +182 -0
  27. package/src/network/disconnect.d.ts +2 -0
  28. package/src/network/disconnect.js +53 -0
  29. package/src/network/index.d.ts +1 -0
  30. package/src/network/index.js +1 -0
  31. package/src/network/invites.d.ts +0 -3
  32. package/src/network/invites.js +3 -40
  33. package/src/network/session.d.ts +2 -0
  34. package/src/network/session.js +21 -0
  35. package/src/protocol/outbound/ship-management.d.ts +66 -1
  36. package/src/protocol/outbound/ship-management.js +83 -0
  37. package/src/state/model/decoder.js +70 -10
  38. package/src/state/model/index.d.ts +4 -0
  39. package/src/state/model/state.js +22 -7
  40. package/src/state/world/index.js +27 -1
package/README.md CHANGED
@@ -1,79 +1,43 @@
1
1
  # dredless
2
2
 
3
- A headless pure Javascript implementation (with type annotations) of `drednot.io`'s client protocol.
3
+ A headless pure Javascript (with type annotations) implementation of [drednot.io](https://drednot.io)'s client protocol.
4
4
 
5
5
  ## Install
6
6
 
7
- ### Node
8
7
  ```sh
9
8
  npm install dredless
10
9
  ```
11
10
 
12
- ### Browser
13
- Use a bundler, or load the browser bundle directly from a CDN:
11
+ Node examples use ES modules (`.mjs`) and a runtime with built-in `fetch`. Browser code runs with the site's browser cookies; see [browser setup](docs/BROWSER_API.md) for supported contexts.
14
12
 
15
- ```html
16
- <script src="https://cdn.jsdelivr.net/npm/dredless/dist/browser/dredless.global.js"></script>
17
- <script>
18
- const session = await Dredless.createAnonSession();
19
- </script>
20
- ```
21
-
22
- ## Quick Start
13
+ ## First request
23
14
 
24
- ### Node (multi-session) usage:
15
+ Save this as `ships.mjs`, then run `node ships.mjs`:
25
16
 
26
17
  ```js
27
- import Dredless, {EquipmentSlot, SignDisplayMode} from "dredless/node";
18
+ import Dredless from "dredless/node";
28
19
 
20
+ const session = await Dredless.createAnonSession(process.env.DREDNOT_ANON_KEY);
29
21
  const servers = await Dredless.fetchServers();
30
- const client = await Dredless.startNewShip(servers[0], "bot", "#de9797");
31
-
32
- client.player.move({ x: 1, y: 0 });
33
- client.inventory.slot(0).equip(EquipmentSlot.Feet);
34
- client.player.placeBlueprint({ x: 28, y: 18, width: 3, height: 3, source: "DSA:..." }, { invSlot: 2 });
35
-
36
- const ship = client.currentShip();
37
- const loader = ship?.machines.loaders()[0];
38
- loader?.configure({ cycle: 5, stack: 12 });
39
-
40
- const door = ship?.machines.doors()[0];
41
- if (door) await door.setRank("crew");
42
- const spawn = ship?.machines.spawnPoints()[0];
43
- if (spawn) await spawn.setRank("captain");
44
-
45
- // Other context-menu actions can be selected by their displayed text.
46
- const cannon = ship?.machines.cannons()[0];
47
- if (cannon) await client.tips.choose(cannon, "Unload Cannon");
48
-
49
- if (door) {
50
- console.log((await door.openTips()).options);
51
- await client.tips.close();
52
- }
22
+ const server = servers[0];
23
+ if (!server) throw new Error("No servers found");
53
24
 
54
- const sign = ship?.machines.signs()[0];
55
- sign?.open();
56
- sign?.setText("Dock here", SignDisplayMode.WhenNear);
57
-
58
- client.on("inventory", () => console.log(client.inventory.hotbarSlots().map((slot) => slot.snapshot())));
59
- client.on("model", ({ world }) => console.log(world.model.transforms()));
25
+ const ships = await session.fetchShips(server);
26
+ console.log(ships.map(({name, hexCode, playerCount}) => ({name, hexCode, playerCount})));
60
27
  ```
61
28
 
62
- ### Browser (ambient-session) usage:
63
-
64
- ```js
65
- import Dredless from "dredless/browser";
66
-
67
- await Dredless.createAnonSession();
68
- const servers = await Dredless.fetchServers();
69
- const ships = await Dredless.fetchShips(servers[0]);
70
- const client = await Dredless.startShip(servers[0], ships[0]);
29
+ This reads the ship list without opening a game connection. Supplying `DREDNOT_ANON_KEY` reuses an anonymous identity; omitting it creates one.
30
+ [Session setup](docs/NODE_API.md#authentication-and-reuse) explains how to reuse anonymous or registered accounts.
71
31
 
72
- // . . . client object can be used the same as in Node
73
- ```
32
+ ## Documentation
74
33
 
75
- ## API Docs
34
+ Start with the [documentation index](docs/README.md).
76
35
 
77
- - [Node top-level API](docs/NODE_API.md): explicit session/token/start helpers. Use this if you are running in a Node environment.
78
- - [Browser top-level API](docs/BROWSER_API.md): ambient browser-session helpers. Use this if you are running in a browser environment.
79
- - [Shared API reference](docs/API_REFERENCE.md): client, world, entity, machine, inventory, management, and protocol APIs. Used by both runtime environments.
36
+ | Task | Guide |
37
+ |-------------------------------------------|-------------------------------------------------------|
38
+ | Connect and read a live ship | [Getting started](docs/GETTING_STARTED.md) |
39
+ | Authenticate in Node | [Node sessions](docs/NODE_API.md) |
40
+ | Use browser cookies or an existing socket | [Browser setup](docs/BROWSER_API.md) |
41
+ | Find a method or type | [API reference](docs/API_REFERENCE.md) |
42
+ | Understand callbacks and completion | [Lifecycle](docs/CLIENT.md), [events](docs/EVENTS.md) |
43
+ | Diagnose missing state or failed actions | [Troubleshooting](docs/TROUBLESHOOTING.md) |