@modlock/modlock 0.1.71 → 0.1.73

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.71",
11
- "@modlock/darwin-x64": "0.1.71",
12
- "@modlock/linux-arm64": "0.1.71",
13
- "@modlock/linux-x64": "0.1.71",
14
- "@modlock/win32-x64": "0.1.71"
10
+ "@modlock/darwin-arm64": "0.1.73",
11
+ "@modlock/darwin-x64": "0.1.73",
12
+ "@modlock/linux-arm64": "0.1.73",
13
+ "@modlock/linux-x64": "0.1.73",
14
+ "@modlock/win32-x64": "0.1.73"
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.71"
23
+ "version": "0.1.73"
24
24
  }
package/rotation.d.ts ADDED
@@ -0,0 +1,76 @@
1
+ /** startingRating is the rating a player starts the session at. */
2
+ export declare const startingRating = 1000;
3
+ /** ratingStep is how far one even match moves each side's rating, by default. */
4
+ export declare const ratingStep = 32;
5
+ /** Standing is one player's record for the session. */
6
+ export interface Standing {
7
+ /** played counts the matches the player was seated for. */
8
+ played: number;
9
+ rating: number;
10
+ wins: number;
11
+ losses: number;
12
+ /** streak counts the matches won in a row, zero after a loss. */
13
+ streak: number;
14
+ }
15
+ /**
16
+ * Standings keeps a Standing for each Steam ID that joined this session. A
17
+ * mod that keeps more per player, such as matches played as each hero,
18
+ * passes extra to add those fields to each new standing.
19
+ */
20
+ export declare class Standings<Extra extends object = object> {
21
+ private readonly extra;
22
+ private readonly bySteamId;
23
+ constructor(extra?: () => Extra);
24
+ /**
25
+ * join is steamId's standing, made at the starting rating on their first
26
+ * join. Its matches played rise to the fewest anyone present has played,
27
+ * so joining late or rejoining never puts a player ahead of the line.
28
+ */
29
+ join(steamId: bigint, present: readonly Standing[]): Standing & Extra;
30
+ /** get is steamId's standing, or undefined before they join. */
31
+ get(steamId: bigint): (Standing & Extra) | undefined;
32
+ }
33
+ /**
34
+ * fewestPlayed is the fewest matches any of standings has played, zero with
35
+ * none.
36
+ */
37
+ export declare function fewestPlayed(standings: readonly Standing[]): number;
38
+ /**
39
+ * nextMatch picks two sides of size players from the line: the 2 * size who
40
+ * have played the fewest matches, the earlier in line first among equals,
41
+ * dealt by rating in a snake (first, second, second, first, ...) so the sum
42
+ * of ratings stays close. One a side is the two in rating order; two a side
43
+ * is the best with the worst against the middle two. It returns undefined
44
+ * while too few wait.
45
+ */
46
+ export declare function nextMatch<T>(line: readonly T[], size: number, standing: (player: T) => Standing): [T[], T[]] | undefined;
47
+ /**
48
+ * afterMatch is the line once a match ends: everyone who did not fight
49
+ * first, then the fighters, each part in line order.
50
+ */
51
+ export declare function afterMatch<T>(line: readonly T[], fought: readonly T[]): T[];
52
+ /**
53
+ * ratingChange is how far each winner's rating rises, and each loser's
54
+ * falls, when a side rated winners beats a side rated losers: the Elo step,
55
+ * larger for an upset.
56
+ */
57
+ export declare function ratingChange(winners: number, losers: number, step?: number): number;
58
+ /**
59
+ * settle records a finished match: each side's ratings move by the change
60
+ * between the sides' average ratings, and the wins, losses and streaks
61
+ * count it. It returns the rating change, zero with an empty side.
62
+ */
63
+ export declare function settle(winners: readonly Standing[], losers: readonly Standing[], step?: number): number;
64
+ /**
65
+ * leastUsed is the option to give a player next so each gets an even share:
66
+ * the index of the smallest of counts, or prefer when it ties for smallest.
67
+ * Counting each player's matches as each hero and seating leastUsed gives
68
+ * everyone every hero about equally.
69
+ */
70
+ export declare function leastUsed(counts: readonly number[], prefer?: number): number;
71
+ /**
72
+ * leaderboard is the rows a viewer sees: players by wins and then rating,
73
+ * the first rows of them, with viewer kept on the last row when they would
74
+ * fall off the end.
75
+ */
76
+ export declare function leaderboard<T>(players: readonly T[], standing: (player: T) => Standing, rows: number, viewer?: T): T[];
package/scores.d.ts ADDED
@@ -0,0 +1,72 @@
1
+ import { type Player } from './host.gen.js';
2
+ /** BoardWindow is a span of time a board keeps standings for, in UTC; a week starts Monday. */
3
+ export type BoardWindow = 'allTime' | 'day' | 'week';
4
+ /** ScoreOptions describe where a score ranks and the run it came from. */
5
+ export interface ScoreOptions {
6
+ /** partition names a value for each of the board's partitions. */
7
+ partition?: Record<string, string>;
8
+ /** tiebreak ranks equal values, lower first, such as fewer deaths. */
9
+ tiebreak?: number;
10
+ /** key identifies the run, so a resent score counts once. */
11
+ key?: string;
12
+ /** earnedAt is when the score was earned, in Unix milliseconds; the host's clock by default. */
13
+ earnedAt?: number;
14
+ /** evidence names what shows the run, such as a recording. */
15
+ evidence?: string;
16
+ }
17
+ /** MatchPlace is one player's finishing place in a match, 1 for the winner. */
18
+ export interface MatchPlace {
19
+ player: Player;
20
+ place: number;
21
+ /** value is the player's score in the match, for a board that keeps one. */
22
+ value?: number;
23
+ }
24
+ /** BoardRead selects a page of a board. */
25
+ export interface BoardRead {
26
+ /** partition names a value for each of the board's partitions. */
27
+ partition?: Record<string, string>;
28
+ /** window is one of the board's windows; all time by default. */
29
+ window?: BoardWindow;
30
+ /** offset skips that many rows from the top. */
31
+ offset?: number;
32
+ /** limit bounds the rows; ten by default. */
33
+ limit?: number;
34
+ /** player asks for this player's own row too. */
35
+ player?: Player;
36
+ }
37
+ /** BoardRow is one player's place on a board. */
38
+ export interface BoardRow {
39
+ rank: number;
40
+ steamId: bigint;
41
+ name: string;
42
+ value: number;
43
+ tiebreak: number;
44
+ count: number;
45
+ }
46
+ /** BoardPage is a page of a board. */
47
+ export interface BoardPage {
48
+ /** rows are the standings in rank order. */
49
+ rows: BoardRow[];
50
+ /** player is the asked player's row, when they hold a standing. */
51
+ player?: BoardRow;
52
+ /** loading is set until the host has read the board; read again on a later frame. */
53
+ loading: boolean;
54
+ }
55
+ /**
56
+ * reportScore reports one score for player to a board the manifest declares.
57
+ * It reports whether the host took it; a host without the scores service
58
+ * takes none, and the mod logs the score instead.
59
+ */
60
+ export declare function reportScore(player: Player, board: string, value: number, options?: ScoreOptions): boolean;
61
+ /**
62
+ * reportMatch reports one match's places to a rating or match board the
63
+ * manifest declares. Players who tie, such as one team's members, share a
64
+ * place. It reports whether the host took it, as reportScore does.
65
+ */
66
+ export declare function reportMatch(board: string, places: readonly MatchPlace[], options?: Omit<ScoreOptions, 'tiebreak'>): boolean;
67
+ /**
68
+ * readBoard reads a page of a board the manifest declares, as the host last
69
+ * read it, or undefined when the host serves no scores. A page the host has
70
+ * not read yet comes back loading.
71
+ */
72
+ export declare function readBoard(board: string, read?: BoardRead): BoardPage | undefined;
package/scriptc.d.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import './index.js';
2
2
  /**
3
- * event answers the Call the host holds, size bytes long. call hands the
4
- * host an encoded Call and returns the size of its Reply; read copies the
5
- * bytes the host holds, the Call first and then each Reply, into its
6
- * argument.
3
+ * event answers the Call the host holds, size bytes long. Each Call binds the
4
+ * host again, as the QuickJS entry does, so a transport bound during one
5
+ * event lasts only until the next.
7
6
  */
8
- export declare function event(size: number, call: (data: Uint8Array) => number, read: (data: Uint8Array) => void): Uint8Array;
7
+ export declare function event(size: number): Uint8Array;
package/strays.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ /** strayGraceSeconds is how long a hero pawn belongs to no player before it is laid down. */
2
+ export declare const strayGraceSeconds = 3;
3
+ /**
4
+ * Strays finds and lays down stray hero pawns. A mod that swaps heroes keeps
5
+ * one and calls sweep each frame with the game time; it looks once a second.
6
+ */
7
+ export declare class Strays {
8
+ /** since maps each stray pawn to when it was first seen with no player. */
9
+ private since;
10
+ private sweptAt;
11
+ /**
12
+ * sweep lays down each hero pawn that has belonged to no player for
13
+ * strayGraceSeconds, at most once a second. The game sets a dead pawn's
14
+ * respawn when it dies, so the hold repeats on each sweep.
15
+ */
16
+ sweep(now: number): void;
17
+ }