js-game-zero 0.0.0-stage → 0.4.0
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/LICENSE +22 -0
- package/README.md +138 -2
- package/dist/active-service.d.ts +21 -0
- package/dist/actor.d.ts +182 -0
- package/dist/animation.d.ts +61 -0
- package/dist/assets.d.ts +148 -0
- package/dist/audio.d.ts +150 -0
- package/dist/browser-asset-backends.d.ts +8 -0
- package/dist/browser.d.ts +10 -0
- package/dist/chunk-q9m20c2h.js +7972 -0
- package/dist/clock.d.ts +29 -0
- package/dist/color.d.ts +15 -0
- package/dist/events.d.ts +145 -0
- package/dist/friendly-names.d.ts +43 -0
- package/dist/geometry.d.ts +125 -0
- package/dist/helpers.d.ts +28 -0
- package/dist/host.d.ts +58 -0
- package/dist/host.js +435 -0
- package/dist/index.d.ts +340 -0
- package/dist/index.js +258 -0
- package/dist/input.d.ts +200 -0
- package/dist/inspection.d.ts +58 -0
- package/dist/jgz.js +8545 -0
- package/dist/node.d.ts +14 -0
- package/dist/node.js +145 -0
- package/dist/pixel-density.d.ts +23 -0
- package/dist/random.d.ts +31 -0
- package/dist/reference/actor.md +197 -0
- package/dist/reference/audio.md +128 -0
- package/dist/reference/clock.md +150 -0
- package/dist/reference/helpers.md +46 -0
- package/dist/reference/hooks.md +379 -0
- package/dist/reference/index.d.ts +2 -0
- package/dist/reference/index.js +39 -0
- package/dist/reference/loaders.md +164 -0
- package/dist/reference/rect.md +129 -0
- package/dist/reference/runtime.md +478 -0
- package/dist/reference/screen.md +392 -0
- package/dist/reference/storage.md +90 -0
- package/dist/rendering.d.ts +216 -0
- package/dist/runtime-contracts.d.ts +117 -0
- package/dist/runtime-diagnostics.d.ts +37 -0
- package/dist/runtime-persistence.d.ts +32 -0
- package/dist/runtime-source.d.ts +82 -0
- package/dist/runtime.d.ts +81 -0
- package/dist/source-scan.d.ts +49 -0
- package/dist/storage-path.d.ts +3 -0
- package/dist/storage.d.ts +88 -0
- package/dist/tone.d.ts +81 -0
- package/dist/touch-controls.d.ts +24 -0
- package/dist/touch-pointer.d.ts +11 -0
- package/dist/util.d.ts +62 -0
- package/package.json +69 -4
package/dist/clock.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
type ClockCallback = () => void;
|
|
2
|
+
type TickCallback = (dt: number) => void;
|
|
3
|
+
export type ClockOptions = {
|
|
4
|
+
/** Receives callback failures after the failing callback is unscheduled. */
|
|
5
|
+
readonly onError?: (error: unknown) => void;
|
|
6
|
+
};
|
|
7
|
+
export declare class Clock {
|
|
8
|
+
private readonly options;
|
|
9
|
+
private time;
|
|
10
|
+
private nextOrder;
|
|
11
|
+
private scheduled;
|
|
12
|
+
private active;
|
|
13
|
+
private tickCallbacks;
|
|
14
|
+
constructor(options?: ClockOptions);
|
|
15
|
+
schedule(callback: ClockCallback, delay: number): void;
|
|
16
|
+
scheduleUnique(callback: ClockCallback, delay: number): void;
|
|
17
|
+
scheduleInterval(callback: ClockCallback, interval: number): void;
|
|
18
|
+
unschedule(callback: Function): void;
|
|
19
|
+
eachTick(callback: TickCallback): void;
|
|
20
|
+
clear(): void;
|
|
21
|
+
tick(dt: number): void;
|
|
22
|
+
now(): number;
|
|
23
|
+
private nextDueEvent;
|
|
24
|
+
private reportCallbackError;
|
|
25
|
+
}
|
|
26
|
+
export declare function setActiveClock(nextClock: Clock | null): Clock | null;
|
|
27
|
+
export declare function getActiveClock(): Clock;
|
|
28
|
+
export declare const clock: Clock;
|
|
29
|
+
export {};
|
package/dist/color.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type Color = string | readonly [number, number, number] | readonly [number, number, number, number];
|
|
2
|
+
/**
|
|
3
|
+
* Turns a color into a canvas style string. A canvas silently ignores a
|
|
4
|
+
* color it can't read and keeps drawing with the previous one, so anything
|
|
5
|
+
* that isn't a recognizable color fails here, with a suggestion.
|
|
6
|
+
*/
|
|
7
|
+
export declare function normalizeColor(color: Color): string;
|
|
8
|
+
/**
|
|
9
|
+
* A color mixed from red, green and blue light, each 0 to 255, with an
|
|
10
|
+
* optional alpha from 0 (invisible) to 255 (solid). It returns the matching
|
|
11
|
+
* list, so it works anywhere a color does, but `rgb(255, 140, 105)` reads
|
|
12
|
+
* plainly to learners who haven't met lists yet.
|
|
13
|
+
*/
|
|
14
|
+
export declare function rgb(red: number, green: number, blue: number, alpha?: number): [number, number, number] | [number, number, number, number];
|
|
15
|
+
export declare function verticalGradient(context: CanvasRenderingContext2D, top: number, height: number, color: Color, gcolor: Color): CanvasGradient;
|
package/dist/events.d.ts
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { type Point } from "./geometry.js";
|
|
2
|
+
import { KeyboardState, MouseState } from "./input.js";
|
|
3
|
+
type HookArgs = Record<string, unknown>;
|
|
4
|
+
/**
|
|
5
|
+
* A hook a game defines. Its arguments are matched by parameter name, in
|
|
6
|
+
* whatever order the game declares them (see the hooks reference), so their
|
|
7
|
+
* types can't be given by position: `onKeyDown(key: number, mod: number)`
|
|
8
|
+
* and `onKeyDown(mod: number)` both fit.
|
|
9
|
+
*/
|
|
10
|
+
export type Hook = (...args: any[]) => void;
|
|
11
|
+
export type InputHooks = {
|
|
12
|
+
onMouseDown?: Hook;
|
|
13
|
+
onMouseUp?: Hook;
|
|
14
|
+
onMouseMove?: Hook;
|
|
15
|
+
onKeyDown?: Hook;
|
|
16
|
+
onKeyUp?: Hook;
|
|
17
|
+
onMusicEnd?: Hook;
|
|
18
|
+
};
|
|
19
|
+
export type BrowserKeyboardLike = {
|
|
20
|
+
code?: string;
|
|
21
|
+
key?: string;
|
|
22
|
+
shiftKey?: boolean;
|
|
23
|
+
ctrlKey?: boolean;
|
|
24
|
+
altKey?: boolean;
|
|
25
|
+
metaKey?: boolean;
|
|
26
|
+
repeat?: boolean;
|
|
27
|
+
getModifierState?: (key: string) => boolean;
|
|
28
|
+
};
|
|
29
|
+
export type BrowserMouseLike = {
|
|
30
|
+
clientX: number;
|
|
31
|
+
clientY: number;
|
|
32
|
+
button?: number;
|
|
33
|
+
buttons?: number;
|
|
34
|
+
movementX?: number;
|
|
35
|
+
movementY?: number;
|
|
36
|
+
};
|
|
37
|
+
export type BrowserWheelLike = {
|
|
38
|
+
clientX: number;
|
|
39
|
+
clientY: number;
|
|
40
|
+
deltaY: number;
|
|
41
|
+
buttons?: number;
|
|
42
|
+
};
|
|
43
|
+
type TargetBounds = {
|
|
44
|
+
left: number;
|
|
45
|
+
top: number;
|
|
46
|
+
width?: number;
|
|
47
|
+
height?: number;
|
|
48
|
+
};
|
|
49
|
+
type BoundsTarget = {
|
|
50
|
+
/**
|
|
51
|
+
* Logical screen size (the game's WIDTH/HEIGHT; the runtime passes its
|
|
52
|
+
* screen's, since pixel density multiplies `canvas.width`). When the
|
|
53
|
+
* canvas is displayed at a different CSS size (e.g. the sandbox preview
|
|
54
|
+
* scales it to fit its pane), positions are mapped back into game
|
|
55
|
+
* coordinates so `pos` always matches what the game draws with.
|
|
56
|
+
*/
|
|
57
|
+
width?: number;
|
|
58
|
+
height?: number;
|
|
59
|
+
ownerDocument?: EventTarget & {
|
|
60
|
+
readonly hidden?: boolean;
|
|
61
|
+
readonly visibilityState?: string;
|
|
62
|
+
};
|
|
63
|
+
getBoundingClientRect?: () => TargetBounds;
|
|
64
|
+
};
|
|
65
|
+
export type MappedKeyboardEvent = {
|
|
66
|
+
key: number;
|
|
67
|
+
mod: number;
|
|
68
|
+
unicode: string;
|
|
69
|
+
repeat: boolean;
|
|
70
|
+
};
|
|
71
|
+
export type MappedMouseEvent = {
|
|
72
|
+
pos: Point;
|
|
73
|
+
button: number | null;
|
|
74
|
+
buttons: Set<number>;
|
|
75
|
+
rel: Point;
|
|
76
|
+
};
|
|
77
|
+
/** Every input hook a game can define, besides `draw` and `update`. */
|
|
78
|
+
export declare const INPUT_HOOK_NAMES: readonly ["onMouseDown", "onMouseUp", "onMouseMove", "onKeyDown", "onKeyUp", "onMusicEnd"];
|
|
79
|
+
export type InputHookName = (typeof INPUT_HOOK_NAMES)[number];
|
|
80
|
+
/**
|
|
81
|
+
* The values each input hook can receive, in the order an ordinary
|
|
82
|
+
* (positional) reading of its parameter list hands them out.
|
|
83
|
+
*/
|
|
84
|
+
export declare const HOOK_PARAMETERS: Readonly<Record<InputHookName, readonly string[]>>;
|
|
85
|
+
/**
|
|
86
|
+
* Calls `handler` with the values from `args` its parameters ask for. A
|
|
87
|
+
* parameter named like a value (`pos`, `key`, `mod`, ...) receives that
|
|
88
|
+
* value wherever it sits in the list, Pygame Zero style. Any other name
|
|
89
|
+
* receives the next value in `order` not already claimed by name, the way an
|
|
90
|
+
* ordinary JavaScript function would — so `onKeyDown(k)` still gets the
|
|
91
|
+
* key. A lone `event` parameter receives the whole `args` object.
|
|
92
|
+
*/
|
|
93
|
+
export declare function dispatchHook(handler: Hook | undefined, args: HookArgs, order?: readonly string[]): void;
|
|
94
|
+
/** Marks `handler` to receive the whole event object, as `event` would. */
|
|
95
|
+
export declare function markWholeEventHook<T extends Function>(handler: T): T;
|
|
96
|
+
/** Whether `handler` receives the whole event object: it was marked, or its
|
|
97
|
+
* one parameter is called `event`. */
|
|
98
|
+
export declare function takesWholeEvent(handler: Function): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Which value each declared parameter receives: its own name when that is a
|
|
101
|
+
* known value, otherwise the next known value not claimed by name.
|
|
102
|
+
*/
|
|
103
|
+
export declare function resolveHookParameters(declared: readonly string[], known: readonly string[]): (string | undefined)[];
|
|
104
|
+
export declare function getParameterNames(callback: Function): string[];
|
|
105
|
+
export declare function mapBrowserKeyEvent(event: BrowserKeyboardLike): MappedKeyboardEvent | null;
|
|
106
|
+
export declare function mapBrowserMouseEvent(event: BrowserMouseLike, target?: BoundsTarget, previousPos?: Point | null): MappedMouseEvent;
|
|
107
|
+
export declare function mapBrowserMouseButton(button: number | undefined): number | null;
|
|
108
|
+
/**
|
|
109
|
+
* Maps a native `wheel` DOM event to a mouse-down-shaped event, matching
|
|
110
|
+
* pygame's convention of reporting scroll wheel motion as button 4 (up) /
|
|
111
|
+
* button 5 (down) presses (see pgzero.constants.mouse.WHEEL_UP/WHEEL_DOWN).
|
|
112
|
+
*
|
|
113
|
+
* Returns null for a zero (or missing) deltaY, since that carries no
|
|
114
|
+
* wheel-button semantics.
|
|
115
|
+
*/
|
|
116
|
+
export declare function mapBrowserWheelEvent(event: BrowserWheelLike, target?: BoundsTarget): MappedMouseEvent | null;
|
|
117
|
+
export declare function buttonsFromBrowserButtons(buttons: number): Set<number>;
|
|
118
|
+
export declare class InputDispatcher {
|
|
119
|
+
readonly keyboard: KeyboardState;
|
|
120
|
+
readonly mouseState: MouseState;
|
|
121
|
+
hooks: InputHooks;
|
|
122
|
+
private lastMousePos;
|
|
123
|
+
private readonly physicalKeys;
|
|
124
|
+
private readonly virtualKeys;
|
|
125
|
+
constructor(hooks?: InputHooks, keyboard?: KeyboardState, mouseState?: MouseState);
|
|
126
|
+
handleKeyDown(event: BrowserKeyboardLike): boolean;
|
|
127
|
+
handleKeyUp(event: BrowserKeyboardLike): boolean;
|
|
128
|
+
handleFocusLoss(): void;
|
|
129
|
+
/** Each pointer owns its press, so releasing one input cannot release another. */
|
|
130
|
+
handleVirtualKeyDown(key: number, source: unknown): void;
|
|
131
|
+
handleVirtualKeyUp(source: unknown): void;
|
|
132
|
+
handleMouseDown(event: BrowserMouseLike, target?: BoundsTarget): boolean;
|
|
133
|
+
handleMouseUp(event: BrowserMouseLike, target?: BoundsTarget): boolean;
|
|
134
|
+
handleMouseMove(event: BrowserMouseLike, target?: BoundsTarget): boolean;
|
|
135
|
+
/**
|
|
136
|
+
* Handles a native `wheel` event. pygame/pgzero report scroll wheel
|
|
137
|
+
* motion through the same channel as mouse button presses (button 4/5),
|
|
138
|
+
* so this dispatches `onMouseDown` just like handleMouseDown.
|
|
139
|
+
*/
|
|
140
|
+
handleWheel(event: BrowserWheelLike, target?: BoundsTarget): boolean;
|
|
141
|
+
private trackMouse;
|
|
142
|
+
attach(mouseTarget: EventTarget & BoundsTarget, keyboardTarget?: EventTarget): () => void;
|
|
143
|
+
}
|
|
144
|
+
export declare function createInputDispatcher(hooks?: InputHooks, keyboard?: KeyboardState, mouseState?: MouseState): InputDispatcher;
|
|
145
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The lowercase spellings of a camelCase name, with or without an underscore
|
|
3
|
+
* between each pair of its words: `collideListAll` gives `collidelistall`,
|
|
4
|
+
* `collide_list_all`, `collidelist_all` and `collide_listall`. Pygame Zero's
|
|
5
|
+
* names (`colliderect`, `angle_to`, `unionall_ip`) are all among them.
|
|
6
|
+
*/
|
|
7
|
+
export declare function otherSpellings(name: string): string[];
|
|
8
|
+
/**
|
|
9
|
+
* Makes the other spellings of `target`'s camelCase members throw when read
|
|
10
|
+
* or written, naming the member: reading `actor.angle_to` throws
|
|
11
|
+
* "actor.angle_to doesn't exist. Did you mean actor.angleTo?". `fields`
|
|
12
|
+
* names members that each instance sets on itself rather than inheriting
|
|
13
|
+
* from `target`. A spelling `target` already has is left alone, and guards
|
|
14
|
+
* are non-enumerable, so they never show up as data.
|
|
15
|
+
*/
|
|
16
|
+
export declare function guardSpellings(target: object, label: string, fields?: readonly string[]): void;
|
|
17
|
+
/**
|
|
18
|
+
* The real member a spelling guard on `target` or its prototypes stands in
|
|
19
|
+
* for (`colliderect` → `collideRect`), or undefined for any other name.
|
|
20
|
+
*/
|
|
21
|
+
export declare function guardedMember(target: object, property: string): string | undefined;
|
|
22
|
+
export type FriendlyServiceOptions = {
|
|
23
|
+
/** Members learners shouldn't reach (internal helpers). */
|
|
24
|
+
readonly hidden?: readonly string[];
|
|
25
|
+
/** Plain-object members to wrap the same way (`screen.draw`). */
|
|
26
|
+
readonly nested?: readonly string[];
|
|
27
|
+
/**
|
|
28
|
+
* Suggestions for guesses that belong somewhere else, by loose name
|
|
29
|
+
* (lowercase, without underscores): `{ drawrect: "screen.draw.rect" }`
|
|
30
|
+
* answers `screen.drawRect`.
|
|
31
|
+
*/
|
|
32
|
+
readonly hints?: Readonly<Record<string, string>>;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Wraps a library service (`screen`, `clock`, `keys`, ...) so reading a
|
|
36
|
+
* member it doesn't have throws
|
|
37
|
+
* `screen.draw.cirlce doesn't exist. Did you mean screen.draw.circle?`,
|
|
38
|
+
* including another spelling of a real member
|
|
39
|
+
* (`screen.draw.filled_circle` suggests `screen.draw.filledCircle`).
|
|
40
|
+
* Plain-object members (`screen.draw`) are wrapped the same way. Methods
|
|
41
|
+
* stay bound to the service, so they can be passed around as callbacks.
|
|
42
|
+
*/
|
|
43
|
+
export declare function friendlyService<T extends object>(target: T, label: string, options?: FriendlyServiceOptions): T;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
export type Point = [number, number];
|
|
2
|
+
export type Size = [number, number];
|
|
3
|
+
export type RectTuple = [number, number, number, number];
|
|
4
|
+
export type RectLike = Rect | RectTuple | readonly [number, number, number, number] | {
|
|
5
|
+
left: number;
|
|
6
|
+
top: number;
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
} | {
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
w: number;
|
|
13
|
+
h: number;
|
|
14
|
+
} | {
|
|
15
|
+
readonly rect: RectLike | (() => RectLike);
|
|
16
|
+
};
|
|
17
|
+
/** A dictionary-like collision target: a `Map`, or a plain object keyed by string. */
|
|
18
|
+
export type RectDict<V> = Map<unknown, V> | Record<string, V>;
|
|
19
|
+
type PairLike = readonly [number, number];
|
|
20
|
+
export declare class Rect {
|
|
21
|
+
left: number;
|
|
22
|
+
top: number;
|
|
23
|
+
width: number;
|
|
24
|
+
height: number;
|
|
25
|
+
constructor(left: number, top: number, width: number, height: number);
|
|
26
|
+
constructor(topLeft: PairLike, size: PairLike);
|
|
27
|
+
constructor(rect: RectLike);
|
|
28
|
+
get x(): number;
|
|
29
|
+
set x(value: number);
|
|
30
|
+
get y(): number;
|
|
31
|
+
set y(value: number);
|
|
32
|
+
get w(): number;
|
|
33
|
+
set w(value: number);
|
|
34
|
+
get h(): number;
|
|
35
|
+
set h(value: number);
|
|
36
|
+
get right(): number;
|
|
37
|
+
set right(value: number);
|
|
38
|
+
get bottom(): number;
|
|
39
|
+
set bottom(value: number);
|
|
40
|
+
get centerX(): number;
|
|
41
|
+
set centerX(value: number);
|
|
42
|
+
get centerY(): number;
|
|
43
|
+
set centerY(value: number);
|
|
44
|
+
get topLeft(): Point;
|
|
45
|
+
set topLeft(value: PairLike);
|
|
46
|
+
get topRight(): Point;
|
|
47
|
+
set topRight(value: PairLike);
|
|
48
|
+
get bottomLeft(): Point;
|
|
49
|
+
set bottomLeft(value: PairLike);
|
|
50
|
+
get bottomRight(): Point;
|
|
51
|
+
set bottomRight(value: PairLike);
|
|
52
|
+
get midTop(): Point;
|
|
53
|
+
set midTop(value: PairLike);
|
|
54
|
+
get midLeft(): Point;
|
|
55
|
+
set midLeft(value: PairLike);
|
|
56
|
+
get midRight(): Point;
|
|
57
|
+
set midRight(value: PairLike);
|
|
58
|
+
get midBottom(): Point;
|
|
59
|
+
set midBottom(value: PairLike);
|
|
60
|
+
get center(): Point;
|
|
61
|
+
set center(value: PairLike);
|
|
62
|
+
get size(): Size;
|
|
63
|
+
set size(value: PairLike);
|
|
64
|
+
/** Index 0: `left`. Mirrors pygame/pgzero's `rect[0]`. */
|
|
65
|
+
get 0(): number;
|
|
66
|
+
/** Index 1: `top`. Mirrors pygame/pgzero's `rect[1]`. */
|
|
67
|
+
get 1(): number;
|
|
68
|
+
/** Index 2: `width`. Mirrors pygame/pgzero's `rect[2]`. */
|
|
69
|
+
get 2(): number;
|
|
70
|
+
/** Index 3: `height`. Mirrors pygame/pgzero's `rect[3]`. */
|
|
71
|
+
get 3(): number;
|
|
72
|
+
/** Iterates as `[left, top, width, height]`, so `[...rect]` works like pgzero's ZRect. */
|
|
73
|
+
[Symbol.iterator](): Iterator<number>;
|
|
74
|
+
copy(): Rect;
|
|
75
|
+
move(x: number, y: number): Rect;
|
|
76
|
+
move(offset: PairLike): Rect;
|
|
77
|
+
moveIp(x: number, y: number): void;
|
|
78
|
+
moveIp(offset: PairLike): void;
|
|
79
|
+
inflate(x: number, y: number): Rect;
|
|
80
|
+
inflate(size: PairLike): Rect;
|
|
81
|
+
inflateIp(x: number, y: number): void;
|
|
82
|
+
inflateIp(size: PairLike): void;
|
|
83
|
+
normalize(): void;
|
|
84
|
+
clamp(other: RectLike): Rect;
|
|
85
|
+
/** Mutating form of {@link clamp}. */
|
|
86
|
+
clampIp(other: RectLike): void;
|
|
87
|
+
clip(other: RectLike): Rect;
|
|
88
|
+
/** Mutating form of {@link clip}. */
|
|
89
|
+
clipIp(other: RectLike): void;
|
|
90
|
+
union(other: RectLike): Rect;
|
|
91
|
+
/** Mutating form of {@link union}. */
|
|
92
|
+
unionIp(other: RectLike): void;
|
|
93
|
+
unionAll(others: RectLike[]): Rect;
|
|
94
|
+
/** Mutating form of {@link unionAll}. */
|
|
95
|
+
unionAllIp(others: RectLike[]): void;
|
|
96
|
+
fit(other: RectLike): Rect;
|
|
97
|
+
contains(other: RectLike): boolean;
|
|
98
|
+
collidePoint(point: PairLike): boolean;
|
|
99
|
+
collidePoint(x: number, y: number): boolean;
|
|
100
|
+
/**
|
|
101
|
+
* True when this rectangle overlaps `target`: another rect (or anything
|
|
102
|
+
* with a rect, like an Actor), or an `[x, y]` point inside it.
|
|
103
|
+
*/
|
|
104
|
+
touches(target: RectLike | PairLike): boolean;
|
|
105
|
+
collideRect(other: RectLike): boolean;
|
|
106
|
+
collideList(others: RectLike[]): number;
|
|
107
|
+
collideListAll(others: RectLike[]): number[];
|
|
108
|
+
/**
|
|
109
|
+
* Returns the first `[key, value]` entry of `dict` that collides with this
|
|
110
|
+
* rect, or `undefined` if none do. By default the *values* are treated as
|
|
111
|
+
* rect-likes (matching rect.py's `use_values=True`); pass `useValues:
|
|
112
|
+
* false` to instead treat the *keys* as rect-likes (only meaningful for a
|
|
113
|
+
* `Map` whose keys are themselves rect-likes, since plain object keys are
|
|
114
|
+
* always strings).
|
|
115
|
+
*/
|
|
116
|
+
collideDict<V>(dict: RectDict<V>, useValues?: boolean): [unknown, V] | undefined;
|
|
117
|
+
/** Same as {@link collideDict}, but returns every colliding entry. */
|
|
118
|
+
collideDictAll<V>(dict: RectDict<V>, useValues?: boolean): Array<[unknown, V]>;
|
|
119
|
+
private applyGeometry;
|
|
120
|
+
}
|
|
121
|
+
export declare class ZRect extends Rect {
|
|
122
|
+
}
|
|
123
|
+
export declare function angleTo(from: PairLike, to: PairLike): number;
|
|
124
|
+
export declare function distanceTo(from: PairLike, to: PairLike): number;
|
|
125
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Small helpers for the things almost every game hand-writes: a random
|
|
3
|
+
* whole number, a random pick from a list, and keeping a value in range.
|
|
4
|
+
* The random ones read the running game's random source, so a seeded run
|
|
5
|
+
* (`run(source, { seed })`) repeats them too.
|
|
6
|
+
*/
|
|
7
|
+
import { type RandomSource } from "./random.js";
|
|
8
|
+
/**
|
|
9
|
+
* A random whole number from `min` to `max`, including both ends:
|
|
10
|
+
* `randomInt(1, 6)` rolls a die.
|
|
11
|
+
*/
|
|
12
|
+
export declare function randomInt(min: number, max: number): number;
|
|
13
|
+
/** A random item from a list: `randomChoice(["red", "green", "blue"])`. */
|
|
14
|
+
export declare function randomChoice<T>(items: readonly T[]): T;
|
|
15
|
+
/**
|
|
16
|
+
* `randomInt` and `randomChoice` that always draw from one game's source,
|
|
17
|
+
* so they repeat with its seed even when called outside its hooks, as the
|
|
18
|
+
* CLI's `call` does.
|
|
19
|
+
*/
|
|
20
|
+
export declare function randomHelpersFor(source: RandomSource): {
|
|
21
|
+
randomInt: typeof randomInt;
|
|
22
|
+
randomChoice: typeof randomChoice;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* `value`, moved inside `min`..`max` if it's outside:
|
|
26
|
+
* `player.x = clamp(player.x, 0, WIDTH)`.
|
|
27
|
+
*/
|
|
28
|
+
export declare function clamp(value: number, min: number, max: number): number;
|
package/dist/host.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/** Advanced host-integration APIs. Learner games import the core root. */
|
|
2
|
+
import * as assets from "./assets.js";
|
|
3
|
+
import * as audio from "./audio.js";
|
|
4
|
+
import * as events from "./events.js";
|
|
5
|
+
import * as inspection from "./inspection.js";
|
|
6
|
+
import * as rendering from "./rendering.js";
|
|
7
|
+
import * as random from "./random.js";
|
|
8
|
+
import * as runtime from "./runtime.js";
|
|
9
|
+
import * as storage from "./storage.js";
|
|
10
|
+
import * as tone from "./tone.js";
|
|
11
|
+
export { AudioUnlockState, BrowserSoundAsset, MusicPlayer } from "./audio.js";
|
|
12
|
+
export { InputDispatcher } from "./events.js";
|
|
13
|
+
export { ToneGenerator } from "./tone.js";
|
|
14
|
+
export declare const assetUrl: typeof assets.assetUrl;
|
|
15
|
+
export declare const audioUnlock: audio.AudioUnlockState;
|
|
16
|
+
export declare const buttonsFromBrowserButtons: typeof events.buttonsFromBrowserButtons;
|
|
17
|
+
export declare const clampVolume: typeof audio.clampVolume;
|
|
18
|
+
export declare const collectRuntimeDiagnostics: typeof runtime.collectRuntimeDiagnostics;
|
|
19
|
+
export declare const createAssetLoaders: typeof assets.createAssetLoaders;
|
|
20
|
+
export declare const createBrowserSoundAsset: typeof audio.createBrowserSoundAsset;
|
|
21
|
+
export declare const createFontLoader: typeof assets.createFontLoader;
|
|
22
|
+
export declare const createImageLoader: typeof assets.createImageLoader;
|
|
23
|
+
export declare const createInputDispatcher: typeof events.createInputDispatcher;
|
|
24
|
+
export declare const createLocalStorageAdapter: typeof storage.createLocalStorageAdapter;
|
|
25
|
+
export declare const createSeededRandom: typeof random.createSeededRandom;
|
|
26
|
+
export declare const createMusicLoader: typeof assets.createMusicLoader;
|
|
27
|
+
export declare const createMusicPlayer: typeof audio.createMusicPlayer;
|
|
28
|
+
export declare const createSoundLoader: typeof assets.createSoundLoader;
|
|
29
|
+
export declare const createStorage: typeof storage.createStorage;
|
|
30
|
+
export declare const createToneGenerator: typeof tone.createToneGenerator;
|
|
31
|
+
export declare const dispatchHook: typeof events.dispatchHook;
|
|
32
|
+
export declare const fitTextboxFontSize: typeof rendering.fitTextboxFontSize;
|
|
33
|
+
export declare const getParameterNames: typeof events.getParameterNames;
|
|
34
|
+
export declare const getGameInspector: typeof inspection.getGameInspector;
|
|
35
|
+
export declare const getScreen: typeof rendering.getScreen;
|
|
36
|
+
export declare const layoutText: typeof rendering.layoutText;
|
|
37
|
+
export declare const loadImages: typeof assets.loadImages;
|
|
38
|
+
export declare const mapBrowserKeyEvent: typeof events.mapBrowserKeyEvent;
|
|
39
|
+
export declare const mapBrowserMouseButton: typeof events.mapBrowserMouseButton;
|
|
40
|
+
export declare const mapBrowserMouseEvent: typeof events.mapBrowserMouseEvent;
|
|
41
|
+
export declare const mapBrowserWheelEvent: typeof events.mapBrowserWheelEvent;
|
|
42
|
+
export declare const normalizeColor: typeof rendering.normalizeColor;
|
|
43
|
+
export declare const normalizeWaveform: typeof tone.normalizeWaveform;
|
|
44
|
+
export declare const parseStatePath: typeof inspection.parseStatePath;
|
|
45
|
+
export declare const noteToFrequency: typeof tone.noteToFrequency;
|
|
46
|
+
export declare const parseToneFrequency: typeof tone.parseToneFrequency;
|
|
47
|
+
export declare const serializeGameValue: typeof inspection.serializeGameValue;
|
|
48
|
+
export declare const setScreen: typeof rendering.setScreen;
|
|
49
|
+
export declare const validateAssetName: typeof assets.validateAssetName;
|
|
50
|
+
export type { AssetLoader, AssetLoaderOptions, AssetLoaders, AssetUrls, DrawableImage, FontAsset, MusicAsset, SoundAsset, SurfaceLike, } from "./assets.js";
|
|
51
|
+
export type { AudioElementFactory, AudioElementLike, BrowserSoundDebugState, BrowserSoundOptions, MusicPlayerOptions, TimeoutScheduler, } from "./audio.js";
|
|
52
|
+
export type { BrowserKeyboardLike, BrowserMouseLike, BrowserWheelLike, MappedKeyboardEvent, MappedMouseEvent, } from "./events.js";
|
|
53
|
+
export type { GameInspector, JsonSafe, StatePath } from "./inspection.js";
|
|
54
|
+
export type { RandomSeed, RandomSource } from "./random.js";
|
|
55
|
+
export type { CanvasLike, TextLayout } from "./rendering.js";
|
|
56
|
+
export type { PreloadedAssets, RuntimeCanvas, RuntimeDiagnostic, RuntimeFailure, RuntimeFailurePhase, RuntimeScheduler, } from "./runtime.js";
|
|
57
|
+
export type { BrowserStorageLike, LocalStorageAdapterOptions, StorageAdapter, StorageOptions, } from "./storage.js";
|
|
58
|
+
export type { AudioContextLike, AudioParamLike, GainNodeLike, OscillatorNodeLike, ToneOptions, } from "./tone.js";
|