@korial29/tiny-fps 0.228.1 → 0.229.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.
- package/README.md +39 -11
- package/dist/assets/room-BUfNl2LM.js +12239 -0
- package/dist/cast-opus-C6oSp1pb.js +1 -0
- package/dist/index.js +5 -5
- package/dist/local.js +1 -1
- package/dist/opus-00JxPO40.js +1 -0
- package/dist/room.js +1 -0
- package/dist/server.js +1 -12177
- package/dist/types/client/index.d.ts +6 -0
- package/dist/types/client/smoke.d.ts +6 -8
- package/dist/types/client/voice/cast-opus.d.ts +2 -2
- package/dist/types/client/voice/opus.d.ts +2 -2
- package/dist/types/room/index.d.ts +4 -0
- package/dist/types/shared/beach.d.ts +11 -0
- package/dist/types/shared/constants.d.ts +5 -0
- package/dist/types/shared/room.d.ts +2 -0
- package/dist/types/shared/types.d.ts +5 -0
- package/dist/types/shared/world.d.ts +2 -0
- package/package.json +5 -1
- package/dist/cast-opus-C8YPQ4KQ.js +0 -1
- package/dist/opus-C_4ZiPUd.js +0 -1
package/README.md
CHANGED
|
@@ -33,6 +33,7 @@ It started as a co-op shooter inspired by carlini's [Yet Another Doom Clone](htt
|
|
|
33
33
|
| `@korial29/tiny-fps` | The game client: rendering, lights and shadows, input, prediction, HUD | ~80 KB |
|
|
34
34
|
| `@korial29/tiny-fps/local` | Same-browser multiplayer, no server: the host runs in a tab | ~15.5 KB |
|
|
35
35
|
| `@korial29/tiny-fps/server` | Node WebSocket server (needs `ws`) | Node only |
|
|
36
|
+
| `@korial29/tiny-fps/room` | The authoritative `Room` alone, no `ws`: bring your own transport | Node only |
|
|
36
37
|
|
|
37
38
|
CI checks the budgets (164 KB and 40 KB) on every pull request.
|
|
38
39
|
|
|
@@ -130,11 +131,13 @@ The canvas fills its container, at any size and ratio. Give the container a size
|
|
|
130
131
|
|
|
131
132
|
Mounts the game and joins. Returns `{ on, players, destroy }`.
|
|
132
133
|
|
|
133
|
-
| Option | Type | Description
|
|
134
|
-
| -------- | ------------ |
|
|
135
|
-
| `name` | `string` | Player name shown above your head (16 characters max). A taken name gets a suffix (`Bob 2`).
|
|
136
|
-
| `url` | `string` | WebSocket URL, room in the path. Ignored when `socket` is given.
|
|
137
|
-
| `socket` | `SocketLike` | Any WebSocket-like object, e.g. `localSocket('room')`.
|
|
134
|
+
| Option | Type | Description |
|
|
135
|
+
| -------- | ------------ | ---------------------------------------------------------------------------------------------------- |
|
|
136
|
+
| `name` | `string` | Player name shown above your head (16 characters max). A taken name gets a suffix (`Bob 2`). |
|
|
137
|
+
| `url` | `string` | WebSocket URL, room in the path. Ignored when `socket` is given. |
|
|
138
|
+
| `socket` | `SocketLike` | Any WebSocket-like object, e.g. `localSocket('room')`. |
|
|
139
|
+
| `cast` | `boolean` | Opens on the character screen; the map loads once its Start is pressed. |
|
|
140
|
+
| `voices` | `boolean` | `false`: no announcer and no players' voices, and their sprites (about 190 KB) are never downloaded. |
|
|
138
141
|
|
|
139
142
|
Without WebGL2 the game stays connected and says so on screen.
|
|
140
143
|
|
|
@@ -166,17 +169,42 @@ A same-browser socket for `tinyFps`. `rules` apply to the game the tab hosts, so
|
|
|
166
169
|
|
|
167
170
|
Starts the WebSocket server, one room per URL path, and returns an async `stop()`. `rules` apply to every room.
|
|
168
171
|
|
|
172
|
+
### `Room`: `@korial29/tiny-fps/room`
|
|
173
|
+
|
|
174
|
+
The host without the WebSocket server, to run behind a transport you already have (Socket.io, a worker…). Each peer is a `Conn` (`{ send(data) }`): pass it to `connect()`, its frames to `receive()` (text as a string, binary as an `ArrayBuffer` of exactly its bytes) and call `disconnect()` when it leaves. `start()` runs the clock, `stop()` ends it. `MAPS` lists the maps, each with its `name`.
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
import { Room } from '@korial29/tiny-fps/room';
|
|
178
|
+
|
|
179
|
+
const room = new Room({ map: 'tranquility', lockMap: true });
|
|
180
|
+
room.start();
|
|
181
|
+
io.on('connection', socket => {
|
|
182
|
+
// Snapshots may be lost (the next one replaces them), the texts (join, roster) may not.
|
|
183
|
+
const conn = {
|
|
184
|
+
send: (data: string | ArrayBuffer) =>
|
|
185
|
+
typeof data === 'string' ? socket.emit('fps', data) : socket.volatile.emit('fps', data),
|
|
186
|
+
};
|
|
187
|
+
room.connect(conn);
|
|
188
|
+
socket.on('fps', data => room.receive(conn, data));
|
|
189
|
+
socket.on('disconnect', () => room.disconnect(conn));
|
|
190
|
+
});
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
On the client, a `SocketLike` that relays the same events goes into `tinyFps(el, { socket })`.
|
|
194
|
+
|
|
169
195
|
### `SocketLike`
|
|
170
196
|
|
|
171
197
|
The subset of `WebSocket` the client uses: `binaryType`, `onopen`, `onclose`, `onmessage`, `send(data)` and `close()`. A real `WebSocket` and `localSocket()` both fit, and so does a relay over a transport you already have. Text frames are JSON, and binary frames (inputs, snapshots) must arrive as an `ArrayBuffer` of exactly their bytes.
|
|
172
198
|
|
|
173
199
|
### Rules
|
|
174
200
|
|
|
175
|
-
| Rule | Default
|
|
176
|
-
| ------------ |
|
|
177
|
-
| `maxPlayers` | `16`
|
|
178
|
-
| `scoreLimit` | `3`
|
|
179
|
-
| `timeLimit` | `480`
|
|
201
|
+
| Rule | Default | Description |
|
|
202
|
+
| ------------ | ------------ | --------------------------------------------------------------------------------- |
|
|
203
|
+
| `maxPlayers` | `16` | Players in a room; the next ones are told the room is full. |
|
|
204
|
+
| `scoreLimit` | `3` | Captures that end a match at once. |
|
|
205
|
+
| `timeLimit` | `480` | Seconds a match lasts. The team with more captures wins, a level score is a draw. |
|
|
206
|
+
| `map` | `'highline'` | The map's key: `highline`, `tranquility` or `landfall`. |
|
|
207
|
+
| `lockMap` | `false` | The room plays `map` for its whole life: the host's picks are ignored. |
|
|
180
208
|
|
|
181
209
|
---
|
|
182
210
|
|
|
@@ -222,7 +250,7 @@ The game is the movement and a capture the flag on top of it, with a tackle, a g
|
|
|
222
250
|
- **The others**: drawn 100 ms in the past, interpolated between snapshots, as runners with one continuous skinned body, a face that blinks and grimaces, a combat stance, a natural gait and every parkour move (leaning well out on a wall-run, the feet on it), in their team colour, with the weapon in their hands.
|
|
223
251
|
- **The city**: the street lies far below the roofs, with roads, their markings and traffic out into the haze, and a fog that thickens toward it; parks of tall branched trees in some blocks, and a skyline of towers around the map.
|
|
224
252
|
- **Sound**: a synthesiser and a mixer that places sounds left or right by where they come from, and an airy music loop of slow pads and soft bells. Steps, jumps, the deep plasma shot, the katana's draw, swish and zap, the guns' reloads and power-up, hits, pickups and the flag events all have their sound. The sound starts with the click that locks the pointer.
|
|
225
|
-
- **Announcer**: a calm voice tells the match starting and its last minute, the flags and the captures from your team's side, two or three takedowns in quick succession, five and ten in a row, a run of plasma shots that mostly hit, and the result. Its 16 lines are generated offline by `scripts/voice.py` and loaded after the first click, apart from the game: about
|
|
253
|
+
- **Announcer**: a calm voice tells the match starting and its last minute, the flags and the captures from your team's side, two or three takedowns in quick succession, five and ten in a row, a run of plasma shots that mostly hit, and the result. Its 16 lines are generated offline by `scripts/voice.py` and loaded after the first click, apart from the game: about 41 KB in Ogg Opus at 12 kbps, or 74 KB in MP3 where the browser cannot decode Opus.
|
|
226
254
|
|
|
227
255
|
---
|
|
228
256
|
|