js-game-zero 0.0.0-placeholder → 0.3.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 +135 -3
- 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-brk0rjcy.js +7846 -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 +8419 -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 +313 -0
- package/dist/reference/storage.md +90 -0
- package/dist/rendering.d.ts +188 -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 +63 -4
package/dist/audio.d.ts
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { type AssetLoader, type LoadedAsset, type MusicAsset, type SoundAsset } from "./assets.js";
|
|
2
|
+
export type AudioElementLike = {
|
|
3
|
+
src: string;
|
|
4
|
+
loop: boolean;
|
|
5
|
+
currentTime: number;
|
|
6
|
+
volume: number;
|
|
7
|
+
duration: number;
|
|
8
|
+
paused?: boolean;
|
|
9
|
+
play(): Promise<void> | void;
|
|
10
|
+
pause(): void;
|
|
11
|
+
addEventListener(type: "ended", listener: () => void): void;
|
|
12
|
+
removeEventListener(type: "ended", listener: () => void): void;
|
|
13
|
+
};
|
|
14
|
+
export type AudioElementFactory = (url: string) => AudioElementLike;
|
|
15
|
+
export declare class AudioUnlockState {
|
|
16
|
+
private unlocked;
|
|
17
|
+
isUnlocked(): boolean;
|
|
18
|
+
markUnlocked(): void;
|
|
19
|
+
}
|
|
20
|
+
export declare const audioUnlock: AudioUnlockState;
|
|
21
|
+
export type BrowserSoundDebugState = {
|
|
22
|
+
readonly active: boolean;
|
|
23
|
+
readonly loop: boolean;
|
|
24
|
+
readonly volume: number;
|
|
25
|
+
readonly unlocked: boolean;
|
|
26
|
+
readonly lastError: string | null;
|
|
27
|
+
};
|
|
28
|
+
export type BrowserSoundOptions = {
|
|
29
|
+
readonly createAudioElement?: AudioElementFactory;
|
|
30
|
+
readonly unlockState?: AudioUnlockState;
|
|
31
|
+
readonly volume?: number;
|
|
32
|
+
};
|
|
33
|
+
export declare class BrowserSoundAsset implements SoundAsset {
|
|
34
|
+
readonly kind: "sound";
|
|
35
|
+
readonly name: string;
|
|
36
|
+
readonly url: string;
|
|
37
|
+
readonly bytes?: ArrayBuffer;
|
|
38
|
+
private readonly createElement;
|
|
39
|
+
private readonly unlockState;
|
|
40
|
+
private readonly activeInstances;
|
|
41
|
+
private metadataElement;
|
|
42
|
+
private volumeValue;
|
|
43
|
+
private lastErrorMessage;
|
|
44
|
+
constructor(asset: LoadedAsset, options?: BrowserSoundOptions);
|
|
45
|
+
play(loops?: number): void;
|
|
46
|
+
loop(): void;
|
|
47
|
+
stop(): void;
|
|
48
|
+
getLength(): number;
|
|
49
|
+
setVolume(volume: number): void;
|
|
50
|
+
getVolume(): number;
|
|
51
|
+
debugState(): BrowserSoundDebugState;
|
|
52
|
+
/** Number of currently overlapping playback instances of this sound. */
|
|
53
|
+
debugInstanceCount(): number;
|
|
54
|
+
private handleInstanceEnded;
|
|
55
|
+
private firstActiveElement;
|
|
56
|
+
private getMetadataElement;
|
|
57
|
+
private playElement;
|
|
58
|
+
private removeInstance;
|
|
59
|
+
}
|
|
60
|
+
export declare function createBrowserSoundAsset(asset: LoadedAsset, options?: BrowserSoundOptions): BrowserSoundAsset;
|
|
61
|
+
export type MusicMode = "loop" | "once";
|
|
62
|
+
export type MusicPlayerOptions = {
|
|
63
|
+
readonly loader?: AssetLoader<MusicAsset>;
|
|
64
|
+
readonly createAudioElement?: AudioElementFactory;
|
|
65
|
+
readonly onMusicEnd?: () => void;
|
|
66
|
+
readonly onError?: (error: unknown) => void;
|
|
67
|
+
readonly scheduler?: TimeoutScheduler;
|
|
68
|
+
readonly volume?: number;
|
|
69
|
+
};
|
|
70
|
+
export type TimeoutScheduler = {
|
|
71
|
+
setTimeout(callback: () => void, delayMs: number): unknown;
|
|
72
|
+
clearTimeout(handle: unknown): void;
|
|
73
|
+
};
|
|
74
|
+
export type MusicDebugState = {
|
|
75
|
+
readonly current: string | null;
|
|
76
|
+
readonly queued: readonly string[];
|
|
77
|
+
readonly isPlaying: boolean;
|
|
78
|
+
readonly volume: number;
|
|
79
|
+
readonly lastError: string | null;
|
|
80
|
+
};
|
|
81
|
+
export declare class MusicPlayer {
|
|
82
|
+
private loaderValue;
|
|
83
|
+
private readonly createElement;
|
|
84
|
+
private readonly scheduler;
|
|
85
|
+
private currentTrack;
|
|
86
|
+
private queuedNames;
|
|
87
|
+
private onEnd;
|
|
88
|
+
private readonly onError;
|
|
89
|
+
private fadeoutHandles;
|
|
90
|
+
private volumeValue;
|
|
91
|
+
private lastErrorMessage;
|
|
92
|
+
private operationGeneration;
|
|
93
|
+
private pendingStart;
|
|
94
|
+
constructor(options?: MusicPlayerOptions);
|
|
95
|
+
play(name: string): Promise<void>;
|
|
96
|
+
playOnce(name: string): Promise<void>;
|
|
97
|
+
queue(name: string): Promise<void>;
|
|
98
|
+
stop(): void;
|
|
99
|
+
pause(): void;
|
|
100
|
+
unpause(): void;
|
|
101
|
+
/** Restarts the current track from the beginning (pygame.mixer.music.rewind). */
|
|
102
|
+
rewind(): void;
|
|
103
|
+
/**
|
|
104
|
+
* Milliseconds the current track has been playing for, or -1 if nothing
|
|
105
|
+
* is loaded (matches pygame.mixer.music.get_pos()).
|
|
106
|
+
*/
|
|
107
|
+
getPos(): number;
|
|
108
|
+
/**
|
|
109
|
+
* Seconds into the current track (0 when nothing is loaded); set it to
|
|
110
|
+
* jump there. Unlike `getPos()`, which reports milliseconds for Pygame
|
|
111
|
+
* compatibility, this reads and writes the same unit.
|
|
112
|
+
*/
|
|
113
|
+
get position(): number;
|
|
114
|
+
set position(seconds: number);
|
|
115
|
+
/** Seeks the current track to the given position in seconds. */
|
|
116
|
+
setPos(seconds: number): void;
|
|
117
|
+
fadeOut(seconds: number): void;
|
|
118
|
+
setVolume(volume: number): void;
|
|
119
|
+
getVolume(): number;
|
|
120
|
+
/**
|
|
121
|
+
* True if music is currently playing (and not paused). Accepts and
|
|
122
|
+
* ignores an optional track name argument, matching pgzero's
|
|
123
|
+
* `music.is_playing(name)` signature.
|
|
124
|
+
*/
|
|
125
|
+
isPlaying(_name?: string): boolean;
|
|
126
|
+
setOnMusicEnd(callback: (() => void) | undefined): void;
|
|
127
|
+
debugState(): MusicDebugState;
|
|
128
|
+
debugCurrentElement(): AudioElementLike | null;
|
|
129
|
+
private get loader();
|
|
130
|
+
/**
|
|
131
|
+
* Starts loading and playing a track, reporting (but never throwing past
|
|
132
|
+
* `play`/`playOnce`) load failures. Returns whether the track actually
|
|
133
|
+
* started, so callers that need to react to a failure — like queue
|
|
134
|
+
* advancement — can do so without relying on a rejected promise.
|
|
135
|
+
*/
|
|
136
|
+
private beginTrackStart;
|
|
137
|
+
private startTrack;
|
|
138
|
+
private playNextQueuedTrack;
|
|
139
|
+
private handleTrackEnded;
|
|
140
|
+
private playElement;
|
|
141
|
+
private reportError;
|
|
142
|
+
private replacePlayback;
|
|
143
|
+
private disposeCurrent;
|
|
144
|
+
private clearFadeout;
|
|
145
|
+
}
|
|
146
|
+
export declare function createMusicPlayer(options?: MusicPlayerOptions): MusicPlayer;
|
|
147
|
+
export declare function setActiveMusicPlayer(nextMusicPlayer: MusicPlayer | null): MusicPlayer | null;
|
|
148
|
+
export declare function getActiveMusicPlayer(): MusicPlayer;
|
|
149
|
+
export declare const music: MusicPlayer;
|
|
150
|
+
export declare function clampVolume(volume: number): number;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { FontAsset, MusicAsset, SoundAsset, SurfaceLike } from "./assets.js";
|
|
2
|
+
export declare const fontExtensions: readonly ["ttf", "otf", "woff", "woff2"];
|
|
3
|
+
export declare function loadBrowserImage(url: string, createSurface: (image: HTMLImageElement) => SurfaceLike): Promise<SurfaceLike>;
|
|
4
|
+
export declare function loadSoundAsset(url: string, name: string): Promise<SoundAsset>;
|
|
5
|
+
export declare function loadMusicAsset(url: string, name: string): Promise<MusicAsset>;
|
|
6
|
+
export declare function loadFontAsset(url: string, name: string): Promise<FontAsset>;
|
|
7
|
+
/** The bytes of a `data:` URL, base64 or percent-encoded. */
|
|
8
|
+
export declare function decodeDataUrl(url: string): ArrayBuffer;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type * as hostApi from "./host.js";
|
|
2
|
+
import * as framework from "./index.js";
|
|
3
|
+
type Host = Pick<typeof hostApi, "createSeededRandom" | "getGameInspector" | "loadImages" | "parseStatePath" | "serializeGameValue">;
|
|
4
|
+
declare const host: Host;
|
|
5
|
+
declare global {
|
|
6
|
+
interface Window {
|
|
7
|
+
JGZ?: typeof framework & typeof host;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export * from "./index.js";
|