Sfoglia il codice sorgente

add .d.ts type declarations for game TypeScript projects

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
LoganZ2 3 giorni fa
parent
commit
0863160452
2 ha cambiato i file con 31 aggiunte e 3 eliminazioni
  1. 20 0
      game-sdk.d.ts
  2. 11 3
      game-sdk.js

+ 20 - 0
game-sdk.d.ts

@@ -0,0 +1,20 @@
+interface GameSDKResult {
+  ok: true
+  rank: number
+}
+
+interface GameSDKError {
+  ok: false
+  error: string
+}
+
+interface IGameSDK {
+  /** This game's id string */
+  gameId: string
+  /** Current player's display name */
+  getPlayerName(): string
+  /** Submit a score. Returns rank on success. */
+  submit(score: number): Promise<GameSDKResult | GameSDKError>
+}
+
+declare const GameSDK: IGameSDK

+ 11 - 3
game-sdk.js

@@ -2,8 +2,16 @@
  * Game Platform SDK
  *
  * window.GameSDK is injected by the platform before your bundle loads.
+ * Call it as a global — no import needed.
  *
- * GameSDK.gameId            — string, this game's id
- * GameSDK.getPlayerName()   — string, current player's display name
- * GameSDK.submit(score)     — Promise<{ ok: true, rank: number } | { ok: false, error: string }>
+ *   const result = await GameSDK.submit(100)
+ *   // { ok: true, rank: 3 }
+ *
+ * For TypeScript projects, copy game-sdk.d.ts into your source tree (or
+ * reference it in tsconfig) to get type checking and autocomplete.
+ *
+ * API:
+ *   GameSDK.gameId            — string
+ *   GameSDK.getPlayerName()   — string
+ *   GameSDK.submit(score)     — Promise<{ ok: true, rank } | { ok: false, error }>
  */