/** * @metaarena/sdk 타입 정의 */ /** onStart() 콜백으로 전달되는 게임 시작 컨텍스트 */ interface GameStartContext { /** 현재 토너먼트 UUID */ tournamentId: string; /** 플레이어 JWT — 서버 사이드 게임에서 서버로 전달해 점수 제출 시 사용 */ playerToken: string; /** MetaArena API 베이스 URL (환경별 자동 설정) */ apiBase: string; } /** gameOver() 에 전달하는 페이로드 */ interface GameOverPayload { /** 최종 점수 (0 이상 정수) */ score: number; /** 총 플레이 시간 (밀리초). 서버 범위 검증에 활용되므로 포함 권장 */ playTimeMs?: number; } interface GameStartMessage { type: 'METAARENA_GAME_START'; tournament_id: string; player_token: string; api_base?: string; } interface ReadyMessage { type: 'METAARENA_READY'; } interface ScoreMessage { type: 'METAARENA_SCORE'; score: number; } interface GameOverMessage { type: 'METAARENA_GAME_OVER'; score: number; play_time_ms?: number; } type OutboundMessage = ReadyMessage | ScoreMessage | GameOverMessage; type InboundMessage = GameStartMessage; /** SDK 에러 */ declare class SDKError extends Error { readonly code: string; constructor(message: string, code: string); } /** * MetaArenaSDK — 메인 클래스 * * 브라우저에서 동작하는 게임(iframe)이 MetaArena 플랫폼과 통신하는 SDK입니다. * API Key / Secret은 필요 없습니다 — 클라이언트 사이드 점수 제출은 플랫폼이 처리합니다. * * @example * ```typescript * import { MetaArenaSDK } from '@metaarena/sdk' * * const sdk = new MetaArenaSDK() * * sdk.onStart(({ tournamentId, playerToken }) => { * // playerToken: 서버 사이드 게임이라면 게임 서버로 전달 * startGame() * }) * * sdk.updateScore(currentScore) // HUD 업데이트 * * sdk.gameOver({ score: currentScore, playTimeMs: elapsed }) * ``` */ declare const SDK_VERSION = "1.0.0"; declare class MetaArenaSDK { private messenger; private startCallbacks; constructor(); /** * 게임 시작 신호 수신 핸들러 등록 * 플랫폼이 METAARENA_GAME_START를 전송하면 호출됩니다. */ onStart(callback: (ctx: GameStartContext) => void): void; /** * 현재 점수를 플랫폼 HUD에 실시간 반영 * 점수가 바뀔 때마다 호출합니다. 이 메서드만으로는 점수가 제출되지 않습니다. */ updateScore(score: number): void; /** * 게임 종료 처리 * * - 플랫폼에 GAME_OVER 신호를 전송해 게임 오버 모달을 표시합니다. * - 클라이언트 사이드 게임: 플랫폼이 자동으로 MetaArena API에 점수를 제출합니다. * - 서버 사이드 게임: UI 표시만 수행하며, 점수 제출은 게임 서버에서 직접 처리합니다. */ gameOver({ score, playTimeMs }: GameOverPayload): void; /** SDK 및 이벤트 리스너 정리 */ destroy(): void; } /** * postMessage 기반 iframe ↔ 플랫폼 통신 모듈 * * 게임(iframe)과 MetaArena 플랫폼(부모 창) 사이의 메시지 교환을 담당합니다. * SDK 내부에서만 사용합니다. */ /** * 플랫폼(호스트) 측 헬퍼 — 게임 iframe으로 GAME_START를 전송할 때 사용 * (MetaArena 플랫폼 코드에서 사용, 게임 개발자가 직접 사용할 일 없음) */ declare class HostMessenger { sendGameStart(frame: HTMLIFrameElement, payload: { tournament_id: string; player_token: string; api_base: string; }): void; } export { type GameOverPayload, type GameStartContext, HostMessenger, type InboundMessage, MetaArenaSDK, type OutboundMessage, SDKError, SDK_VERSION };