UNPKG

rune-sdk

Version:

Build a multiplayer game played by millions! Your game runs inside the Rune app with 10 million installs across [iOS](https://apps.apple.com/app/rune-games-and-voice-chat/id1450358364) and [Android](https://play.google.com/store/apps/details?id=ai.rune.ti

508 lines (498 loc) 14.5 kB
/* Copyright (c) 2024 Rune AI Inc. All rights reserved. This code is proprietary to Rune AI Inc. The code may be used solely for accessing the Service provided by Rune AI Inc. following the Rune AI Inc. Terms of Service ("Terms") accessible at rune.ai/eula. You may not use this code for any use or purpose other than as expressly permitted by the Terms. Restrictions set forth in the Terms include, but is not limited to, that you may not copy, adapt, modify, prepare derivative works based upon, distribute, license, sell, transfer, publicly display, publicly perform, transmit, stream, broadcast, attempt to discover any source code, reverse engineer, decompile, dissemble, or otherwise exploit the code as a whole or any portion of the code. */ type GameId = number; type PlayerId = string; type Player = { playerId: PlayerId; displayName: string; avatarUrl: string; }; type Players = Record<PlayerId, Player>; type Base64Png = string; type LogInfo = { devDash: null; } | { devDash: { type: "CLIENT" | "LOGIC"; userType?: "UNKNOWN" | "PLAYER" | "SPECTATOR"; }; }; type ServerErrorMessage = keyof typeof errorMap; declare const errorMap: { SERVER_UPDATE_LOOP_FASTER_THAN_GAME_TIME: { devUIUnexpected: true; logInfo: { devDash: null; }; }; GET_GAME_STATE_FAILED: { devUIUnexpected: true; logInfo: { devDash: null; }; }; SERVER_RECEIVED_MESSAGE_TOO_BIG: { devUIUnexpected: true; logInfo: { devDash: null; }; }; SERVER_MESSAGE_TO_CLIENTS_TOO_BIG: { devUIUnexpected: true; logInfo: { devDash: null; }; }; SERVER_FULL: { devUIUnexpected: true; logInfo: { devDash: null; }; }; ON_PLAYER_JOINED_CALLBACK_MISSING: { devUIUnexpected: true; logInfo: { devDash: null; }; }; ROOM_GAME_STATE_MISSING: { devUIUnexpected: true; logInfo: { devDash: null; }; }; PERSIST_DATA_AFTER_ERROR_NOT_AVAILABLE: { devUIUnexpected: true; logInfo: { devDash: null; }; }; GET_PERSISTED_STATE_FAILED: { devUIUnexpected: true; logInfo: { devDash: null; }; }; GAME_END_PERSIST_USER_NOT_FOUND: { devUIUnexpected: true; logInfo: { devDash: null; }; }; PLAYER_LEFT_NO_USERS_INCORRECT_PERSISTED_PLAYERS: { devUIUnexpected: true; logInfo: { devDash: null; }; }; PERSISTED_STATE_NOT_ENABLED: { devUIUnexpected: true; logInfo: { devDash: null; }; }; UPDATE_LOOP_BEHIND_GAME_TIME: { devUIMessage: string; logInfo: { devDash: null; }; }; AI_PROMPT_REQUEST_FAILED: { devUIUnexpected: true; logInfo: { devDash: null; }; }; ACTION_PARAMS_SIZE_OVER_LIMIT: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); PLAYER_JOINED_FAILED: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); PLAYER_LEFT_FAILED: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); AI_PROMPT_RESPONSE_FAILED: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); ACTION_TRIGGERED_IN_LOGIC: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); STATE_SYNC_TOO_BIG: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); GAME_OVER_INVALID_OPTIONS: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); SERVER_UPDATE_LOOP_FAILED: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); ACTION_FAILED: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); SETUP_GAME_OVER_NOT_ALLOWED: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); SETUP_FAILED: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); PERSISTED_STATE_USED_WITHOUT_FLAG: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); SETUP_PERSISTED_KEY_NOT_ALLOWED: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); PERSISTED_NOT_AN_OBJECT: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); PERSISTED_KEY_MISSING: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); PERSISTED_EXTRA_KEY_DETECTED: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); PERSISTED_PLAYER_MISSING: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); PERSISTED_PLAYER_NOT_AN_OBJECT: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); PERSISTED_PLAYER_OVER_LIMIT: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); AI_PROMPT_RESPONSE_NOT_DEFINED: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); AI_PROMPT_REQUEST_PARAM_WRONG_FORMAT: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); }; type GameOverResult = "WON" | "LOST" | "TIE" | number; type GameOverOptions = { delayPopUp?: boolean; minimizePopUp?: boolean; } & ({ players: { [playerId: PlayerId]: GameOverResult; }; everyone?: never; } | { players?: never; everyone: GameOverResult; }); type GameOverGameEnded = { reason: "gameEnded"; options: GameOverOptions; }; type GameOverPlayerLeft = { reason: "playerLeft"; }; type GameOverMinPlayers = { reason: "minPlayers"; }; type GameOverError = { reason: "err"; err?: { message: ServerErrorMessage; data?: object; }; }; type GameOverContext = (GameOverMinPlayers | GameOverPlayerLeft | GameOverGameEnded | GameOverError) & { players: Players; }; type ClientToGame = { type: "setForceMuteStatus"; muted: boolean; } | { type: "setDebugOverlayStatus"; enabled: boolean; } | { type: "DISCONNECTED"; } | { type: "READY_TO_REQUEST_STATE_SYNC"; } | { type: "CLIPBOARD_WRITE_RES"; reqId: string; success: boolean; } | { type: "CLIPBOARD_READ_RES"; reqId: string; text: string | null; } | { type: "STORAGE_WRITE_RES"; reqId: string; success: boolean; } | { type: "STORAGE_READ_RES"; reqId: string; value: string | null; }; type GameToClient = { type: "INIT"; version: string; } | { type: "ERR"; msg: string; err?: string; errInfo: object; stack?: string; } | { type: "WARNING"; msg: string; data?: unknown; } | { type: "INFO"; msg: string; data?: unknown; } | { type: "WINDOW_ERR"; err: { msg: string; filename: string; lineno: number; colno: number; stack?: string; }; } | { type: "WINDOW_ALERT"; message: string; } | { type: "BROWSER_INITIAL_OVERLAY_CLICKED"; } | { type: "BROWSER_IFRAME_LOADED"; } | { type: "GAME_OVER"; context: GameOverContext; } | { type: "OPEN_EXTERNAL_APP"; url: string; } | { type: "CLIPBOARD_WRITE_REQ"; reqId: string; text: string; } | { type: "CLIPBOARD_READ_REQ"; reqId: string; } | { type: "STORAGE_WRITE_REQ"; reqId: string; key: string; value: string; } | { type: "STORAGE_READ_REQ"; reqId: string; key: string; } | { type: "SHOW_GAME_OVER_POP_UP"; } | { type: "SHOW_INVITE_SHEET"; } | { type: "SHOW_SHARE_IMAGE"; img: Base64Png | null; } | { type: "ON_STATE_SYNC"; } | { type: "ON_CHANGE"; } | { type: "FPS_STATS"; min: number; max: number; avg: number; } | { type: "FPS_WARNING"; fps: number; isLowFps: boolean; }; type StaticLogInfo = { gameId: GameId; gameVersionId: number; isGameMsg: true; }; type GameToClientWithGameInfo = GameToClient & { gameId: GameId; logInfo: LogInfo & StaticLogInfo; }; type GameClient = { onServerMsg: (msg: string) => void; onGameMsg: (msg: string) => void; onDisconnected: () => void; onConnected: () => void; sendMsgToGame: (msg: ClientToGame) => void; stop: () => void; }; type NetworkClient = { sendMsgToServer: (msg: string) => void; sendMsgToGame: (msg: string) => void; }; type ClientProtocolVersion = number; type OnGameStateChangedStates = { state: "LOADING"; } | { state: "PLAYING"; } | { state: "ERR"; } | { state: "GAME_OVER"; context: GameOverContext; }; declare function createGameClient({ network, onGameToClientPayload, onGameStateChanged, onReloadRequested, gameId, clientProtocolVersion, }: { network: NetworkClient; onGameToClientPayload: (gameToClient: GameToClientWithGameInfo) => void; onGameStateChanged: (state: OnGameStateChangedStates) => void; onReloadRequested: () => void; gameId: number; clientProtocolVersion: ClientProtocolVersion; }): GameClient; export { GameOverContext, GameOverOptions, GameOverResult, OnGameStateChangedStates, createGameClient };