/** * THE SOUNDS OF A CARD TABLE: a card dealt, turned over, played, the deck * shuffled, a pile gathered in, a hand fanned. The recordings are real cards * (Kenney's Casino Audio, CC0; see docs/credits.md), loaded the first time a * sound is played and never before, so a page that stays silent never fetches * them. Where they cannot be loaded or decoded, a short sound made in the * browser stands in. Nothing here throws: a platform with no audio, a context * the browser holds still, or a failed decode is simply silent. * * Toranpu never makes a sound by itself. A table asks for one with `play`. */ /** Every kind of sound, in the order a game meets them. * * @example * ```ts * import { CARD_SOUND_KINDS } from "@johnmorrisdotca/toranpu/card-sounds"; * console.log(CARD_SOUND_KINDS); * ``` */ export declare const CARD_SOUND_KINDS: readonly ["shuffle", "deal", "flip", "play", "gather", "fan"]; /** One kind of sound: `deal` a card sent to a hand, `flip` a card turned over, `play` a card laid on the table, `shuffle` the deck shuffled, `gather` a pile swept in, `fan` a hand spread open. * * @example * ```ts * import type { CardSoundKind } from "@johnmorrisdotca/toranpu/card-sounds"; * * const value: CardSoundKind = "play"; * console.log(value); * ``` */ export type CardSoundKind = (typeof CARD_SOUND_KINDS)[number]; /** The recordings, by name (`deal-2`), as base64 AAC. * * @example * ```ts * import type { CardSoundData } from "@johnmorrisdotca/toranpu/card-sounds"; * * const value: CardSoundData = {}; * console.log(Object.keys(value)); * ``` */ export type CardSoundData = Readonly>; /** The parts of a window the sounds use: an audio context and `atob`. Any of them may be missing. * * @example * ```ts * import type { CardSoundWindow } from "@johnmorrisdotca/toranpu/card-sounds"; * * const value: CardSoundWindow = {}; * console.log(value.AudioContext === undefined); * ``` */ export type CardSoundWindow = { AudioContext?: typeof AudioContext; webkitAudioContext?: typeof AudioContext; atob?: (text: string) => string; }; /** How a table's sounds are made. Every field may be left out. * * @example * ```ts * import type { CardSoundsOptions } from "@johnmorrisdotca/toranpu/card-sounds"; * * const value: CardSoundsOptions = { muted: true, volume: 0.5, window: null }; * console.log(value.volume); * ``` */ export type CardSoundsOptions = { /** Start muted: nothing plays, and nothing is fetched, until `setMuted(false)`. Unless said, not muted. */ muted?: boolean; /** How loud, from 0 to 1. Unless said, 0.6. */ volume?: number; /** Where the recordings come from: the package's own module unless another is handed in. */ load?: () => Promise<{ CARD_SOUND_DATA: CardSoundData; }>; /** The window to make sound in: the page's own unless another is handed in (a test's, or none for silence). */ window?: CardSoundWindow | null; }; /** How one sound is played. * * @example * ```ts * import type { PlayCardSoundOptions } from "@johnmorrisdotca/toranpu/card-sounds"; * * const value: PlayCardSoundOptions = { count: 3, gap: 80, delay: 20 }; * console.log(value.count); * ``` */ export type PlayCardSoundOptions = { /** How many cards: `deal` with 13 is thirteen cards dealt one after another (heard as at most `MOST_SOUNDS_AT_ONCE`). Unless said, one. */ count?: number; /** Milliseconds between one card's sound and the next. Unless said, 85. */ gap?: number; /** Milliseconds to wait before the first. Unless said, none. */ delay?: number; }; /** A table's sounds: `play` one, mute and unmute, change the volume, `close` when the table goes. * * @example * ```ts * import type { CardSounds } from "@johnmorrisdotca/toranpu/card-sounds"; * import { createCardSounds } from "@johnmorrisdotca/toranpu/card-sounds"; * * const value: CardSounds = createCardSounds({ muted: true, window: null }); * console.log(value.muted); * ``` */ export type CardSounds = { /** Play a sound, or several of one kind in a row; nothing while muted or closed. */ play(kind: CardSoundKind, options?: PlayCardSoundOptions): void; /** Fetch and decode the recordings now, rather than at the first sound. True once they are ready; false where they cannot be had. */ load(): Promise; /** Whether it is muted. */ readonly muted: boolean; /** Mute or unmute. Muting stops nothing already playing; it only keeps anything new from starting. */ setMuted(muted: boolean): void; /** How loud, from 0 to 1. */ volume: number; /** Stop for good, and let the audio context go. */ close(): void; }; /** As many sounds as one call plays: thirteen cards dealt are eight slides, not a wall of noise. * * @example * ```ts * import { MOST_SOUNDS_AT_ONCE } from "@johnmorrisdotca/toranpu/card-sounds"; * console.log(MOST_SOUNDS_AT_ONCE); * ``` */ export declare const MOST_SOUNDS_AT_ONCE = 8; /** When each of `count` sounds starts, in milliseconds from the first: one every `gap`, and no more than `MOST_SOUNDS_AT_ONCE`, spread over the same time. * * @param count - The requested number of cards, sounds or layout positions. * @param gap - Milliseconds between successive sounds. * @returns When each of `count` sounds starts, in milliseconds from the first: one every `gap`, and no more than `MOST_SOUNDS_AT_ONCE`, spread over the same time. * * @example * ```ts * import { soundTimes } from "@johnmorrisdotca/toranpu/card-sounds"; * * console.log(soundTimes(5, 80)); * ``` */ export declare function soundTimes(count: number, gap?: number): number[]; /** A table's card sounds. Nothing is fetched and no audio context is made until the first sound. * * @param options - Options for this call; omitted fields retain their documented defaults. * @returns A table's card sounds. Nothing is fetched and no audio context is made until the first sound. * * @example * ```ts * import { createCardSounds } from "@johnmorrisdotca/toranpu/card-sounds"; * * console.log(createCardSounds({ muted: true, window: null }).muted); * ``` */ export declare function createCardSounds(options?: CardSoundsOptions): CardSounds;