dredless 0.7.0 → 1.0.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 +22 -57
- package/dist/browser/dredless.global.js +794 -98
- package/dist/browser/dredless.global.js.map +4 -4
- package/docs/ACCOUNT.md +146 -0
- package/docs/API_REFERENCE.md +63 -2563
- package/docs/BROWSER_API.md +151 -70
- package/docs/CLIENT.md +183 -0
- package/docs/EVENTS.md +136 -0
- package/docs/GETTING_STARTED.md +135 -0
- package/docs/MACHINES.md +351 -0
- package/docs/MANAGEMENT.md +285 -0
- package/docs/NODE_API.md +120 -318
- package/docs/PLAYER_INVENTORY.md +235 -0
- package/docs/PROTOCOL.md +227 -0
- package/docs/README.md +44 -0
- package/docs/TROUBLESHOOTING.md +91 -0
- package/docs/WORLD_STATE.md +183 -0
- package/package.json +1 -2
- package/src/browser.d.ts +31 -1
- package/src/browser.js +10 -0
- package/src/client/core.js +302 -15
- package/src/client/domains/index.js +57 -7
- package/src/client/index.d.ts +1 -1
- package/src/index.d.ts +299 -13
- package/src/index.js +10 -0
- package/src/network/account.js +182 -0
- package/src/network/disconnect.d.ts +2 -0
- package/src/network/disconnect.js +53 -0
- package/src/network/index.d.ts +1 -0
- package/src/network/index.js +1 -0
- package/src/network/invites.d.ts +0 -3
- package/src/network/invites.js +3 -40
- package/src/network/session.d.ts +2 -0
- package/src/network/session.js +21 -0
- package/src/protocol/outbound/ship-management.d.ts +66 -1
- package/src/protocol/outbound/ship-management.js +83 -0
- package/src/state/model/decoder.js +70 -10
- package/src/state/model/index.d.ts +4 -0
- package/src/state/model/state.js +22 -7
- package/src/state/world/index.js +27 -1
package/README.md
CHANGED
|
@@ -1,79 +1,44 @@
|
|
|
1
1
|
# dredless
|
|
2
2
|
|
|
3
|
-
A headless
|
|
3
|
+
A headless JavaScript client for [drednot.io](https://drednot.io). Use it to join ships, read world state, send player input, configure machines, and manage ships and accounts.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
|
-
### Node
|
|
8
7
|
```sh
|
|
9
8
|
npm install dredless
|
|
10
9
|
```
|
|
11
10
|
|
|
12
|
-
|
|
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
|
-
|
|
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
|
-
|
|
15
|
+
Save this as `ships.mjs`, then run `node ships.mjs`:
|
|
25
16
|
|
|
26
17
|
```js
|
|
27
|
-
import Dredless
|
|
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
|
|
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");
|
|
22
|
+
const server = servers[0];
|
|
23
|
+
if (!server) throw new Error("No servers found");
|
|
48
24
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
await client.tips.close();
|
|
52
|
-
}
|
|
53
|
-
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
```js
|
|
65
|
-
import Dredless from "dredless/browser";
|
|
29
|
+
This reads the ship list without opening a game connection. Supplying `DREDNOT_ANON_KEY` reuses an anonymous identity; omitting it creates one. [Session setup](docs/NODE_API.md#authentication-and-reuse) explains how to reuse anonymous or registered accounts.
|
|
66
30
|
|
|
67
|
-
|
|
68
|
-
const servers = await Dredless.fetchServers();
|
|
69
|
-
const ships = await Dredless.fetchShips(servers[0]);
|
|
70
|
-
const client = await Dredless.startShip(servers[0], ships[0]);
|
|
31
|
+
## Documentation
|
|
71
32
|
|
|
72
|
-
|
|
73
|
-
```
|
|
33
|
+
Start with the [documentation index](docs/README.md).
|
|
74
34
|
|
|
75
|
-
|
|
35
|
+
| Task | Guide |
|
|
36
|
+
| --- | --- |
|
|
37
|
+
| Connect and read a live ship | [Getting started](docs/GETTING_STARTED.md) |
|
|
38
|
+
| Authenticate in Node | [Node sessions](docs/NODE_API.md) |
|
|
39
|
+
| Use browser cookies or an existing socket | [Browser setup](docs/BROWSER_API.md) |
|
|
40
|
+
| Find a method or type | [API reference](docs/API_REFERENCE.md) |
|
|
41
|
+
| Understand callbacks and completion | [Lifecycle](docs/CLIENT.md), [events](docs/EVENTS.md) |
|
|
42
|
+
| Diagnose missing state or failed actions | [Troubleshooting](docs/TROUBLESHOOTING.md) |
|
|
76
43
|
|
|
77
|
-
|
|
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.
|
|
44
|
+
Docs describe this checkout. A published npm version or CDN bundle can have fewer methods; use documentation from the corresponding release when working with an older version.
|