@modlock/modlock 0.0.0-stage → 0.1.64

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/format.d.ts ADDED
@@ -0,0 +1,29 @@
1
+ /**
2
+ * clock writes seconds as minutes and seconds, such as 4:07, rounding up so a
3
+ * countdown reads 0:00 only once it has run out. Negative time reads 0:00.
4
+ */
5
+ export declare function clock(seconds: number): string;
6
+ /**
7
+ * stopwatch writes seconds with hundredths, such as 1:04.37, rounding down
8
+ * so a run's time never reads faster than it was. Negative time reads 0:00.00.
9
+ */
10
+ export declare function stopwatch(seconds: number): string;
11
+ /**
12
+ * percent writes part of whole as a whole percentage from 0% to 100%, such
13
+ * as 42%, or a dash while whole is not positive. A fraction is percent(f, 1).
14
+ */
15
+ export declare function percent(part: number, whole: number): string;
16
+ /** grouped writes a number rounded to a whole with comma thousands, such as 4,210. */
17
+ export declare function grouped(value: number): string;
18
+ /** ordinal writes a place, such as 1st, 2nd, 11th or 23rd. */
19
+ export declare function ordinal(place: number): string;
20
+ /**
21
+ * count writes a number of things, in the plural unless one, such as 1 kill
22
+ * or 3 kills. plural defaults to thing with an s.
23
+ */
24
+ export declare function count(number: number, thing: string, plural?: string): string;
25
+ /**
26
+ * clip shortens text to at most width characters, at a word break where one
27
+ * falls in the cut, and marks the cut with an ellipsis.
28
+ */
29
+ export declare function clip(text: string, width: number): string;
@@ -0,0 +1,34 @@
1
+ /** FrameClock times the frames of one mod. */
2
+ declare class FrameClock {
3
+ /** frames holds the milliseconds each frame of the current minute took. */
4
+ private readonly frames;
5
+ private readonly costs;
6
+ /** laps holds the current frame's systems and milliseconds. */
7
+ private laps;
8
+ /** slowest holds the laps of the minute's slowest frame. */
9
+ private slowest;
10
+ /** slowestMs is the slowest frame's milliseconds, below any frame when none ran. */
11
+ private slowestMs;
12
+ private start;
13
+ private mark;
14
+ /** reportAt is the tick that ends the current minute. */
15
+ private reportAt;
16
+ /** begin starts timing a frame. */
17
+ begin(): void;
18
+ /** elapsed is the milliseconds since the frame began. */
19
+ get elapsed(): number;
20
+ /** lap charges the time since the previous lap, or the frame's start, to system. */
21
+ lap(system: string): void;
22
+ /**
23
+ * end finishes the frame and, once a minute of ticks passed, logs the
24
+ * minute's median and slowest frame with the systems that cost the most:
25
+ * each one's mean and slowest milliseconds a frame, and the slowest frame's
26
+ * costliest laps, to the server log.
27
+ * The minute ends on the first frame at or past its last tick, since the
28
+ * host skips a slow mod's frames and may skip that tick.
29
+ */
30
+ end(tick: bigint): void;
31
+ }
32
+ /** frameClock is the mod's one frame clock. */
33
+ export declare const frameClock: FrameClock;
34
+ export {};
package/globals.d.ts ADDED
@@ -0,0 +1,69 @@
1
+ // The globals every Modlock JavaScript runtime gives a mod, beyond the
2
+ // standard ECMAScript library. A mod reads them through these declarations
3
+ // alone: scriptc lowers a global only when the name resolves to its own
4
+ // declaration, so a mod that declares one itself shadows it.
5
+
6
+ /** Console writes lines to the server log under the mod's name. */
7
+ interface Console {
8
+ /** log writes its arguments, separated by spaces, as one line. */
9
+ log(...parts: unknown[]): void
10
+ /** info writes as log does. */
11
+ info(...parts: unknown[]): void
12
+ /** warn writes as log does. */
13
+ warn(...parts: unknown[]): void
14
+ /** error writes as log does. */
15
+ error(...parts: unknown[]): void
16
+ /** debug writes as log does. */
17
+ debug(...parts: unknown[]): void
18
+ }
19
+
20
+ /** console writes to the server log. */
21
+ declare var console: Console
22
+
23
+ /** Performance reads a monotonic clock. */
24
+ interface Performance {
25
+ /** now returns the milliseconds since the mod started, with a fraction. */
26
+ now(): number
27
+ }
28
+
29
+ /** performance is the mod's clock for timing its own work. */
30
+ declare var performance: Performance
31
+
32
+ // TextEncoder and TextDecoder are interfaces with constructor variables, as
33
+ // in the standard library, rather than classes: a mod whose source graph
34
+ // reaches two copies of this file merges them instead of failing on a
35
+ // duplicate identifier.
36
+
37
+ /** TextEncoder encodes strings as UTF-8. */
38
+ interface TextEncoder {
39
+ /** encoding is always "utf-8". */
40
+ readonly encoding: 'utf-8'
41
+ /** encode returns text's UTF-8 bytes. */
42
+ encode(text?: string): Uint8Array
43
+ }
44
+
45
+ /** TextEncoder constructs an encoder. */
46
+ declare var TextEncoder: {
47
+ prototype: TextEncoder
48
+ new (): TextEncoder
49
+ }
50
+
51
+ /** TextDecoder decodes UTF-8 bytes. */
52
+ interface TextDecoder {
53
+ /** encoding is always "utf-8". */
54
+ readonly encoding: 'utf-8'
55
+ /** decode returns the text in bytes. */
56
+ decode(bytes?: ArrayBuffer | ArrayBufferView): string
57
+ }
58
+
59
+ /** TextDecoder constructs a decoder. */
60
+ declare var TextDecoder: {
61
+ prototype: TextDecoder
62
+ new (): TextDecoder
63
+ }
64
+
65
+ /**
66
+ * A style sheet in the mod's content/styles/ directory. Importing one, as
67
+ * import './content/styles/hud.css', adds it to every interface the mod shows.
68
+ */
69
+ declare module '*.css' {}
package/ground.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ import { type Vector } from './host.gen.js';
2
+ /** GroundOptions shape the trace ground runs; each one has a default. */
3
+ export interface GroundOptions {
4
+ /** above is how far over the point the trace starts, 64 units by default. */
5
+ readonly above?: number;
6
+ /** below is how far under the point the trace ends, 1024 units by default. */
7
+ readonly below?: number;
8
+ /** layers is what counts as floor: solid and player clip by default. */
9
+ readonly layers?: bigint;
10
+ }
11
+ /**
12
+ * ground returns the floor under point, searched from just above it. It
13
+ * returns undefined when no floor answers in reach, when the trace starts
14
+ * inside a wall, and before the world's collision is ready.
15
+ */
16
+ export declare function ground(point: Vector, { above, below, layers, }?: GroundOptions): Vector | undefined;
package/heroes.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ /** Titled is something players pick by name: the game's name and the one players read. */
2
+ export interface Titled {
3
+ readonly name: string;
4
+ readonly title: string;
5
+ }
6
+ /** Hero is one released hero: its game name, such as 'hero_atlas', its title and its fixed id. */
7
+ export interface Hero extends Titled {
8
+ readonly id: number;
9
+ /** portrait is the hero's small stock portrait, as an image's src. */
10
+ readonly portrait: string;
11
+ }
12
+ /** heroes are the released heroes, by title. */
13
+ export declare const heroes: readonly Hero[];
14
+ /** findHero matches what a player typed to a hero, as findTitled does. */
15
+ export declare function findHero(typed: string): Hero | undefined;
16
+ /**
17
+ * findTitled matches what a player typed, such as 'geist', 'Lady Geist' or
18
+ * 'hero_ghost', to an entry of list: an exact name first, then the first
19
+ * title that starts with or contains it.
20
+ */
21
+ export declare function findTitled<T extends Titled>(list: readonly T[], typed: string): T | undefined;
package/hook.d.ts ADDED
@@ -0,0 +1,55 @@
1
+ /** hookAbility is the designer name of Bebop's hook. */
2
+ export declare const hookAbility = "citadel_ability_hook";
3
+ /** hookUpgrades unlocks the hook with all three upgrades. */
4
+ export declare const hookUpgrades = 15;
5
+ /** HookAbility is the part of the host's Ability that Hook reads. */
6
+ export interface HookAbility {
7
+ readonly name: string;
8
+ readonly entity: number;
9
+ readonly upgrades: number;
10
+ readonly cooldownStart: number;
11
+ readonly cooldownEnd: number;
12
+ }
13
+ /** HookPlayer is the part of the host's Player that Hook moves. */
14
+ export interface HookPlayer {
15
+ abilities(): readonly HookAbility[];
16
+ setAbility(options: {
17
+ ability: string;
18
+ upgrades?: number;
19
+ cooldownEnd?: number;
20
+ }): boolean;
21
+ refreshAbility(ability: string): boolean;
22
+ }
23
+ /** ReadHandle is the host's readField, which Hook calls for the hook's victim. */
24
+ export type ReadHandle = (entity: number, className: string, field: string, type: 'handle') => unknown;
25
+ /**
26
+ * HookRead is what the hook did this frame: the hero it holds, if any, and
27
+ * whether a new throw began since the last frame Hook reported one.
28
+ */
29
+ export interface HookRead {
30
+ readonly victim: number | undefined;
31
+ readonly thrown: boolean;
32
+ }
33
+ /**
34
+ * Hook watches one thrower's hook. Its cooldown lasts cooldownSeconds from
35
+ * each throw; zero ends it at once, so the hook is always ready.
36
+ */
37
+ export declare class Hook {
38
+ private readonly read;
39
+ private readonly cooldownSeconds;
40
+ /** thrownAt is the start of the latest cooldown counted as a throw. */
41
+ private thrownAt;
42
+ constructor(read: ReadHandle, cooldownSeconds?: number);
43
+ /** reset forgets the throws counted so far, for a thrower in a new world. */
44
+ reset(): void;
45
+ /**
46
+ * update reads the thrower's hook at game time now, keeps it fully upgraded
47
+ * and sets the length of any cooldown a throw started. It reports nothing
48
+ * for a hero without the hook.
49
+ */
50
+ update(player: HookPlayer, now: number): HookRead | undefined;
51
+ /** victim is the hero the hook entity holds, or undefined while it holds none. */
52
+ private victim;
53
+ /** setCooldown ends the cooldown cooldownSeconds after the hook's throw. */
54
+ private setCooldown;
55
+ }
package/host.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ /** Transport exchanges an encoded Call for the host's encoded Reply. */
2
+ export type Transport = (call: Uint8Array) => Uint8Array;
3
+ /** Dispatch answers one encoded Call the host delivers with its encoded Reply. */
4
+ export type Dispatch = (call: Uint8Array) => Uint8Array;
5
+ /** bind routes the mod's host calls through t from now on. */
6
+ export declare function bind(t: Transport): void;
7
+ /** serveEvents answers each event the host delivers with d. */
8
+ export declare function serveEvents(d: Dispatch): void;
9
+ /**
10
+ * deliver answers one encoded Call from the host. The library registers its
11
+ * dispatch when it loads, before any event can arrive.
12
+ */
13
+ export declare function deliver(call: Uint8Array): Uint8Array;
14
+ /**
15
+ * call calls one Host method with its encoded request and returns the
16
+ * encoded response, or undefined when the call failed; the host logs why.
17
+ * The response may be a view into the reply the transport returned.
18
+ */
19
+ export declare function call(method: string, request: Uint8Array): Uint8Array | undefined;