@hopple/sdk 0.1.0-rc.3 → 1.0.0-next.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/manifest.d.ts ADDED
@@ -0,0 +1,1011 @@
1
+ //#region ../../../../../../../tmp/hopple-sdk-types-SLrqDf/manifest/src/manifest.d.ts
2
+ /**
3
+ * The API a game is written against: `M.m`, a major and the least minor it
4
+ * needs, or `next`, the pre-releases of the next stable release.
5
+ *
6
+ * @group Manifest
7
+ * @category Important
8
+ * @pattern ^(?:(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)|next)$
9
+ * @errorMessage must be the API the game is written against, like "1.0", or "next"
10
+ */
11
+ type ApiVersion = string;
12
+ /**
13
+ * How the game wants to be held. The host decides what to do about it.
14
+ *
15
+ * @group Layout
16
+ */
17
+ type Orientation = 'portrait' | 'landscape' | 'any';
18
+ /**
19
+ * Whether the host may put its own furniture over the game's frame.
20
+ *
21
+ * The one layout question that has to be answered before the bundle runs, which
22
+ * is why it is declared here rather than asked at runtime: the host sizes the
23
+ * frame before there is a game to ask. A game that says nothing gets `reserve`,
24
+ * so a rail never lands on the buttons of something written before rails
25
+ * existed.
26
+ *
27
+ * @group Layout
28
+ */
29
+ type InsetMode =
30
+ /** The frame is the whole surface; read `sdk.layout` and keep out of the way. */
31
+ 'draw-under' |
32
+ /** The host shrinks the frame clear of its own furniture. Nothing to avoid. */
33
+ 'reserve';
34
+ /**
35
+ * What a game declares about layout. Absent means every default.
36
+ *
37
+ * @group Layout
38
+ * @category Useful
39
+ */
40
+ type LayoutDeclaration = {
41
+ insets: InsetMode;
42
+ };
43
+ /**
44
+ * What a prop may hold, as one word. The three the wire carries, and no more.
45
+ *
46
+ * @group Analytics
47
+ */
48
+ type AnalyticsType = 'string' | 'number' | 'boolean';
49
+ /**
50
+ * One event's props. Every one optional: see `AnalyticsDeclaration`.
51
+ *
52
+ * Prop names follow the grammar event names do, which `@hopple/protocol`
53
+ * enforces on the wire too; a test keeps the two in step.
54
+ *
55
+ * @group Analytics
56
+ * @maxProperties 8
57
+ * @propertyNames { pattern: '^[a-z0-9]+(?:[._-][a-z0-9]+)*$', maxLength: 24, errorMessage: 'must be a prop name of lowercase letters, digits, dots, hyphens and underscores' }
58
+ */
59
+ type AnalyticsShape = Record<string, AnalyticsType>;
60
+ /**
61
+ * The custom events a game sends, and what each one carries.
62
+ *
63
+ * **The first key here whose reader is not the host.** `layout.insets` is
64
+ * declared because a frame has to be sized before there is a game to ask;
65
+ * nothing about analytics has to be answered before the bundle runs. What earns
66
+ * this its place is cardinality: names and columns invented at runtime make a
67
+ * pipe nobody can build a table for, and the party that has to build that table
68
+ * — the publish CLI, the server, a creator dashboard — is exactly the party that
69
+ * already reads the manifest and never talks to a game.
70
+ *
71
+ * **Every prop is optional and nothing is required**, which is what keeps the
72
+ * declaration cheap enough to be worth asking for: forgetting one costs a column
73
+ * rather than the event. The additive rule carries over unchanged — add events,
74
+ * add props, never retype one — and that is the whole of what a per-event table
75
+ * needs to survive the game's next version.
76
+ *
77
+ * @group Analytics
78
+ * @category Useful
79
+ */
80
+ type AnalyticsDeclaration = {
81
+ /**
82
+ * Every event the game may send, by name.
83
+ *
84
+ * Names starting `hopple.` are the host's own records and not a game's to
85
+ * use. The grammar is the wire's too: `@hopple/protocol` enforces the same
86
+ * one, and a test keeps the two in step. At most 64 events: the wire never
87
+ * sees a declaration, so nothing enforces this at runtime and nothing has to.
88
+ *
89
+ * @maxProperties 64
90
+ * @propertyNames { pattern: '^[a-z0-9]+(?:[._-][a-z0-9]+)*$', maxLength: 48, not: { pattern: '^hopple\\.' }, errorMessage: 'must be lowercase letters, digits, dots, hyphens and underscores, and must not start with "hopple.", which the host uses' }
91
+ */
92
+ events: Record<string, AnalyticsShape>;
93
+ };
94
+ /**
95
+ * What a game expects to keep, in bytes.
96
+ *
97
+ * **The manifest's own test is whether the host must know before the bundle
98
+ * runs**, and here it must: a host that prefetches a save from a server has to
99
+ * know which games have one before there is a game to ask, and a publish
100
+ * pipeline that provisions storage has to know before a player exists.
101
+ *
102
+ * The budget the game expects, not a grant. A host answers with its own cap at
103
+ * the handshake, and a game with no key here may still call the API — it just
104
+ * gets nothing prefetched, which is the honest reading of not having said so.
105
+ *
106
+ * @group Save
107
+ * @category Useful
108
+ */
109
+ type SaveDeclaration = {
110
+ /**
111
+ * At most 1 MiB. Not the same question as what a host will take — that is
112
+ * the host's and is settled at the handshake. This is only what is worth
113
+ * writing down: a declaration in the megabytes is a game that has
114
+ * misunderstood what this is for, and finding that out at publish time is
115
+ * cheaper than at a player's.
116
+ *
117
+ * @asType integer
118
+ * @exclusiveMinimum 0
119
+ * @maximum 1048576
120
+ */
121
+ bytes: number;
122
+ };
123
+ /**
124
+ * One thing a game makes noise with, as the player is offered it.
125
+ *
126
+ * The title is the whole of it, and required: this exists to be a label on a
127
+ * fader in a host's own panel, and a fader labelled `sfx2` is a control nobody
128
+ * can use. What a channel *is* — a bus, a set of samples, one oscillator — is
129
+ * the game's business and is never described here.
130
+ *
131
+ * @group Audio
132
+ */
133
+ type AudioChannel = {
134
+ /**
135
+ * What to call it in front of a player.
136
+ *
137
+ * @category Important
138
+ * @pattern \S
139
+ * @maxLength 40
140
+ * @errorMessage must not be blank
141
+ */
142
+ title: string;
143
+ };
144
+ /**
145
+ * What this game makes noise with, so a host can offer a fader for each.
146
+ *
147
+ * **A map from the first version, even for a game with one channel.** The
148
+ * channel id travels in `audio.set`, which is frozen game-side code, and a
149
+ * single-channel key would have to *change meaning* to grow a second one — the
150
+ * one move the additive rule forbids.
151
+ *
152
+ * **The manifest's test is whether the host must know before the bundle runs**,
153
+ * and here it must twice over. The panel is drawn where the game's title is,
154
+ * which a host draws for games in a feed that nobody has opened; and the
155
+ * opening volumes ride in the handshake, so the host has to know which channels
156
+ * it is stating a volume for before there is a game to ask.
157
+ *
158
+ * **The key is required, and `null` is how a silent game says so.** Leaving it
159
+ * out would read the same as forgetting it, and a game that makes noise but
160
+ * never said so is one whose player cannot turn it down. An object with no
161
+ * channels is a game with sound and no tracks worth a fader of their own: it
162
+ * gets a master fader and a mute button and no more. What is never optional is
163
+ * obeying what the host then says: see `AudioState`.
164
+ *
165
+ * @group Audio
166
+ * @category Useful
167
+ */
168
+ type AudioDeclaration = {
169
+ /**
170
+ * The channels, by id. Optional, and may be empty: either way there is only
171
+ * the master. At most 8: a panel of faders nobody can read is not a feature.
172
+ *
173
+ * `master` is refused rather than quietly shadowed. A master fader exists
174
+ * whether or not a game has said anything, and an author who wrote it meant
175
+ * something by it; a fader that turned out to be the host's own would be a
176
+ * control that ignored half of what they wired it to. The id grammar is the
177
+ * wire's too, and a test keeps the two in step.
178
+ *
179
+ * @maxProperties 8
180
+ * @propertyNames { pattern: '^[a-z0-9]+(?:[._-][a-z0-9]+)*$', maxLength: 48, not: { const: 'master' }, errorMessage: 'must be lowercase letters, digits, dots, hyphens and underscores, and must not be "master", which every host adds itself' }
181
+ */
182
+ channels?: Record<string, AudioChannel>;
183
+ };
184
+ /**
185
+ * Which way a board sorts — the one thing about a score that cannot be guessed.
186
+ *
187
+ * `desc` is the ordinary leaderboard, where more is better. `asc` is a time, a
188
+ * stroke count, a number of moves. Nothing downstream can infer this from the
189
+ * values it holds, and a client that guessed would render a time board upside
190
+ * down, so it is required rather than defaulted.
191
+ *
192
+ * @group Score
193
+ */
194
+ type ScoreDirection = 'asc' | 'desc';
195
+ /**
196
+ * How to draw the number.
197
+ *
198
+ * A client renders a board for a game it has never run, so it cannot ask the
199
+ * game what `224310` means. `integer` is a count, `decimal` a measurement,
200
+ * `duration-ms` a time to be written as minutes and seconds. Absent is
201
+ * `integer`, which is what most boards are.
202
+ *
203
+ * @group Score
204
+ */
205
+ type ScoreFormat = 'integer' | 'decimal' | 'duration-ms';
206
+ /** @group Score */
207
+ type ScoreBoard = {
208
+ /**
209
+ * What to call it in front of a player.
210
+ *
211
+ * @category Important
212
+ * @pattern \S
213
+ * @maxLength 40
214
+ * @errorMessage must not be blank
215
+ */
216
+ title: string;
217
+ direction: ScoreDirection;
218
+ /** See `ScoreFormat`. Absent means `integer`. */
219
+ format?: ScoreFormat;
220
+ };
221
+ /**
222
+ * The boards this game keeps a score on.
223
+ *
224
+ * **A map from the first version, even for a game that wants one board.** The
225
+ * board id travels in `score.submit`, which is frozen game-side code, and a
226
+ * single-board key would have to *change meaning* to grow a second one — the
227
+ * one thing the additive rule forbids. A map costs a game with one board the
228
+ * few characters of naming it, and costs a game with four nothing at all.
229
+ *
230
+ * **Read by the host and by the server**, which is what earns it a key rather
231
+ * than a runtime call: a client draws a game's board in a sheet over a feed
232
+ * without ever having run that game, and the server has to know how a board
233
+ * sorts before it can answer a query about one.
234
+ *
235
+ * @group Score
236
+ * @category Useful
237
+ */
238
+ type ScoreDeclaration = {
239
+ /**
240
+ * The boards, by id. At least one: a `score` key with no boards is a game
241
+ * that meant to declare one and did not, and reading it as "no boards" would
242
+ * hand it a scoreboard tab with nothing behind it. The id grammar is the
243
+ * wire's too, and a test keeps the two in step.
244
+ *
245
+ * @minProperties 1
246
+ * @maxProperties 16
247
+ * @propertyNames { pattern: '^[a-z0-9]+(?:[._-][a-z0-9]+)*$', maxLength: 48, errorMessage: 'must be lowercase letters, digits, dots, hyphens and underscores' }
248
+ */
249
+ boards: Record<string, ScoreBoard>;
250
+ };
251
+ /**
252
+ * One named step on the way to a measured achievement's target.
253
+ *
254
+ * **A tier is a label, never a second achievement.** The achievement is
255
+ * unlocked at its `target` and nowhere else; a tier is what a panel calls the
256
+ * player between here and there — *Silver, 50 of 100*. Modelling each tier as
257
+ * its own id would be three rows in every board that draws them and three
258
+ * unlocks a game has to remember to send, where this is one number reported
259
+ * once and read three ways.
260
+ *
261
+ * @group Achievements
262
+ */
263
+ type AchievementTier = {
264
+ /**
265
+ * The reported value this tier is reached at, on the near side of the target.
266
+ *
267
+ * @minimum -9007199254740991
268
+ * @maximum 9007199254740991
269
+ */
270
+ at: number;
271
+ /**
272
+ * What to call the player who has reached it.
273
+ *
274
+ * @category Important
275
+ * @pattern \S
276
+ * @maxLength 40
277
+ * @errorMessage must not be blank
278
+ */
279
+ title: string;
280
+ /**
281
+ * A glyph for this tier, where it wants its own.
282
+ *
283
+ * @pattern \S
284
+ * @maxLength 8
285
+ * @errorMessage must not be blank
286
+ */
287
+ icon?: string;
288
+ };
289
+ /**
290
+ * What makes an achievement measured rather than flagged.
291
+ *
292
+ * **`direction` is the one thing that cannot be guessed**, exactly as it cannot
293
+ * be guessed for a board. `desc` — the default, and what most achievements are
294
+ * — counts up to the target: *break 100 blocks*. `asc` counts down to it:
295
+ * *finish under two minutes*, where the value kept is the player's best time
296
+ * and a smaller one beats a larger. A panel that assumed bigger-is-better would
297
+ * draw a stopwatch achievement as though every slow run were progress.
298
+ *
299
+ * **`format` is how to draw the number**, for the reason a board needs one:
300
+ * whoever renders this has never run the game and cannot ask it what `112400`
301
+ * means.
302
+ *
303
+ * Both are `ScoreDirection` and `ScoreFormat` rather than types of their own.
304
+ * "Which way is better" and "how is this number written" are the same two
305
+ * questions wherever they are asked, and a second spelling of each is two
306
+ * vocabularies to keep in step and one bug when they drift.
307
+ *
308
+ * @group Achievements
309
+ */
310
+ type AchievementProgress = {
311
+ /**
312
+ * The value that unlocks it. Reaching it is the whole of being unlocked.
313
+ *
314
+ * Bounded by `Number.MAX_SAFE_INTEGER`, for the reason `SCORE_VALUE_MAX` is:
315
+ * past there a whole number stops round-tripping through JSON and through a
316
+ * 64-bit column, and progress toward a target nobody can reproduce is
317
+ * progress nobody can draw.
318
+ *
319
+ * @minimum -9007199254740991
320
+ * @maximum 9007199254740991
321
+ */
322
+ target: number;
323
+ /** Which way is better. Absent is `desc`: more is better. */
324
+ direction?: ScoreDirection;
325
+ /** How to draw the value. Absent is `integer`. */
326
+ format?: ScoreFormat;
327
+ /**
328
+ * Named milestones on the way, ordered toward the target.
329
+ *
330
+ * @maxItems 8
331
+ */
332
+ tiers?: AchievementTier[];
333
+ };
334
+ /**
335
+ * One thing a player can be shown to have done.
336
+ *
337
+ * **Two kinds, told apart by one key.** Without `progress` this is a flag: it
338
+ * happens once, and saying so twice is the same fact twice. With `progress` it
339
+ * is measured — a count, a distance, a best time — reported as the game goes
340
+ * and unlocked when the value reaches the target.
341
+ *
342
+ * **`secret` withholds the words, never the row.** A secret achievement is
343
+ * listed while it is locked, so a player can see there is one left, with its
344
+ * title and detail held back until it is theirs. Hiding the row itself would
345
+ * make the list's length change under the player, which reads as a bug rather
346
+ * than as a surprise. It is a courtesy of the panel and not a secret kept from
347
+ * the machine: the manifest ships beside the bundle and is public, so anybody
348
+ * who wants the words already has them.
349
+ *
350
+ * @group Achievements
351
+ */
352
+ type Achievement = {
353
+ /**
354
+ * What to call it in front of a player.
355
+ *
356
+ * @category Important
357
+ * @pattern \S
358
+ * @maxLength 40
359
+ * @errorMessage must not be blank
360
+ */
361
+ title: string;
362
+ /**
363
+ * One line under the title, saying what it takes.
364
+ *
365
+ * @pattern \S
366
+ * @maxLength 120
367
+ * @errorMessage must not be blank
368
+ */
369
+ detail?: string;
370
+ /**
371
+ * A short glyph to draw beside it — an emoji, usually. Eight characters is
372
+ * enough for an emoji with a modifier on it.
373
+ *
374
+ * @pattern \S
375
+ * @maxLength 8
376
+ * @errorMessage must not be blank
377
+ */
378
+ icon?: string;
379
+ /** Whether the words are withheld until it is unlocked. See above. */
380
+ secret?: boolean;
381
+ /** Present makes this measured rather than flagged. See `AchievementProgress`. */
382
+ progress?: AchievementProgress;
383
+ };
384
+ /**
385
+ * The achievements this game keeps for a player.
386
+ *
387
+ * **A map, for the reason `score.boards` is one**: the id travels in
388
+ * `achievement.unlock`, which is frozen game-side code, so the shape has to
389
+ * hold a second entry without anything changing meaning.
390
+ *
391
+ * **Read by the host, by the client and by the server, and by none of them from
392
+ * the game.** The site draws this panel for a game sitting in the feed that has
393
+ * never been run; the server refuses an id no publisher declared. That is what
394
+ * earns a manifest key rather than a runtime call — the same test `score`
395
+ * passed.
396
+ *
397
+ * @group Achievements
398
+ * @category Useful
399
+ */
400
+ type AchievementDeclaration = {
401
+ /**
402
+ * The achievements, by id. At least one: an `achievements` key with nothing
403
+ * in it is a game that meant to declare one and did not. The id grammar is
404
+ * the wire's too, and a test keeps the two in step.
405
+ *
406
+ * @minProperties 1
407
+ * @maxProperties 128
408
+ * @propertyNames { pattern: '^[a-z0-9]+(?:[._-][a-z0-9]+)*$', maxLength: 48, errorMessage: 'must be lowercase letters, digits, dots, hyphens and underscores' }
409
+ */
410
+ list: Record<string, Achievement>;
411
+ };
412
+ /**
413
+ * A device a game can be played with, as one word.
414
+ *
415
+ * Hardware rather than API surface: `mouse` and `touch` are separate words even
416
+ * though a game reads both through one pointer, because what a *client* does
417
+ * with this is decide whether to put a game in front of somebody who has no way
418
+ * to play it.
419
+ *
420
+ * @group Input
421
+ */
422
+ type InputDevice = 'keyboard' | 'mouse' | 'touch' | 'gamepad';
423
+ /**
424
+ * One set of devices that together are enough to play.
425
+ *
426
+ * @group Input
427
+ * @minItems 1
428
+ * @maxItems 8
429
+ */
430
+ type InputDeviceSet = InputDevice[];
431
+ /**
432
+ * A name for something that can *press* an action.
433
+ *
434
+ * `key.<code>` names a physical key by `KeyboardEvent.code` — **the code and
435
+ * never the character**. `KeyA` is the key where A sits on a US keyboard and
436
+ * stays that key on AZERTY, where it types Q, so a game that binds movement to
437
+ * codes has WASD under the same four fingers everywhere. `Escape` is the host's:
438
+ * it leaves fullscreen and pointer lock, which are invisible from inside the
439
+ * frame, and a game that bound it would lose that fight quietly on every press.
440
+ *
441
+ * `pad.south` is the south of either cluster: the face button on one pad and the
442
+ * d-pad's down on another, which is what makes one binding cover both. Compass
443
+ * words for both clusters, with no `pad.dpad.down` alias beside
444
+ * `pad.left.south` — a vocabulary that can never shrink should not start out
445
+ * doubled. A thumbstick is not one of these; see `InputStick`.
446
+ *
447
+ * @group Input
448
+ * @pattern ^(?:key\.(?!Escape$)(?=.{1,48}$)[A-Za-z][A-Za-z0-9]*|pointer\.(?:primary|secondary)|mouse\.(?:left|middle|right)|touch\.tap|controls\.(?=.{1,48}$)[a-z0-9]+(?:[_-][a-z0-9]+)*|pad\.(?:north|south|east|west|start|select)|pad\.(?:left|right)\.(?:north|south|east|west|bumper|trigger))$
449
+ * @errorMessage is not a binding this SDK knows (a thumbstick is read rather than bound, and Escape is the host's key)
450
+ */
451
+ type InputBinding = string;
452
+ /**
453
+ * A name for a thumbstick — something a game reads, never binds.
454
+ *
455
+ * @group Input
456
+ * @pattern ^(?:controls\.(?=.{1,48}$)[a-z0-9]+(?:[_-][a-z0-9]+)*|pad\.stick|pad\.(?:left|right)\.stick)$
457
+ * @errorMessage must name a thumbstick, such as pad.left.stick
458
+ */
459
+ type InputStick = string;
460
+ /**
461
+ * What presses an action: at least one binding, and at most 8.
462
+ *
463
+ * @group Input
464
+ * @minItems 1
465
+ * @maxItems 8
466
+ */
467
+ type InputBindings = InputBinding[];
468
+ /**
469
+ * One thing a player does, named by the game and bound to whatever produces it.
470
+ *
471
+ * **An action is a button and never an axis.** A key, a face button on a pad, a
472
+ * pointer button and an on-screen button all press the same action, because
473
+ * from the game's side they are the same event. A thumbstick is not one of
474
+ * those and is read through its own API — folding the two together would put a
475
+ * range on every binding that mostly does not have one, and would leave a game
476
+ * unable to say whether it meant the press or the lean.
477
+ *
478
+ * **An object rather than a bare list of bindings**, from the first version,
479
+ * because two strings are wanted the moment anybody draws this: a `title` for
480
+ * the remapping screen, which shows actions to a player and cannot show
481
+ * `move.left`, and a `label` for the face of an on-screen button. Growing a
482
+ * list into an object later would change what an action's value *is*, which is
483
+ * the one move the additive rule forbids. Only the object is accepted, even for
484
+ * an action that needs neither string: one way to write an action is one way to
485
+ * read it.
486
+ *
487
+ * @group Input
488
+ */
489
+ type InputAction = {
490
+ /** What presses it. See `InputBinding` for the vocabulary. */
491
+ bind: InputBindings;
492
+ /**
493
+ * What to call it in front of a player, in a remapping screen.
494
+ *
495
+ * @pattern \S
496
+ * @maxLength 40
497
+ * @errorMessage must not be blank
498
+ */
499
+ title?: string;
500
+ /**
501
+ * What to draw on an on-screen button: a glyph, or a letter.
502
+ *
503
+ * @pattern \S
504
+ * @maxLength 8
505
+ * @errorMessage must not be blank
506
+ */
507
+ label?: string;
508
+ };
509
+ /**
510
+ * What presses a player's action on a pad or on the screen: a pad button, or
511
+ * an on-screen control. Keys and mouse buttons are a keyboard set's, in
512
+ * `PlayerInputDeclaration.keyboard`.
513
+ *
514
+ * @group Input
515
+ * @pattern ^(?:controls\.(?=.{1,48}$)[a-z0-9]+(?:[_-][a-z0-9]+)*|pad\.(?:north|south|east|west|start|select)|pad\.(?:left|right)\.(?:north|south|east|west|bumper|trigger))$
516
+ * @errorMessage must be a pad button or an on-screen control: a player's keys and mouse buttons go in input.player.keyboard
517
+ */
518
+ type PlayerBinding = string;
519
+ /**
520
+ * What presses a player's action on their part of the keyboard: a key, or a
521
+ * mouse button.
522
+ *
523
+ * @group Input
524
+ * @pattern ^(?:key\.(?!Escape$)(?=.{1,48}$)[A-Za-z][A-Za-z0-9]*|mouse\.(?:left|middle|right))$
525
+ * @errorMessage must be a key or a mouse button (and Escape is the host's key)
526
+ */
527
+ type KeyboardBinding = string;
528
+ /**
529
+ * One thing each player does: the same action for every local player, pressed
530
+ * by their own pad, their own part of the keyboard, or the on-screen controls.
531
+ *
532
+ * @group Input
533
+ */
534
+ type PlayerInputAction = {
535
+ /**
536
+ * What presses it on a pad, the same for every pad, and on the screen.
537
+ * Leave it out for an action pressed only on the keyboard.
538
+ *
539
+ * @minItems 1
540
+ * @maxItems 8
541
+ */
542
+ bind?: PlayerBinding[];
543
+ /**
544
+ * What to call it in front of a player, in a remapping screen.
545
+ *
546
+ * @pattern \S
547
+ * @maxLength 40
548
+ * @errorMessage must not be blank
549
+ */
550
+ title?: string;
551
+ /**
552
+ * What to draw on an on-screen button: a glyph, or a letter.
553
+ *
554
+ * @pattern \S
555
+ * @maxLength 8
556
+ * @errorMessage must not be blank
557
+ */
558
+ label?: string;
559
+ /**
560
+ * Whether pressing it on a pad or a part of the keyboard nobody plays with
561
+ * makes a new player, while the game is taking players. Left out on every
562
+ * action, any of them does.
563
+ */
564
+ join?: boolean;
565
+ };
566
+ /**
567
+ * One part of the keyboard one player plays with: the keys and mouse buttons
568
+ * that press each of the player actions there.
569
+ *
570
+ * @group Input
571
+ */
572
+ type KeyboardSet = {
573
+ /**
574
+ * What the players call it: *Left keys*, *Arrows*.
575
+ *
576
+ * @pattern \S
577
+ * @maxLength 40
578
+ * @errorMessage must not be blank
579
+ */
580
+ title?: string;
581
+ /**
582
+ * The keys and mouse buttons of each player action, by its id.
583
+ *
584
+ * @maxProperties 64
585
+ * @propertyNames { pattern: '^[a-z0-9]+(?:[._-][a-z0-9]+)*$', maxLength: 48, errorMessage: 'must be a player action id' }
586
+ */
587
+ bind: Record<string, KeyboardBinding[]>;
588
+ };
589
+ /**
590
+ * What each local player does, and how they share the keyboard.
591
+ *
592
+ * **One set of actions for every player.** Each local player has their own
593
+ * copy, pressed by the pad they hold, the part of the keyboard they play with,
594
+ * or the on-screen controls. A pad's buttons are the same for every pad, so any
595
+ * number of pads just works; the keyboard is split into sets, one player each,
596
+ * so the number of sets is how many can share it.
597
+ *
598
+ * @group Input
599
+ */
600
+ type PlayerInputDeclaration = {
601
+ /**
602
+ * The actions each player has, by id: never an id `actions` declares too.
603
+ *
604
+ * @maxProperties 32
605
+ * @propertyNames { pattern: '^[a-z0-9]+(?:[._-][a-z0-9]+)*$', maxLength: 48, errorMessage: 'must be lowercase letters, digits, dots, hyphens and underscores' }
606
+ */
607
+ actions: Record<string, PlayerInputAction>;
608
+ /**
609
+ * The parts of the keyboard players play with, one player each, in the
610
+ * order they are offered. A player alone hears every one of them. Left out,
611
+ * the keyboard presses no player's action.
612
+ *
613
+ * @minItems 1
614
+ * @maxItems 4
615
+ */
616
+ keyboard?: KeyboardSet[];
617
+ };
618
+ /**
619
+ * How a group of on-screen buttons is arranged.
620
+ *
621
+ * Arrangement only, with the count doing the rest, so three across and five
622
+ * down need no words of their own. **A shape nobody recognises is drawn as a
623
+ * `column`** — the same escape `Obstruction.reserved` is. Whoever renders these
624
+ * may be older than the game that declared them, and a control that fails to
625
+ * appear is a game that cannot be played at all. It is still refused at
626
+ * publish, where saying so is cheap.
627
+ *
628
+ * @group Input
629
+ */
630
+ type ControlShape = 'row' | 'column' | 'diamond' | 'cluster';
631
+ /**
632
+ * One on-screen control: a group of buttons, or a thumbstick.
633
+ *
634
+ * **A button slot names an action; a stick slot names a stick.** The asymmetry
635
+ * is the hardware's. On-screen buttons have no fixed count or position — three
636
+ * across, five down, four in a diamond — so there is no standard control to
637
+ * unify them with, and the action is the only stable name they have. Thumbsticks
638
+ * come in twos and everybody agrees which is which, so a virtual one says which
639
+ * it stands for and a game reads the physical stick and this one through one id.
640
+ *
641
+ * There is no d-pad here. A d-pad is four buttons wherever it exists — four
642
+ * entries on the wire from a real pad, four keys on a keyboard — so a layout
643
+ * that wants one declares four buttons and binds them like anything else.
644
+ *
645
+ * @group Input
646
+ * @if { properties: { type: { const: 'buttons' } }, required: ['type'] }
647
+ * @then { required: ['buttons'], properties: { as: { type: 'object', additionalProperties: { $ref: '#/definitions/InputBinding' } }, axis: { not: {}, errorMessage: 'is only for a thumbstick' } } }
648
+ * @else { properties: { as: { $ref: '#/definitions/InputStick' } } }
649
+ */
650
+ type ControlSlot = {
651
+ type: 'buttons' | 'thumbstick';
652
+ /**
653
+ * `buttons` only: the actions this control presses, in drawing order.
654
+ *
655
+ * @minItems 1
656
+ * @maxItems 8
657
+ */
658
+ buttons?: string[];
659
+ /** `buttons` only. See `ControlShape`. Absent is `column`. */
660
+ shape?: ControlShape;
661
+ /**
662
+ * What this control stands in for on a standard pad.
663
+ *
664
+ * On a thumbstick it is the stick id a game reads — `pad.left.stick` — so one
665
+ * `onStick` sees the physical stick and this one alike. Left out, the stick is
666
+ * only itself, which a game reads as `controls.<id>`. On a group of buttons it
667
+ * is a map from action to standard button, optional and rarely wanted: a game
668
+ * whose bindings already name `pad.south` needs nothing here, and this is for
669
+ * one that also wants the low-level path to see the press.
670
+ */
671
+ as?: InputStick | Record<string, InputBinding>;
672
+ /** `thumbstick` only. See `ControlAxis`. Absent, the stick moves both ways. */
673
+ axis?: ControlAxis;
674
+ };
675
+ /**
676
+ * The one direction an on-screen thumbstick moves in: `x` across, `y` up and
677
+ * down.
678
+ *
679
+ * For a game that steers along one line — a runner sliding left and right, a
680
+ * paddle — where a stick that also leans up and down is a thumb wandering off
681
+ * the line it means. The drawn stick becomes a track along that axis and always
682
+ * reports the other one as 0. **Only the drawn stick:** a real pad's stick still
683
+ * reports both, so a game reads the axis it wants from either.
684
+ *
685
+ * Whoever draws the controls may be older than the game, and draw a stick that
686
+ * moves both ways. The SDK zeroes the other axis whatever the renderer reports,
687
+ * so the game hears one axis either way.
688
+ *
689
+ * @group Input
690
+ */
691
+ type ControlAxis = 'x' | 'y';
692
+ /**
693
+ * The controls in one zone of a layout, by id.
694
+ *
695
+ * @group Input
696
+ * @maxProperties 8
697
+ * @propertyNames { pattern: '^[a-z0-9]+(?:[._-][a-z0-9]+)*$', maxLength: 48, errorMessage: 'must be a control id of lowercase letters, digits, dots, hyphens and underscores' }
698
+ */
699
+ type ControlZoneSlots = Record<string, ControlSlot>;
700
+ /**
701
+ * One named arrangement of on-screen controls.
702
+ *
703
+ * A game may declare several and switch between them — a menu wants different
704
+ * controls from play, and a driving section different ones again — which is why
705
+ * they are named rather than there being one. A zone nobody knows is a layout
706
+ * from a newer minor, which a host reads leniently, so whoever draws it simply
707
+ * has nowhere to put it.
708
+ *
709
+ * @group Input
710
+ */
711
+ type ControlLayout = {
712
+ left?: ControlZoneSlots;
713
+ right?: ControlZoneSlots;
714
+ full?: ControlZoneSlots;
715
+ };
716
+ /**
717
+ * What a game says about how it is played.
718
+ *
719
+ * **It passes the manifest's test twice.** The host must know before the bundle
720
+ * runs — whether on-screen controls apply at all, and what a remapping screen
721
+ * offers, are settled before there is a game to ask — and it is read by parties
722
+ * that never run the game: a feed deciding whether to show a keyboard-only game
723
+ * to somebody holding a phone, and a remapping screen opened from outside a run.
724
+ *
725
+ * Action, control and layout ids follow the grammar the wire does, and a test
726
+ * keeps the two in step.
727
+ *
728
+ * @group Input
729
+ * @category Useful
730
+ */
731
+ type InputDeclaration = {
732
+ /**
733
+ * The sets of hardware this game can be played with: any one set, every
734
+ * member of which must be present.
735
+ *
736
+ * A flat list of alternatives rather than a tree of `any` and `all`. Every
737
+ * real answer is a handful of alternatives, and this one renders straight into
738
+ * *needs a keyboard and a mouse* without anybody having written a solver.
739
+ *
740
+ * **The publisher's claim, taken at its word**, exactly as `orientation` is:
741
+ * nothing here checks it against the bindings. It cannot be checked. A game is
742
+ * free to read the platform directly — raw key events, an accelerometer, a
743
+ * microphone — and that is a stated allowance rather than an oversight, so
744
+ * what a game *binds* never implies what it can be played with.
745
+ *
746
+ * @minItems 1
747
+ * @maxItems 8
748
+ */
749
+ supported?: InputDeviceSet[];
750
+ /**
751
+ * The actions, by id.
752
+ *
753
+ * @maxProperties 64
754
+ * @propertyNames { pattern: '^[a-z0-9]+(?:[._-][a-z0-9]+)*$', maxLength: 48, errorMessage: 'must be lowercase letters, digits, dots, hyphens and underscores' }
755
+ */
756
+ actions?: Record<string, InputAction>;
757
+ /**
758
+ * Named arrangements of on-screen controls. See `ControlLayout`.
759
+ *
760
+ * @maxProperties 8
761
+ * @propertyNames { pattern: '^[a-z0-9]+(?:[._-][a-z0-9]+)*$', maxLength: 48, errorMessage: 'must be a layout name of lowercase letters, digits, dots, hyphens and underscores' }
762
+ */
763
+ controls?: Record<string, ControlLayout>;
764
+ /**
765
+ * What each local player does, beside `actions`, which are everybody's. See
766
+ * `PlayerInputDeclaration`.
767
+ */
768
+ player?: PlayerInputDeclaration;
769
+ };
770
+ /**
771
+ * How many people play a game on one device.
772
+ *
773
+ * Read by hosts before the game runs: a listing says *1–4 on one device*, and
774
+ * the input panel offers a row for each player.
775
+ *
776
+ * @group Input
777
+ * @category Useful
778
+ */
779
+ type PlayersDeclaration = {
780
+ /**
781
+ * The most players on one device, each with their own copy of
782
+ * `input.player`'s actions. 1 when left out.
783
+ *
784
+ * @minimum 1
785
+ * @maximum 8
786
+ * @asType integer
787
+ */
788
+ local?: number;
789
+ };
790
+ /**
791
+ * A preview's revision: a whole number from 1, the `R` of its package's
792
+ * `0.R.p`. A breaking change to the preview is a new revision.
793
+ *
794
+ * @group Manifest
795
+ * @category Useful
796
+ * @minimum 1
797
+ * @asType integer
798
+ */
799
+ type PreviewRevision = number;
800
+ /**
801
+ * The previews a game is written against, each at the revision it needs.
802
+ *
803
+ * A preview is a part of the SDK that is not stable yet: its own `0.x`
804
+ * package, versioned apart from `api`, and served only to the games that
805
+ * declare it, at the revision they declare. A change to a preview reaches the
806
+ * games written against it and nobody else.
807
+ *
808
+ * @group Manifest
809
+ * @category Useful
810
+ */
811
+ type PreviewsDeclaration = {
812
+ /**
813
+ * That this game plays over the network, in matches, at this revision of
814
+ * `@hopple/sdk-preview-network`: `sdk.match`.
815
+ *
816
+ * The permission a reviewer grants, and what lets a host offer *Play with
817
+ * friends* before the game has loaded. Nothing else about networking is
818
+ * declared: the way a match is played, and its size, are chosen by the game
819
+ * when it makes one. Absent, a game is never told about a match, and never
820
+ * reaches one.
821
+ */
822
+ network?: PreviewRevision;
823
+ };
824
+ /**
825
+ * Publishing refuses a key the manifest's API does not know; a host reading a
826
+ * published one ignores it (see `validateManifest`).
827
+ *
828
+ * @group Manifest
829
+ * @category Important
830
+ */
831
+ type GameManifest = {
832
+ /**
833
+ * The API the game is written against. The major picks what the game is
834
+ * served; the minor is the least it needs. The CLI fills it from the
835
+ * installed `@hopple/sdk` when the config leaves it out.
836
+ *
837
+ * @category Important
838
+ */
839
+ api: ApiVersion;
840
+ /**
841
+ * Stable across versions, and unique among its publisher's games: it is the
842
+ * second half of the address the game is published at, `owner/id`, and the
843
+ * name every new version is filed under. Lowercase, url-safe, and no two
844
+ * hyphens in a row, because it ends up in urls and storage keys.
845
+ *
846
+ * @category Important
847
+ * @pattern ^[a-z0-9]+(?:-[a-z0-9]+)*$
848
+ * @maxLength 64
849
+ * @errorMessage must be lowercase letters, digits and hyphens
850
+ */
851
+ id: string;
852
+ /**
853
+ * The handle of the account the game is published under: the first half of
854
+ * `owner/id`. Absent, it is whoever publishes it. Present, only that account
855
+ * and the game's collaborators may publish it.
856
+ *
857
+ * @category Useful
858
+ * @pattern ^[a-z0-9]+(?:-[a-z0-9]+)*$
859
+ * @maxLength 64
860
+ * @errorMessage must be a handle: lowercase letters, digits and hyphens
861
+ */
862
+ owner?: string;
863
+ /**
864
+ * The game's own version, `MAJOR.MINOR.PATCH`. Ours to read, never to parse for meaning.
865
+ *
866
+ * @category Important
867
+ * @pattern ^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$
868
+ * @errorMessage must look like 1.0.0
869
+ */
870
+ version: string;
871
+ /**
872
+ * @category Important
873
+ * @pattern \S
874
+ * @maxLength 60
875
+ * @errorMessage must not be blank
876
+ */
877
+ title: string;
878
+ /**
879
+ * A sentence or two about the game, shown beside its title.
880
+ *
881
+ * @category Useful
882
+ * @pattern \S
883
+ * @maxLength 500
884
+ * @errorMessage must not be blank
885
+ */
886
+ description?: string;
887
+ /**
888
+ * A picture of the game, shown wherever a link to it is pasted — a chat, a
889
+ * post, a message.
890
+ *
891
+ * The path of a PNG, JPEG or WebP file, relative to the config the manifest
892
+ * is in, and at most `COVER_MAX_BYTES`. `hopple publish` uploads it beside
893
+ * the game. 1200 × 630 is the shape every platform shows whole; without one,
894
+ * a link shows Hopple's own card.
895
+ *
896
+ * @category Useful
897
+ * @pattern ^(?!/)(?!.*\.\.)[A-Za-z0-9._/-]+\.(?:png|jpe?g|webp)$
898
+ * @maxLength 200
899
+ * @errorMessage must be the path of a .png, .jpg or .webp file beside the config, like "cover.png"
900
+ */
901
+ cover?: string;
902
+ /** @category Important */
903
+ orientation: Orientation;
904
+ /**
905
+ * How the game wants the host's furniture handled. See `InsetMode`.
906
+ *
907
+ * @category Useful
908
+ */
909
+ layout?: LayoutDeclaration;
910
+ /**
911
+ * The custom events this game sends. See `AnalyticsDeclaration`.
912
+ *
913
+ * @category Useful
914
+ */
915
+ analytics?: AnalyticsDeclaration;
916
+ /**
917
+ * That this game keeps state, and roughly how much. See `SaveDeclaration`.
918
+ *
919
+ * @category Useful
920
+ */
921
+ save?: SaveDeclaration;
922
+ /**
923
+ * The boards this game keeps a score on. See `ScoreDeclaration`.
924
+ *
925
+ * @category Useful
926
+ */
927
+ score?: ScoreDeclaration;
928
+ /**
929
+ * What a player can be shown to have done. See `AchievementDeclaration`.
930
+ *
931
+ * @category Useful
932
+ */
933
+ achievements?: AchievementDeclaration;
934
+ /**
935
+ * How this game is played, and what it draws to be played with. See `InputDeclaration`.
936
+ *
937
+ * @category Useful
938
+ */
939
+ input?: InputDeclaration;
940
+ /**
941
+ * How many play on one device. See `PlayersDeclaration`.
942
+ *
943
+ * @category Useful
944
+ */
945
+ players?: PlayersDeclaration;
946
+ /**
947
+ * What this game makes noise with, one channel at a time, or `null` for a
948
+ * game that makes none. See `AudioDeclaration`.
949
+ *
950
+ * @category Important
951
+ */
952
+ audio: AudioDeclaration | null;
953
+ /**
954
+ * The previews this game is written against, each at its revision. See
955
+ * `PreviewsDeclaration`.
956
+ *
957
+ * @category Useful
958
+ */
959
+ previews?: PreviewsDeclaration;
960
+ };
961
+ /**
962
+ * @group Manifest
963
+ * @category Useful
964
+ */
965
+ type ManifestProblem = {
966
+ /** The key at fault, or `''` when the document itself is the problem. */
967
+ field: string;
968
+ message: string;
969
+ };
970
+ /**
971
+ * @group Manifest
972
+ * @category Useful
973
+ */
974
+ type ManifestCheck = {
975
+ ok: true;
976
+ manifest: GameManifest;
977
+ } | {
978
+ ok: false;
979
+ problems: ManifestProblem[];
980
+ };
981
+ /**
982
+ * Check a parsed manifest, without throwing and without changing it.
983
+ *
984
+ * Every problem is reported, not just the first: someone fixing a manifest
985
+ * wants the list, and a validator that reveals one error per run is a validator
986
+ * people stop running. A key the manifest does not know is refused, since a
987
+ * misspelt one would otherwise mean nothing in silence; `lenient` ignores it
988
+ * instead, for reading a manifest that was published, possibly against a newer
989
+ * minor than this one. A key we *do* know, spelled wrongly, is refused either
990
+ * way: `"draw_under"` would otherwise mean `reserve` in silence, and silence
991
+ * here looks exactly like a bug in the host.
992
+ *
993
+ * @group Manifest
994
+ * @category Important
995
+ */
996
+ declare function validateManifest(value: unknown, options?: {
997
+ lenient?: boolean;
998
+ }): ManifestCheck;
999
+ /**
1000
+ * One line per problem, worded the same wherever a manifest is rejected.
1001
+ *
1002
+ * Field names are set in backticks, because plenty of them are ordinary words
1003
+ * — "entry is required" reads as a sentence about some entry, and
1004
+ * "`entry` is required" names a key.
1005
+ *
1006
+ * @group Manifest
1007
+ * @category Useful
1008
+ */
1009
+ declare function describeProblems(problems: readonly ManifestProblem[]): string;
1010
+ //#endregion
1011
+ export { type ManifestCheck, type ManifestProblem, describeProblems, validateManifest };