@modlock/modlock 0.1.85 → 0.1.87

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/package.json CHANGED
@@ -7,11 +7,11 @@
7
7
  "license": "MIT",
8
8
  "name": "@modlock/modlock",
9
9
  "optionalDependencies": {
10
- "@modlock/darwin-arm64": "0.1.85",
11
- "@modlock/darwin-x64": "0.1.85",
12
- "@modlock/linux-arm64": "0.1.85",
13
- "@modlock/linux-x64": "0.1.85",
14
- "@modlock/win32-x64": "0.1.85"
10
+ "@modlock/darwin-arm64": "0.1.87",
11
+ "@modlock/darwin-x64": "0.1.87",
12
+ "@modlock/linux-arm64": "0.1.87",
13
+ "@modlock/linux-x64": "0.1.87",
14
+ "@modlock/win32-x64": "0.1.87"
15
15
  },
16
16
  "repository": {
17
17
  "type": "git",
@@ -20,5 +20,5 @@
20
20
  "sideEffects": false,
21
21
  "type": "module",
22
22
  "types": "index.d.ts",
23
- "version": "0.1.85"
23
+ "version": "0.1.87"
24
24
  }
package/persist.d.ts ADDED
@@ -0,0 +1,81 @@
1
+ import { type Player } from './host.gen.js';
2
+ /** PersistValue is one field's value: a number, a string or a tags field's members. */
3
+ export type PersistValue = number | string | readonly string[];
4
+ /** PersistRecord is one player's record: each field written so far, by name. */
5
+ export type PersistRecord = Readonly<Record<string, PersistValue>>;
6
+ /**
7
+ * PersistRead is what persist.get knows of a record: loading until the host
8
+ * answers, then loaded, or unavailable with why, such as a host that keeps
9
+ * no records.
10
+ */
11
+ export type PersistRead = {
12
+ readonly state: 'loading';
13
+ } | {
14
+ readonly state: 'loaded';
15
+ readonly record: PersistRecord;
16
+ } | {
17
+ readonly state: 'unavailable';
18
+ readonly error: string;
19
+ };
20
+ /**
21
+ * PersistChange is one change to one field: add to a count or number, max
22
+ * or min a number, set a count, number or string, insert or remove a tag.
23
+ */
24
+ export type PersistChange = {
25
+ readonly add: number;
26
+ } | {
27
+ readonly max: number;
28
+ } | {
29
+ readonly min: number;
30
+ } | {
31
+ readonly set: number | string;
32
+ } | {
33
+ readonly insert: string;
34
+ } | {
35
+ readonly remove: string;
36
+ };
37
+ /** PersistChanges names the changes of one update by field, one or several each. */
38
+ export type PersistChanges = Readonly<Record<string, PersistChange | readonly PersistChange[]>>;
39
+ /** PersistOptions describe one update. */
40
+ export interface PersistOptions {
41
+ /**
42
+ * key identifies the change, such as a round, so a resent update counts
43
+ * once. An update that adds needs one.
44
+ */
45
+ key?: string;
46
+ /** record selects the record; leave it unset, as hosts keep one record of each type for now. */
47
+ record?: string;
48
+ }
49
+ /**
50
+ * PersistDone ends one update: with the record after it, and whether its key
51
+ * made it a repeat the host left out, or with the error that refused it.
52
+ */
53
+ export type PersistDone = (record: PersistRecord | undefined, error?: string, repeated?: boolean) => void;
54
+ export declare const persist: {
55
+ /**
56
+ * get returns player's record of type, a record type the manifest
57
+ * declares. The first get starts the read and answers loading; a later
58
+ * get answers what the host sent. A record never written loads empty.
59
+ */
60
+ get(player: Player, type: string): PersistRead;
61
+ /**
62
+ * getMany starts reading the record of type for each of players, up to
63
+ * 16, in one call, such as everyone in a lobby at join. persist.get then
64
+ * answers each; a Player kept after its player left answers unavailable.
65
+ */
66
+ getMany(players: readonly Player[], type: string): void;
67
+ /**
68
+ * update changes player's record of type by changes, which the host
69
+ * applies all or none. With a key, an update the host already took is left
70
+ * out, so resending after a lost answer counts once. An update with an add
71
+ * and no key is refused without being sent, since a resend would count it
72
+ * twice. An update the host answers as taking too long may still have been
73
+ * kept: send it again with the same key, and do not act as if nothing was
74
+ * written. persist.get answers the changed record once the host has
75
+ * answered, and done runs then. An update for a Player kept after its
76
+ * player left is refused without being sent.
77
+ */
78
+ update(player: Player, type: string, changes: PersistChanges, options?: PersistOptions, done?: PersistDone): void;
79
+ /** refresh reads player's record of type again, such as after unavailable. */
80
+ refresh(player: Player, type: string): void;
81
+ };
@@ -0,0 +1,17 @@
1
+ import { type ServiceFailure, type ServiceRepliedEvent } from './host.gen.js';
2
+ /**
3
+ * ServiceDone ends one callServiceLater: with the reply, or without one and
4
+ * with the error and the failure that says why.
5
+ */
6
+ export type ServiceDone = (reply: Uint8Array | undefined, error?: string, failure?: ServiceFailure) => void;
7
+ /**
8
+ * callServiceLater calls method of a service the host provides and returns at
9
+ * once; done runs in a later frame with the answer, or with an error when
10
+ * the service refused, the call waited past timeoutMilliseconds or nobody
11
+ * provides the service. Zero waits the host's longest, 30 seconds. done runs
12
+ * once while the mod runs; calls still waiting when the mod stops end with
13
+ * it.
14
+ */
15
+ export declare function callServiceLater(service: string, method: string, payload: Uint8Array, done: ServiceDone, timeoutMilliseconds?: number): void;
16
+ /** endServiceCall ends the started call event names, once. */
17
+ export declare function endServiceCall(event: ServiceRepliedEvent): void;
@@ -0,0 +1,36 @@
1
+ /** stragglerConnectSeconds is how long a human may take to finish joining by default. */
2
+ export declare const stragglerConnectSeconds = 120;
3
+ /** StragglersOptions configures Stragglers. */
4
+ export interface StragglersOptions {
5
+ /**
6
+ * connectSeconds is how long a human may stay connecting before the server
7
+ * kicks them, stragglerConnectSeconds by default. Zero or less never kicks.
8
+ */
9
+ connectSeconds?: number;
10
+ /**
11
+ * heroes lays down the heroes no player holds, such as a disconnected
12
+ * player's, as Strays does. It is true by default.
13
+ */
14
+ heroes?: boolean;
15
+ }
16
+ /**
17
+ * Stragglers kicks players stuck joining and lays down heroes left without a
18
+ * player. A mod keeps one and calls sweep each frame with the game time; it
19
+ * looks once a second.
20
+ */
21
+ export declare class Stragglers {
22
+ private readonly connectSeconds;
23
+ private readonly strays;
24
+ /** joining maps each connecting human's slot to its generation and when it was first seen. */
25
+ private joining;
26
+ /** kicked holds the generation each slot had when this kicked it. */
27
+ private readonly kicked;
28
+ private sweptAt;
29
+ constructor(options?: StragglersOptions);
30
+ /**
31
+ * sweep kicks each human connecting for longer than connectSeconds, once
32
+ * per connection, and lays down heroes no player holds, at most once a
33
+ * second.
34
+ */
35
+ sweep(now: number): void;
36
+ }
package/ui.d.ts CHANGED
@@ -213,6 +213,7 @@ export interface Props {
213
213
  readonly sound?: string;
214
214
  readonly disabled?: boolean;
215
215
  readonly onPress?: (player: Player) => void;
216
+ readonly onAction?: LayoutPressHandler;
216
217
  readonly enter?: Style;
217
218
  readonly exit?: Style;
218
219
  readonly cycle?: Cycle;
@@ -373,16 +374,23 @@ export interface ButtonProps extends ElementProps {
373
374
  disabled?: boolean;
374
375
  onPress?: (player: Player) => void;
375
376
  }
377
+ /**
378
+ * LayoutPressHandler hears a press a layout's script sent: the player the
379
+ * server says sent it, its action and its JSON payload, undefined for none.
380
+ */
381
+ export type LayoutPressHandler = (player: Player, action: string, payload: unknown) => void;
376
382
  /**
377
383
  * LayoutProps load a layout from the mod's content addon: src is its path
378
384
  * there, such as 'shop.xml', and data is the JSON value its script reads with
379
- * Modlock.data.
385
+ * Modlock.data. onAction hears each press its script sends with
386
+ * Modlock.press.
380
387
  */
381
388
  export interface LayoutProps {
382
389
  class?: string;
383
390
  style?: Style;
384
391
  src: string;
385
392
  data?: unknown;
393
+ onAction?: LayoutPressHandler;
386
394
  }
387
395
  /** JSX types the elements a mod's JSX may use. */
388
396
  export declare namespace JSX {
@@ -518,8 +526,12 @@ export declare function toast(player: Player, text: string, seconds?: number): b
518
526
  export declare function uiSound(player: Player, sound: string, options?: {
519
527
  readonly seconds?: number;
520
528
  }): boolean;
521
- /** press runs the handler of the button the player pressed. */
522
- export declare function press(player: Player, node: string): void;
529
+ /**
530
+ * press runs the handler of the button the player pressed, or, for a press
531
+ * with an action, the handler of the layout whose script sent it, with the
532
+ * payload's JSON, undefined for none or for text JSON cannot read.
533
+ */
534
+ export declare function press(player: Player, node: string, action?: string, payload?: string): void;
523
535
  /**
524
536
  * change runs the handler of the input the player changed, with its value as
525
537
  * the host checked it.