@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/ui.d.ts ADDED
@@ -0,0 +1,428 @@
1
+ import type { Player } from './host.gen.js';
2
+ /**
3
+ * Length is a size: pixels, a percentage of the parent, 'fit' to size to the
4
+ * children, or 'fill' to share the space left in the parent's flow.
5
+ */
6
+ export type Length = number | `${number}%` | 'fit' | 'fill';
7
+ /**
8
+ * Edges are distances in pixels: one for every side, [vertical, horizontal],
9
+ * or [top, right, bottom, left]. They are an array rather than a union of
10
+ * tuples, which scriptc does not compile.
11
+ */
12
+ export type Edges = number | readonly number[];
13
+ /**
14
+ * Overflow decides what happens to children that do not fit: 'squish' shrinks
15
+ * them, 'clip' cuts them off, 'scroll' lets the player scroll to them, and
16
+ * 'show' draws them outside the element.
17
+ */
18
+ export type Overflow = 'squish' | 'clip' | 'scroll' | 'show';
19
+ /**
20
+ * Gradient blends colors across an element in place of its background. The
21
+ * colors run down by default; at places each color from 0 to 1, spaced evenly
22
+ * when unset.
23
+ */
24
+ export interface Gradient {
25
+ shape?: 'down' | 'right' | 'up' | 'left' | 'radial';
26
+ colors: readonly string[];
27
+ at?: readonly number[];
28
+ }
29
+ /**
30
+ * Shadow is a soft shadow, offset by x and y and softened by blur, in pixels.
31
+ * Spread grows a box's shadow in pixels, or strengthens a text shadow, where 0
32
+ * draws it at full strength; inset draws a box's shadow inside its edge.
33
+ */
34
+ export interface Shadow {
35
+ x?: number;
36
+ y?: number;
37
+ blur?: number;
38
+ spread?: number;
39
+ color: string;
40
+ inset?: boolean;
41
+ }
42
+ /**
43
+ * Transition animates each change of an element's style, and the move to its
44
+ * hover style and back, over seconds after delay. Easing is 'out' unless set.
45
+ */
46
+ export interface Transition {
47
+ seconds: number;
48
+ delay?: number;
49
+ easing?: 'out' | 'in' | 'inOut' | 'linear';
50
+ }
51
+ /**
52
+ * Style lays out and paints an element. Colors are '#rrggbb' or '#rrggbbaa'.
53
+ * Options that take one or two numbers are an array rather than a union of
54
+ * tuples, which scriptc does not compile.
55
+ */
56
+ export interface Style {
57
+ width?: Length;
58
+ height?: Length;
59
+ /** minWidth, maxWidth, minHeight and maxHeight bound the element's size. */
60
+ minWidth?: Length;
61
+ maxWidth?: Length;
62
+ minHeight?: Length;
63
+ maxHeight?: Length;
64
+ /**
65
+ * flow places the children in a column or a row, or in columns or rows that
66
+ * wrap where one is full; unset stacks them.
67
+ */
68
+ flow?: 'down' | 'right' | 'downWrap' | 'rightWrap';
69
+ /**
70
+ * x and y place the element at an offset from its parent's top left corner,
71
+ * in pixels or a percent of the parent, outside the parent's flow.
72
+ */
73
+ x?: number | `${number}%`;
74
+ y?: number | `${number}%`;
75
+ /** zIndex draws the element above its siblings with a lower index. */
76
+ zIndex?: number;
77
+ /** overflow decides what children that do not fit do, across and down. */
78
+ overflow?: Overflow;
79
+ /** overflowX and overflowY set overflow for one direction. */
80
+ overflowX?: Overflow;
81
+ overflowY?: Overflow;
82
+ horizontalAlign?: 'left' | 'center' | 'right';
83
+ verticalAlign?: 'top' | 'center' | 'bottom';
84
+ margin?: Edges;
85
+ padding?: Edges;
86
+ background?: string;
87
+ color?: string;
88
+ fontSize?: number;
89
+ bold?: boolean;
90
+ textAlign?: 'left' | 'center' | 'right';
91
+ borderRadius?: number;
92
+ /** opacity fades the element and its children, from 0 to 1. */
93
+ opacity?: number;
94
+ /**
95
+ * face is one of the game's typefaces: 'body' its text, 'block' the
96
+ * capitals of its clock and titles, 'serif' its menus.
97
+ */
98
+ face?: 'body' | 'block' | 'serif';
99
+ /** uppercase sets the text in capitals. */
100
+ uppercase?: boolean;
101
+ /** letterSpacing widens the space between letters, in pixels. */
102
+ letterSpacing?: number;
103
+ /** shadow draws a soft drop shadow under the text, to read over the world. */
104
+ shadow?: boolean;
105
+ /** textShadow draws this shadow under the text in place of shadow's. */
106
+ textShadow?: Shadow;
107
+ /**
108
+ * borderWidth and borderColor draw a line around the element's edge; it
109
+ * shows only when both are set.
110
+ */
111
+ borderWidth?: number;
112
+ borderColor?: string;
113
+ /** gradient fills the element in place of its background. */
114
+ gradient?: Gradient;
115
+ /** boxShadow draws a shadow around or inside the element's box. */
116
+ boxShadow?: Shadow;
117
+ /** tint washes the element and its children with a color, recoloring a white icon. */
118
+ tint?: string;
119
+ /** saturation, brightness and contrast scale the colors; 1 leaves them. */
120
+ saturation?: number;
121
+ brightness?: number;
122
+ contrast?: number;
123
+ /** blur blurs the element and its children by a radius in pixels. */
124
+ blur?: number;
125
+ italic?: boolean;
126
+ /** weight sets the text's weight in place of bold. */
127
+ weight?: 'thin' | 'light' | 'normal' | 'medium' | 'semiBold' | 'bold' | 'black';
128
+ /** lineHeight is the height of each line of text, in pixels. */
129
+ lineHeight?: number;
130
+ /** noWrap keeps the text on one line. */
131
+ noWrap?: boolean;
132
+ /**
133
+ * textOverflow ends text that does not fit with an 'ellipsis', 'shrink's it
134
+ * until it fits, or 'clip's it at the edge.
135
+ */
136
+ textOverflow?: 'ellipsis' | 'shrink' | 'clip';
137
+ /** decoration draws a line under or through the text. */
138
+ decoration?: 'underline' | 'strike';
139
+ /** translate moves the element as drawn by [x, y] pixels. */
140
+ translate?: readonly number[];
141
+ /** scale scales the element as drawn: one factor, or [x, y]. */
142
+ scale?: number | readonly number[];
143
+ /** rotate turns the element clockwise, in degrees. */
144
+ rotate?: number;
145
+ /**
146
+ * origin is the point the element scales and turns about, as [x, y]
147
+ * percents of its size; unset is its center.
148
+ */
149
+ origin?: readonly number[];
150
+ /**
151
+ * transition animates each change of the style: seconds, or a Transition.
152
+ * Animate transform, opacity and colors; size and placement animate too, but
153
+ * move the element's neighbors each frame.
154
+ */
155
+ transition?: number | Transition;
156
+ }
157
+ /**
158
+ * HudPart is a part of the game's own HUD: 'levelUp' the notice for each boon,
159
+ * ability point and power increase, 'ownHealth' the player's health bar with
160
+ * its shields and regeneration, 'topBar' the bar of team scores, portraits
161
+ * and clock across the top, 'ammo' the clip ring, count and ammo warnings at
162
+ * the crosshair, 'souls' the souls and level readout, 'minimap' the minimap
163
+ * with its hints and district name, 'abilities' the ability and active item
164
+ * bar. Whatever a part does not name stays, such as the crosshair and chat.
165
+ */
166
+ export type HudPart = 'levelUp' | 'ownHealth' | 'topBar' | 'ammo' | 'souls' | 'minimap' | 'abilities';
167
+ /** Child is anything an element may hold. Text becomes a label. */
168
+ export type Child = UiElement | string | number | boolean | null | undefined | readonly Child[];
169
+ /** Component returns the elements that stand for its props. */
170
+ export type Component<P> = (props: P) => Child;
171
+ /**
172
+ * UiElement is one element of an interface, as JSX builds it. A component's
173
+ * element is a fragment holding what the component returned.
174
+ */
175
+ export interface UiElement {
176
+ readonly type: string;
177
+ readonly props: Props;
178
+ readonly key?: string;
179
+ }
180
+ /**
181
+ * Props are an element's props: every intrinsic element's, by name, so the
182
+ * encoder reads them as typed fields. A component's props pass through to it.
183
+ */
184
+ export interface Props {
185
+ readonly class?: string;
186
+ readonly style?: Style;
187
+ readonly hover?: Style;
188
+ readonly tooltip?: string;
189
+ readonly hoverSound?: string;
190
+ readonly children?: Child;
191
+ readonly src?: string;
192
+ readonly scaling?: Scaling;
193
+ readonly hero?: number;
194
+ readonly look?: HeroLookName;
195
+ readonly data?: unknown;
196
+ readonly sound?: string;
197
+ readonly disabled?: boolean;
198
+ readonly onPress?: (player: Player) => void;
199
+ readonly enter?: Style;
200
+ readonly exit?: Style;
201
+ readonly cycle?: Cycle;
202
+ readonly token?: string;
203
+ readonly variables?: Readonly<Record<string, string | number>>;
204
+ readonly steamId?: bigint;
205
+ readonly value?: string | number;
206
+ readonly placeholder?: string;
207
+ readonly maxLength?: number;
208
+ readonly min?: number;
209
+ readonly max?: number;
210
+ readonly step?: number;
211
+ readonly on?: boolean;
212
+ readonly options?: readonly string[];
213
+ readonly selected?: number;
214
+ readonly onChange?: (player: Player, value: never) => void;
215
+ }
216
+ /**
217
+ * ElementProps are the props every drawn element takes. hover is the style
218
+ * drawn over style while the pointer is over the element; tooltip is the text
219
+ * the game's tooltip shows then, and hoverSound the game's sound event played
220
+ * as the pointer enters, such as 'UI.MainMenu.Hover'. An element with any of
221
+ * them takes the pointer, so the game behind it does not.
222
+ */
223
+ export interface ElementProps {
224
+ /** class names the element's classes in the mod's sheets, separated by spaces. */
225
+ class?: string;
226
+ style?: Style;
227
+ hover?: Style;
228
+ tooltip?: string;
229
+ hoverSound?: string;
230
+ /** enter is the style the element's panel starts from when it first shows. */
231
+ enter?: Style;
232
+ /** exit is the style the element's panel eases to as it leaves. */
233
+ exit?: Style;
234
+ /** cycle swings the element to another style and back while it shows. */
235
+ cycle?: Cycle;
236
+ }
237
+ /**
238
+ * Cycle swings an element from its style to style and back, each way taking
239
+ * seconds, count times or, without a count, while it shows.
240
+ */
241
+ export interface Cycle {
242
+ style: Style;
243
+ seconds: number;
244
+ count?: number;
245
+ }
246
+ /** PanelProps lay out a panel, which groups its children. */
247
+ export interface PanelProps extends ElementProps {
248
+ children?: Child;
249
+ }
250
+ /**
251
+ * LabelProps show text: the label's text children, joined, or the game's text
252
+ * for token in the player's language, with each {s:name} place in it filled
253
+ * from variables.
254
+ */
255
+ export interface LabelProps extends ElementProps {
256
+ children?: Child;
257
+ token?: string;
258
+ variables?: Readonly<Record<string, string | number>>;
259
+ }
260
+ /** AvatarProps show the Steam picture of the player with steamId. */
261
+ export interface AvatarProps extends ElementProps {
262
+ steamId: bigint;
263
+ }
264
+ /**
265
+ * InputProps are the props every input takes. A disabled input takes no
266
+ * changes.
267
+ */
268
+ export interface InputProps extends ElementProps {
269
+ disabled?: boolean;
270
+ }
271
+ /**
272
+ * EntryProps make a box the player types a line into: value is its text,
273
+ * placeholder the faint text it shows empty, and maxLength its limit in
274
+ * characters, 100 unless set, and at most 240 bytes of text.
275
+ */
276
+ export interface EntryProps extends InputProps {
277
+ value?: string;
278
+ placeholder?: string;
279
+ maxLength?: number;
280
+ onChange?: (player: Player, text: string) => void;
281
+ }
282
+ /**
283
+ * SliderProps make a bar the player drags to a number from min to max, 0 to 1
284
+ * unless set, stopping at each step when step is set.
285
+ */
286
+ export interface SliderProps extends InputProps {
287
+ value?: number;
288
+ min?: number;
289
+ max?: number;
290
+ step?: number;
291
+ onChange?: (player: Player, value: number) => void;
292
+ }
293
+ /** ToggleProps make a box the player checks, labeled by its text children. */
294
+ export interface ToggleProps extends InputProps {
295
+ children?: Child;
296
+ on?: boolean;
297
+ onChange?: (player: Player, on: boolean) => void;
298
+ }
299
+ /** DropdownProps let the player pick one of options; selected is its index. */
300
+ export interface DropdownProps extends InputProps {
301
+ options: readonly string[];
302
+ selected?: number;
303
+ onChange?: (player: Player, index: number) => void;
304
+ }
305
+ /**
306
+ * Scaling fits a picture into its element's box: 'fit' shows it whole, 'cover'
307
+ * fills the box and crops, 'stretch' fills the box and stretches, 'fitWidth'
308
+ * and 'fitHeight' fit one side, and 'none' draws it at its own size.
309
+ */
310
+ export type Scaling = 'fit' | 'cover' | 'stretch' | 'fitWidth' | 'fitHeight' | 'none';
311
+ /** ImageProps show an image from the game's content, such as 'file://{images}/hud/icon.png'. */
312
+ export interface ImageProps extends ElementProps {
313
+ src: string;
314
+ scaling?: Scaling;
315
+ }
316
+ /**
317
+ * HeroLookName is one of the game's pictures of a hero: 'small' the square
318
+ * portrait of the kill feed, 'card' the hero picker's tall card, 'icon' the
319
+ * round icon, 'vertical' the hero grid's narrow portrait, 'topBar' the top
320
+ * bar's portrait and 'minimap' the minimap icon.
321
+ */
322
+ export type HeroLookName = 'small' | 'card' | 'icon' | 'vertical' | 'topBar' | 'minimap';
323
+ /** HeroProps show a picture of hero, by the game's hero id. */
324
+ export interface HeroProps extends ElementProps {
325
+ hero: number;
326
+ look?: HeroLookName;
327
+ scaling?: Scaling;
328
+ }
329
+ /**
330
+ * ButtonProps make a button, which holds its children and calls onPress
331
+ * with the player who pressed it. Players press buttons while they have a
332
+ * cursor. sound is the game's sound event the press plays, such as
333
+ * 'UI.MainMenu.Activate', and a disabled button takes no presses.
334
+ */
335
+ export interface ButtonProps extends ElementProps {
336
+ children?: Child;
337
+ sound?: string;
338
+ disabled?: boolean;
339
+ onPress?: (player: Player) => void;
340
+ }
341
+ /**
342
+ * LayoutProps load a layout from the mod's content addon: src is its path
343
+ * there, such as 'shop.xml', and data is the JSON value its script reads with
344
+ * Modlock.data.
345
+ */
346
+ export interface LayoutProps {
347
+ class?: string;
348
+ style?: Style;
349
+ src: string;
350
+ data?: unknown;
351
+ }
352
+ /** JSX types the elements a mod's JSX may use. */
353
+ export declare namespace JSX {
354
+ type Element = UiElement;
355
+ interface IntrinsicElements {
356
+ panel: PanelProps & IntrinsicAttributes;
357
+ label: LabelProps & IntrinsicAttributes;
358
+ image: ImageProps & IntrinsicAttributes;
359
+ hero: HeroProps & IntrinsicAttributes;
360
+ button: ButtonProps & IntrinsicAttributes;
361
+ layout: LayoutProps & IntrinsicAttributes;
362
+ avatar: AvatarProps & IntrinsicAttributes;
363
+ entry: EntryProps & IntrinsicAttributes;
364
+ slider: SliderProps & IntrinsicAttributes;
365
+ toggle: ToggleProps & IntrinsicAttributes;
366
+ dropdown: DropdownProps & IntrinsicAttributes;
367
+ }
368
+ interface IntrinsicAttributes {
369
+ key?: string | number;
370
+ }
371
+ interface ElementChildrenAttribute {
372
+ children: unknown;
373
+ }
374
+ }
375
+ /**
376
+ * jsx builds one element, rendering a component in place; the TypeScript
377
+ * compiler calls it for JSX.
378
+ */
379
+ export declare function jsx(type: string | Component<Props>, props: Props, key?: string | number): UiElement;
380
+ /** jsxs builds an element with several children, as jsx does. */
381
+ export declare const jsxs: typeof jsx;
382
+ /** Fragment groups children without a panel of its own. */
383
+ export declare function Fragment(props: {
384
+ children?: Child;
385
+ }): Child;
386
+ /**
387
+ * show replaces the interface the mod shows player with root. A player who
388
+ * left and a mod that restarted show nothing until the next call.
389
+ */
390
+ export declare function show(player: Player, root: Child): boolean;
391
+ /**
392
+ * hideHud hides parts of the game's own HUD from player until the next call;
393
+ * an empty list shows them all again.
394
+ */
395
+ export declare function hideHud(player: Player, parts: readonly HudPart[]): boolean;
396
+ /**
397
+ * sheet adds the style sheet at path in the mod's content styles directory,
398
+ * such as 'hud.css', to every interface the mod shows, after the sheets added
399
+ * before it. Adding a sheet again changes nothing. A path is letters, digits,
400
+ * '_', '-' and '.' in segments separated by '/', ending in '.css'; another
401
+ * adds nothing and returns false. The build turns an import of a sheet, such
402
+ * as import './content/styles/hud.css', into this call.
403
+ */
404
+ export declare function sheet(path: string): boolean;
405
+ /**
406
+ * route sends player value under name, for every layout of the mod to read
407
+ * with Modlock.route, until the next call; undefined removes it. A name is
408
+ * letters, digits, '_', '-' and '.', and the value is anything JSON.stringify
409
+ * takes. A route with another name, or a value JSON cannot hold, sends nothing
410
+ * and returns false.
411
+ */
412
+ export declare function route(player: Player, name: string, value: unknown): boolean;
413
+ /** hide removes the interface, the routes and the notices the mod shows player. */
414
+ export declare function hide(player: Player): boolean;
415
+ /**
416
+ * toast shows player text in a notice at the lower left for seconds.
417
+ * Notices stack, newest last, slide in, and fade as they expire.
418
+ */
419
+ export declare function toast(player: Player, text: string, seconds?: number): boolean;
420
+ /** press runs the handler of the button the player pressed. */
421
+ export declare function press(player: Player, node: string): void;
422
+ /**
423
+ * change runs the handler of the input the player changed, with its value as
424
+ * the host checked it.
425
+ */
426
+ export declare function change(player: Player, node: string, value: string | number | boolean | undefined): void;
427
+ /** tick advances the clock to the frame at seconds and fades expiring notices. */
428
+ export declare function tick(seconds: number): void;
package/vector.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ import type { Angles, Vector } from './host.gen.js';
2
+ /** at builds a point or direction from its coordinates. */
3
+ export declare function at(x: number, y: number, z: number): Vector;
4
+ /** add is a moved by b. */
5
+ export declare function add(a: Vector, b: Vector): Vector;
6
+ /** sub is the step from b to a. */
7
+ export declare function sub(a: Vector, b: Vector): Vector;
8
+ /** scale is a times s. */
9
+ export declare function scale(a: Vector, s: number): Vector;
10
+ /** dot is the dot product of a and b. */
11
+ export declare function dot(a: Vector, b: Vector): number;
12
+ /** length is a's length. */
13
+ export declare function length(a: Vector): number;
14
+ /** normalize is a at unit length, or +x for a zero vector. */
15
+ export declare function normalize(a: Vector): Vector;
16
+ /** lerp is the point t of the way from a to b: a at 0, b at 1. */
17
+ export declare function lerp(a: Vector, b: Vector, t: number): Vector;
18
+ /** distance is how far apart a and b are. */
19
+ export declare function distance(a: Vector, b: Vector): number;
20
+ /** flatDistance is how far apart a and b are seen from above, ignoring height. */
21
+ export declare function flatDistance(a: Vector, b: Vector): number;
22
+ /** toward is the unit direction from from to to, or zero when they meet. */
23
+ export declare function toward(from: Vector, to: Vector): Vector;
24
+ /** yawToward is the yaw that faces from from toward to, in degrees. */
25
+ export declare function yawToward(from: Vector, to: Vector): number;
26
+ /** level is the view that looks along yaw, straight ahead. */
27
+ export declare function level(yaw: number): Angles;
28
+ /** aimAt is the view from from that looks at to, without roll. */
29
+ export declare function aimAt(from: Vector, to: Vector): Angles;
30
+ /** forward is the unit direction a view looks along; roll does not change it. */
31
+ export declare function forward(angles: Angles): Vector;