lab13-sdk
Version:
JS13K tools and game infrastructure SDK.
198 lines (197 loc) • 10.9 kB
TypeScript
import PartySocket, { PartySocket as PartySocket$1 } from "partysocket";
//#region src/audio/player.d.ts
type Part = string;
type Song = Part[];
type MusicPlayerOptions = {
noteLengthMs: number;
loop?: boolean;
volume?: number;
baseNote?: string;
onNotesPlayed?: (col: number) => void;
};
declare const noteToFrequency: (note: string, baseNote?: string, baseFreq?: number) => number;
declare const playSingleNote: (audioContext: AudioContext, frequency: number, start: number, options?: {
noteLengthMs?: number;
volume?: number;
}) => void;
declare const createSongPlayer: (song: Song) => {
play: (options?: Partial<MusicPlayerOptions>) => void;
stop: () => void;
};
type MusicPlayer = ReturnType<typeof createSongPlayer>;
//#endregion
//#region src/demo/index.d.ts
type DemoOptions = {
iframeWidth?: number;
iframeHeight?: number;
buttonText?: string;
buttonStyle?: Partial<CSSStyleDeclaration>;
containerStyle?: Partial<CSSStyleDeclaration>;
iframeStyle?: Partial<CSSStyleDeclaration>;
};
declare const useDemo: (options?: Partial<DemoOptions>) => {
isDemoMode: boolean;
addIframe?: undefined;
container?: undefined;
addButton?: undefined;
sizeSlider?: undefined;
resizeAllIframes?: undefined;
} | {
isDemoMode: boolean;
addIframe: () => void;
container: HTMLDivElement;
addButton: HTMLButtonElement;
sizeSlider: HTMLDivElement;
resizeAllIframes: () => void;
};
//#endregion
//#region src/online/command.d.ts
declare const onCommandMessage: (command: string, callback: (data: string) => void, socket?: any) => void;
declare const sendCommandMessageToClient: (clientId: string, command: string, data: string, socket?: any) => void;
declare const sendCommandMessageToAll: (command: string, data: string, socket?: any) => void;
declare const labCommand: (command: string) => string;
//#endregion
//#region src/online/core-events.d.ts
declare const onClientJoined: (callback: (clientId: string) => void, socket?: any) => void;
declare const onClientLeft: (callback: (clientId: string) => void, socket?: any) => void;
declare const onClientIdUpdated: (callback: (myClientId: string) => void, socket?: any) => void;
//#endregion
//#region src/online/deepCopy.d.ts
declare const deepCopy: <T extends object>(obj: T) => T;
//#endregion
//#region src/online/generateUUID.d.ts
declare const generateUUID: () => string;
//#endregion
//#region src/online/message.d.ts
declare const sendMessage: (message: string, socket?: any) => void;
declare const sendMessageToClient: (clientId: string, message: string, socket?: any) => void;
//#endregion
//#region src/online/myId.d.ts
type UseMyIdOptions = {
socket?: PartySocket$1;
};
declare const useMyId: (options?: Partial<UseMyIdOptions>) => {
getMyId: () => string;
};
declare const onMyIdUpdated: (callback: (myClientId: string) => void, socket?: any) => void;
//#endregion
//#region src/online/presence.d.ts
declare const sendIdentToClient: (recipientClientId: string, clientId: string, socket?: any) => void;
declare const onIdentReceived: (callback: (fromClientId: string) => void, socket?: any) => void;
declare const usePresence: (socket?: any) => void;
//#endregion
//#region src/online/socket.d.ts
declare const onOpen: (callback: () => void, socket?: any) => void;
declare const onClose: (callback: () => void, socket?: any) => void;
declare const onError: (callback: () => void, socket?: any) => void;
//#endregion
//#region src/online/state/merge.d.ts
type PartialDeep<T> = { [P in keyof T]?: T[P] extends object ? PartialDeep<T[P]> : T[P] };
type PartialStructWithNullPropsDeep<T> = { [P in keyof T]?: T[P] extends object ? PartialStructWithNullPropsDeep<T[P]> | null : T[P] | null };
declare const PRIVATE_KEY_PREFIX = "_";
type PrivateKeyPrefix = typeof PRIVATE_KEY_PREFIX;
type PrivateKey = `${PrivateKeyPrefix}${string}`;
declare const PRIVATE_KEY_COLLECTION_KEY: PrivateKey;
declare const ENTITY_COLLECTION_PREFIX = "@";
type EntityCollectionPrefix = typeof ENTITY_COLLECTION_PREFIX;
type EntityCollectionKey = `${EntityCollectionPrefix}${string}`;
type PlayerEntityCollectionKey = `${EntityCollectionPrefix}players`;
declare const PLAYER_ENTITY_COLLECTION_KEY: PlayerEntityCollectionKey;
declare function mergeDeep<T extends Record<string, any>>(target: T, delta: PartialStructWithNullPropsDeep<T>, deleteNulls?: boolean, parentKey?: string): PartialStructWithNullPropsDeep<T>;
//#endregion
//#region src/online/state/copier.d.ts
declare const createMyStateCopier: (myIdGetter: () => string | null) => <TStateShape extends StateBase>(currentState: PartialDeep<TStateShape>, newState: PartialDeep<TStateShape>) => PartialDeep<TStateShape>;
//#endregion
//#region src/online/state/normalize.d.ts
declare const round: (n: number, precision?: number) => number;
declare const normalizeRad: (n: number) => number;
declare const normalizeDeg: (n: number) => number;
type NormalizeFn = (obj: any, key: string, value: any, parentKeys: string[]) => any;
declare const createKeyNormalizer: (normalizeFn: NormalizeFn) => <T extends Record<string, any>>(target: T, parentKeys?: string[]) => T;
declare const createPositionNormalizer: <TState extends Record<string, any>>(precision?: number) => <T extends Record<string, any>>(target: T, parentKeys?: string[]) => T;
declare const createVelocityNormalizer: <TState extends Record<string, any>>(precision?: number) => <T extends Record<string, any>>(target: T, parentKeys?: string[]) => T;
declare const createRotationNormalizer: <TState extends Record<string, any>>(precision?: number, useDegrees?: boolean) => <T extends Record<string, any>>(target: T, parentKeys?: string[]) => T;
//#endregion
//#region src/online/state/onStateDeltaMessage.d.ts
declare const onStateDeltaMessage: <TStateShape extends StateBase>(callback: (delta: StateDelta<TStateShape>) => void, socket?: any) => void;
//#endregion
//#region src/online/state/onStateMessage.d.ts
declare const onStateMessage: <TStateShape extends StateBase>(callback: (state: TStateShape) => void, socket?: any) => void;
//#endregion
//#region src/online/state/useEasyState.d.ts
type UseEasyStateOptions<TStateShape extends StateBase> = {
positionPrecision?: number;
rotationPrecision?: number;
rotationUnits?: 'd' | 'r';
onPlayerStateAvailable?: (id: string, state: TStateShape[PlayerEntityCollectionKey][string]) => void;
} & StateOptions<TStateShape>;
declare const useEasyState: <TStateShape extends StateBase>(options?: Partial<UseEasyStateOptions<TStateShape>>) => {
getState: (copy?: boolean) => PartialDeep<TStateShape>;
getMyState: (copy?: boolean) => PartialDeep<TStateShape["@players"][string]> | null;
getPlayerStates: (copy?: boolean) => PartialDeep<TStateShape["@players"]>;
getPlayerState: (clientId: string, copy?: boolean) => PartialDeep<TStateShape["@players"][string]> | null;
updateMyState: (delta: PartialStructWithNullPropsDeep<TStateShape["@players"][string]>) => void;
updatePlayerState: (clientId: string, delta: PartialStructWithNullPropsDeep<TStateShape["@players"][string]> | null) => void;
updateState: (delta: PartialStructWithNullPropsDeep<TStateShape>, send?: boolean) => void;
};
//#endregion
//#region src/online/state/useState.d.ts
type StateBase<TPlayerState = Record<string, any>> = {
[PLAYER_ENTITY_COLLECTION_KEY]: {
[key: string]: TPlayerState;
};
};
type StateDelta<T extends StateBase> = PartialStructWithNullPropsDeep<T>;
type StateOptions<TStateShape extends StateBase> = {
onBeforeSendState?: (state: PartialDeep<TStateShape>) => PartialDeep<TStateShape>;
onStateReceived?: (currentState: PartialDeep<TStateShape>, newState: PartialDeep<TStateShape>) => PartialDeep<TStateShape>;
onBeforeSendDelta?: (delta: StateDelta<TStateShape>) => StateDelta<TStateShape>;
onDeltaReceived?: (delta: StateDelta<TStateShape>) => StateDelta<TStateShape>;
onAfterStateUpdated?: (state: PartialDeep<TStateShape>, delta: StateDelta<TStateShape>) => void;
socket?: PartySocket$1;
deltaThrottleMs?: number;
debug?: boolean;
};
declare const useState: <TStateShape extends StateBase>(options?: Partial<StateOptions<TStateShape>>) => {
getState: (copy?: boolean) => PartialDeep<TStateShape>;
getMyState: (copy?: boolean) => PartialDeep<TStateShape[PlayerEntityCollectionKey][string]> | null;
getPlayerStates: (copy?: boolean) => PartialDeep<TStateShape[PlayerEntityCollectionKey]>;
getPlayerState: (clientId: string, copy?: boolean) => PartialDeep<TStateShape[PlayerEntityCollectionKey][string]> | null;
updateMyState: (delta: PartialStructWithNullPropsDeep<TStateShape[PlayerEntityCollectionKey][string]>) => void;
updatePlayerState: (clientId: string, delta: PartialStructWithNullPropsDeep<TStateShape[PlayerEntityCollectionKey][string]> | null) => void;
updateState: (delta: PartialStructWithNullPropsDeep<TStateShape>, send?: boolean) => void;
};
//#endregion
//#region src/online/useOnline.d.ts
type OnlineOptions = {
host?: string;
global?: boolean;
};
declare const useOnline: (room: string, options?: Partial<OnlineOptions>) => PartySocket;
//#endregion
//#region src/w/useKeyboard.d.ts
declare const useKeyboard: () => {
getKeys: () => {
[key: string]: boolean;
};
isKeyPressed: (key: string) => boolean | undefined;
};
//#endregion
//#region src/w/usePointerLock.d.ts
type PointerLockOptions = {
onMove: (e: MouseEvent) => void;
element: HTMLElement;
};
declare const usePointerLock: (options?: Partial<PointerLockOptions>) => void;
//#endregion
//#region src/w/useResizer.d.ts
declare const useResizer: () => void;
//#endregion
//#region src/w/useSpeedThrottledRaf.d.ts
declare const useSpeedThrottledRaf: (moveSpeed: number, moveFunction: (speed: number) => void) => void;
//#endregion
//#region src/w/useW.d.ts
declare const useW: () => void;
//#endregion
export { DemoOptions, ENTITY_COLLECTION_PREFIX, EntityCollectionKey, EntityCollectionPrefix, MusicPlayer, MusicPlayerOptions, OnlineOptions, PLAYER_ENTITY_COLLECTION_KEY, PRIVATE_KEY_COLLECTION_KEY, PRIVATE_KEY_PREFIX, Part, PartialDeep, PartialStructWithNullPropsDeep, PlayerEntityCollectionKey, PointerLockOptions, PrivateKey, PrivateKeyPrefix, Song, StateBase, StateDelta, StateOptions, UseEasyStateOptions, UseMyIdOptions, createKeyNormalizer, createMyStateCopier, createPositionNormalizer, createRotationNormalizer, createSongPlayer, createVelocityNormalizer, deepCopy, generateUUID, labCommand, mergeDeep, normalizeDeg, normalizeRad, noteToFrequency, onClientIdUpdated, onClientJoined, onClientLeft, onClose, onCommandMessage, onError, onIdentReceived, onMyIdUpdated, onOpen, onStateDeltaMessage, onStateMessage, playSingleNote, round, sendCommandMessageToAll, sendCommandMessageToClient, sendIdentToClient, sendMessage, sendMessageToClient, useDemo, useEasyState, useKeyboard, useMyId, useOnline, usePointerLock, usePresence, useResizer, useSpeedThrottledRaf, useState, useW };
//# sourceMappingURL=index.d.ts.map