### Remix SDK Installation Source: https://www.npmjs.com/package/@remix-gg/game-sdk/v/0.4.0 Instructions on how to install the Remix SDK using various package managers. ```APIDOC ## Installation Install the SDK using your preferred package manager: ```bash npm install @remix-gg/sdk # or bun install @remix-gg/sdk # or yarn add @remix-gg/sdk # or pnpm add @remix-gg/sdk ``` When you upload game code to Remix, a script tag to reference the SDK will automatically be added to your game code. The SDK will be accessible from `window.RemixSDK`. ``` -------------------------------- ### Implement Remix SDK in a Game Class Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0 A comprehensive example demonstrating how to initialize the SDK, listen for platform events, manage game state, and handle in-game purchases within a game class. ```typescript import { sdk } from '@remix-gg/sdk'; import type { GameState, Player } from '@remix-gg/sdk'; class MyGame { sdk = sdk; player: Player; gameState: GameState | null = null; isMuted: boolean = true; constructor() { this.sdk = window.RemixSDK; this.setupEventListeners(); this.initialize(); } private async setupEventListeners() { this.sdk.onPlayAgain(() => { this.resetGame(); }); this.sdk.onToggleMute((data) => { this.isMuted = data.isMuted; }); this.sdk.onPurchaseComplete(() => { this.checkPurchasedItems(); }); } private async initialize() { await this.sdk.ready(); this.player = this.sdk.player; this.gameState = this.sdk.gameState; this.checkPurchasedItems(); } private checkPurchasedItems() { if (this.sdk.hasItem('save-game')) { this.canSaveGame = true; } if (this.sdk.hasItem('super-skin')) { this.hasSuperSkin = true; } } private async purchaseItem(itemId: string) { await this.sdk.purchase({ item: itemId }); this.checkPurchasedItems(); } private gameOver(finalScore: number) { this.sdk.singlePlayer.actions.gameOver({ score: finalScore }); } } ``` -------------------------------- ### Remix SDK Example Implementation Source: https://www.npmjs.com/package/@remix-gg/game-sdk/v/0.4.0 An example of how to implement the Remix SDK within an HTML5 game, including event listeners and game state management. ```APIDOC ## Example Implementation ```javascript import { sdk } from '@remix-gg/sdk' import type { GameState, Player } from '@remix-gg/sdk' class MyGame { sdk = sdk player: Player gameState: GameState | null = null isMuted: boolean = true // some example values that correlate to items purchased by boosting canSaveGame: boolean = false hasSuperSkin: boolean = false constructor() { // attach the sdk to the Game class to we can reference it easily this.sdk = window.RemixSDK // Setup event listeners this.setupEventListeners() // Initialize your game this.initialize() } private async setupEventListeners() { // Listen for play again events this.sdk.onPlayAgain(() => { this.resetGame() }) // Listen for mute state changes this.sdk.onToggleMute((data) => { this.isMuted = data.isMuted }) // Listen for purchase completions (optional) this.sdk.onPurchaseComplete(() => { this.checkPurchasedItems() }) } private async initialize() { // wait for the sdk to get game information from Remix await this.sdk.ready() // get information the game uses from the SDK this.player = this.sdk.player this.gameState = this.sdk.gameState // check which items the user has already purchased this.checkPurchasedItems() //... start the game logic } private checkPurchasedItems() { // check the identifier for each item to see if the user has purchased it if (this.sdk.hasItem('save-game')) { this.canSaveGame = true } if (this.sdk.hasItem('super-skin')) { this.hasSuperSkin = true } } private async purchaseItem(itemId: string) { // trigger the boost UI and then check for new items after await this.sdk.purchase({ item: itemId }) this.checkPurchasedItems() } private gameOver(finalScore: number) { // this.sdk.singlePlayer.actions.gameOver({ score: finalScore }) } private saveGame() { // return unless the user has purchased the 'save-game' item // see checkPurchasedItems if (!this.canSaveGame) return // push game state updates to save progress for the user const gameState: GameState = this.getCurrentGameState(); this.sdk.singlePlayer.actions.saveGameState({ gameState }) } private triggerHapticFeedback() { this.sdk.hapticFeedback() } } ``` ``` -------------------------------- ### Install Remix SDK Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0 Commands to install the Remix SDK package using various popular JavaScript package managers. ```bash npm install @remix-gg/sdk bun install @remix-gg/sdk yarn add @remix-gg/sdk pnpm add @remix-gg/sdk ``` -------------------------------- ### Implement Remix SDK in Game Class Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0?activeTab=code A comprehensive example showing how to initialize the SDK, listen for events, manage game state, and handle in-game purchases. ```typescript import { sdk } from '@remix-gg/sdk'; import type { GameState, Player } from '@remix-gg/sdk'; class MyGame { sdk = window.RemixSDK; player: Player; gameState: GameState | null = null; isMuted: boolean = true; constructor() { this.setupEventListeners(); this.initialize(); } private async setupEventListeners() { this.sdk.onPlayAgain(() => this.resetGame()); this.sdk.onToggleMute((data) => { this.isMuted = data.isMuted; }); this.sdk.onPurchaseComplete(() => this.checkPurchasedItems()); } private async initialize() { await this.sdk.ready(); this.player = this.sdk.player; this.gameState = this.sdk.gameState; this.checkPurchasedItems(); } private checkPurchasedItems() { if (this.sdk.hasItem('save-game')) { /* ... */ } } private async purchaseItem(itemId: string) { await this.sdk.purchase({ item: itemId }); this.checkPurchasedItems(); } private gameOver(finalScore: number) { this.sdk.singlePlayer.actions.gameOver({ score: finalScore }); } } ``` -------------------------------- ### Implement Remix SDK in a Game Class Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0?activeTab=readme An example implementation showing how to initialize the SDK, listen for events, check purchased items, and report game progress. ```typescript import { sdk } from '@remix-gg/sdk' import type { GameState, Player } from '@remix-gg/sdk' class MyGame { sdk = sdk player: Player gameState: GameState | null = null isMuted: boolean = true constructor() { this.sdk = window.RemixSDK this.setupEventListeners() this.initialize() } private async setupEventListeners() { this.sdk.onPlayAgain(() => { this.resetGame() }) this.sdk.onToggleMute((data) => { this.isMuted = data.isMuted }) this.sdk.onPurchaseComplete(() => { this.checkPurchasedItems() }) } private async initialize() { await this.sdk.ready() this.player = this.sdk.player this.gameState = this.sdk.gameState this.checkPurchasedItems() } private checkPurchasedItems() { if (this.sdk.hasItem('save-game')) { this.canSaveGame = true } if (this.sdk.hasItem('super-skin')) { this.hasSuperSkin = true } } private gameOver(finalScore: number) { this.sdk.singlePlayer.actions.gameOver({ score: finalScore }) } } ``` -------------------------------- ### Implement Remix SDK in a Game Class Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0?activeTab=dependencies A comprehensive example showing how to initialize the SDK, handle events, manage player state, and perform in-game actions like purchases and saving progress. ```typescript import { sdk } from '@remix-gg/sdk'; import type { GameState, Player } from '@remix-gg/sdk'; class MyGame { sdk = sdk; player: Player; gameState: GameState | null = null; isMuted: boolean = true; constructor() { this.sdk = window.RemixSDK; this.setupEventListeners(); this.initialize(); } private async setupEventListeners() { this.sdk.onPlayAgain(() => { this.resetGame(); }); this.sdk.onToggleMute((data) => { this.isMuted = data.isMuted; }); this.sdk.onPurchaseComplete(() => { this.checkPurchasedItems(); }); } private async initialize() { await this.sdk.ready(); this.player = this.sdk.player; this.gameState = this.sdk.gameState; this.checkPurchasedItems(); } private checkPurchasedItems() { if (this.sdk.hasItem('save-game')) { this.canSaveGame = true; } if (this.sdk.hasItem('super-skin')) { this.hasSuperSkin = true; } } private async purchaseItem(itemId: string) { await this.sdk.purchase({ item: itemId }); this.checkPurchasedItems(); } private gameOver(finalScore: number) { this.sdk.singlePlayer.actions.gameOver({ score: finalScore }); } private saveGame() { if (!this.canSaveGame) return; const gameState: GameState = this.getCurrentGameState(); this.sdk.singlePlayer.actions.saveGameState({ gameState }); } } ``` -------------------------------- ### Implement Remix SDK in Game Class Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0?activeTab=dependents An example implementation showing how to initialize the SDK, listen for events, handle purchases, and interact with game state. ```typescript import { sdk } from '@remix-gg/sdk' import type { GameState, Player } from '@remix-gg/sdk' class MyGame { sdk = sdk player: Player gameState: GameState | null = null isMuted: boolean = true constructor() { this.sdk = window.RemixSDK this.setupEventListeners() this.initialize() } private async setupEventListeners() { this.sdk.onPlayAgain(() => { this.resetGame() }) this.sdk.onToggleMute((data) => { this.isMuted = data.isMuted }) this.sdk.onPurchaseComplete(() => { this.checkPurchasedItems() }) } private async initialize() { await this.sdk.ready() this.player = this.sdk.player this.gameState = this.sdk.gameState this.checkPurchasedItems() } private checkPurchasedItems() { if (this.sdk.hasItem('save-game')) { this.canSaveGame = true } if (this.sdk.hasItem('super-skin')) { this.hasSuperSkin = true } } private async purchaseItem(itemId: string) { await this.sdk.purchase({ item: itemId }) this.checkPurchasedItems() } private gameOver(finalScore: number) { this.sdk.singlePlayer.actions.gameOver({ score: finalScore }) } } ``` -------------------------------- ### Remix SDK Example Game Implementation (TypeScript) Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0?activeTab=versions An example implementation of a game class using the Remix SDK in TypeScript. It demonstrates setting up event listeners for game events like 'play again', 'toggle mute', and 'purchase complete', initializing the game with SDK data, and handling item purchases. ```typescript import { sdk } from '@remix-gg/sdk' import type { GameState, Player } from '@remix-gg/sdk' class MyGame { sdk = sdk player: Player gameState: GameState | null = null isMuted: boolean = true // some example values that correlate to items purchased by boosting canSaveGame: boolean = false hasSuperSkin: boolean = false constructor() { // attach the sdk to the Game class to we can reference it easily this.sdk = window.RemixSDK // Setup event listeners this.setupEventListeners() // Initialize your game this.initialize() } private async setupEventListeners() { // Listen for play again events this.sdk.onPlayAgain(() => { this.resetGame() }) // Listen for mute state changes this.sdk.onToggleMute((data) => { this.isMuted = data.isMuted }) // Listen for purchase completions (optional) this.sdk.onPurchaseComplete(() => { this.checkPurchasedItems() }) } private async initialize() { // wait for the sdk to get game information from Remix await this.sdk.ready() // get information the game uses from the SDK this.player = this.sdk.player this.gameState = this.sdk.gameState // check which items the user has already purchased this.checkPurchasedItems() //... start the game logic } private checkPurchasedItems() { // check the identifier for each item to see if the user has purchased it if (this.sdk.hasItem('save-game')) { this.canSaveGame = true } if (this.sdk.hasItem('super-skin')) { this.hasSuperSkin = true } } private async purchaseItem(itemId: string) { // trigger the boost UI and then check for new items after await this.sdk.purchase({ item: itemId }) this.checkPurchasedItems() } private gameOver(finalScore: number) { // this.sdk.singlePlayer.actions.gameOver({ score: finalScore }) } private saveGame() { // return unless the user has purchased the 'save-game' item // see checkPurchasedItems if (!this.canSaveGame) return // push game state updates to save progress for the user const gameState: GameState = this.getCurrentGameState(); this.sdk.singlePlayer.actions.saveGameState({ gameState }) } private triggerHapticFeedback() { this.sdk.hapticFeedback() } } ``` -------------------------------- ### Game State Update Handling Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0?activeTab=dependents Provides an example of how to handle game state updates, including refuting invalid states. ```APIDOC ## Example: Handling Game State Updates ### Description This example demonstrates how to process incoming game state updates for a multiplayer game, such as Chess. It includes logic to apply moves, render the board, and update game status. If the received game state is invalid, it triggers a refute action. ### Code Example ```typescript handleGameStateUpdate({ gameState }) { if (!gameState) return; const { id, gameState: { moves } } = gameState; try { this.chess.reset(); if (moves?.length > 0) { for (const move of moves) { this.chess.move(move); } } this.renderBoard(); this.updateStatus(); this.updateMoveHistory(); this.updateCapturedPieces(); } catch (error) { // game state is invalid, refuting this game state update this.sdk.multiplayer.actions.refuteGameState({ gameStateId: id }); } } ``` ``` -------------------------------- ### Game State Update Handling Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0?activeTab=dependencies Provides an example of how to handle game state updates, including resetting the game, applying moves, and refuting invalid states. ```APIDOC ## Game State Update Example ### Description This example function demonstrates how to handle incoming game state updates for a Chess game. It resets the board, applies moves, and updates the UI. If the game state is invalid, it refutes the update. ### Method N/A (Client-side function) ### Endpoint N/A ### Parameters #### Request Body - **gameState** (object) - Required - An object containing the game's state, including its ID and moves. - **gameState.id** (string) - The unique identifier of the game state. - **gameState.gameState** (object) - Contains the current state of the game. - **gameState.gameState.moves** (array) - An array of moves made in the game. ### Request Example ```javascript { "gameState": { "id": "game-state-123", "gameState": { "moves": ["e2e4", "e7e5"] } } } ``` ### Response N/A (This is a client-side function for handling updates) ### Error Handling If the provided game state is invalid, the `refuteGameState` method is called. ``` -------------------------------- ### Initiate In-Game Purchase (JavaScript) Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0?activeTab=dependencies Starts the purchase process for a specified in-game item. This function returns a promise that indicates the success or failure of the transaction. Ensure the item identifier is valid and configured in the Remix web app. ```javascript async function purchaseItem(itemId) { const result = await sdk.purchase({ item: itemId }); if (result.success) { console.log(`Purchase of ${itemId} successful!`); } else { console.log(`Purchase of ${itemId} failed.`); } } purchaseItem('your-item-id'); ``` -------------------------------- ### Remix SDK Initialization and Event Listeners Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0?activeTab=dependencies This section covers the initialization process of the SDK and how to set up event listeners for various game events like play again, mute changes, and purchase completions. ```APIDOC ## SDK Initialization and Event Handling ### Description This section details how to initialize the Remix SDK within your game and set up event listeners to react to user interactions and game state changes managed by the Remix platform. ### Initialization To initialize the SDK and ensure it's ready to communicate with the Remix platform, you should await the `sdk.ready()` function before accessing game information. ```javascript import { sdk } from '@remix-gg/sdk' // ... inside your game class or initialization logic this.sdk = window.RemixSDK await this.sdk.ready() // Now you can safely access player, gameState, etc. ``` ### Event Listeners The SDK provides methods to listen for specific events triggered by the Remix platform or user actions. - **`sdk.onPlayAgain(callback)`** - Description: Registers a callback function to be executed when the 'Play Again' action is triggered. - Parameters: - `callback` (function) - The function to call when play again is initiated. - **`sdk.onToggleMute(callback)`** - Description: Registers a callback function to be executed when the mute state is toggled. - Parameters: - `callback` (function) - The function to call, receiving an object with `isMuted` boolean. - Example callback data: `{ isMuted: true }` - **`sdk.onPurchaseComplete(callback)`** - Description: Registers a callback function to be executed after a purchase is successfully completed. - Parameters: - `callback` (function) - The function to call upon purchase completion. ### Request Example (Conceptual) ```json // No direct request body for event listeners, but callback data is provided. // Example data received by onToggleMute: { "isMuted": true } ``` ### Response Example (Conceptual) ```json // No direct response for event listeners, but callbacks are executed. // Example of a successful purchase completion callback: // Your function registered with onPurchaseComplete() will be called. ``` ``` -------------------------------- ### SDK Initialization and Ready State Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0?activeTab=dependents Methods to initialize the SDK and ensure game information is loaded from the platform. ```APIDOC ## sdk.ready() ### Description Waits for the SDK to receive all game information from the Remix platform. This must be awaited before accessing player or game state data. ### Method Async Function ### Returns - **Promise** - Resolves when the SDK is fully initialized. ## sdk.isReady ### Description Synchronous check to see if the SDK has received game information. ### Type boolean ``` -------------------------------- ### Remix SDK API: Triggering Purchases Source: https://www.npmjs.com/package/@remix-gg/game-sdk/v/0.4.0 Shows how to initiate an in-game purchase using `sdk.purchase({ item: itemId })`. After a successful purchase, it's recommended to re-check purchased items to update the game state accordingly. ```typescript private async purchaseItem(itemId: string) { // trigger the boost UI and then check for new items after await this.sdk.purchase({ item: itemId }) this.checkPurchasedItems() } ``` -------------------------------- ### Initialize and Manage Multiplayer Game State with Remix.gg SDK Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0 This TypeScript code demonstrates how to initialize the Remix.gg SDK, set up event listeners for multiplayer game events like state updates and player actions, and manage the game state. It includes methods for saving game state, handling game over conditions, and processing item purchases. ```typescript import { sdk } from '@remix-gg/sdk' import type { GameState, Player } from '@remix-gg/sdk' class Game { sdk = sdk gameState: GameState player: Player players: Player[] constructor() { this.sdk = window.RemixSDK // Initialize your game this.initialize() // Setup event listeners this.setupEventListeners() } private setupEventListeners() { // Listen for play again events this.sdk.onPlayAgain(() => { this.resetGame() }) // Listen for mute state changes this.sdk.onToggleMute((data) => { this.setMuted(data.isMuted) }) // Listen for game state updates (essential for multiplayer) this.sdk.onGameStateUpdated((data) => { const { id, gameState } = data const newGameStateIsValid = this.validateGameState(gameState); if (newGameStateIsValid) { this.gameState = gameState } else { sdk.multiplayer.actions.refuteGameState({ gameStateId: id }); } }) // Listen for purchase completions (optional) sdk.onPurchaseComplete((data) => { if (data.success) { this.handlePurchaseSuccess() } }) } private async initialize() { await this.sdk.ready() this.gameState = this.sdk.gameState this.player = this.sdk.player this.players = this.sdk.players } private saveGameState(gameState: Record, nextTurnPlayerId: string) { sdk.multiplayer.actions.saveGameState({ gameState, alertUserIds: [nextTurnPlayerId], }) } private gameOver(scores: { playerId: string, score: number }[]) { sdk.multiplayer.actions.gameOver({ scores }) } private async purchaseItem(itemId: string) { try { const result = await sdk.multiplayer.actions.purchase({ item: itemId }) if (result.success) { console.log(`Successfully purchased ${itemId}`) // Item is now available via sdk.hasItem(itemId) or sdk.purchasedItems // The purchasedItems array is automatically updated for all players } else { console.log(`Purchase failed for ${itemId}`) } } catch (error) { console.error('Purchase error:', error) } } } ``` -------------------------------- ### Implement Multiplayer Game Class with Remix SDK Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0?activeTab=code A TypeScript class implementation demonstrating how to initialize the Remix SDK, set up event listeners for game state and player interactions, and execute multiplayer actions such as saving state and processing purchases. ```typescript import { sdk } from '@remix-gg/sdk' import type { GameState, Player } from '@remix-gg/sdk' class Game { sdk = sdk gameState: GameState player: Player players: Player[] constructor() { this.sdk = window.RemixSDK this.initialize() this.setupEventListeners() } private setupEventListeners() { this.sdk.onPlayAgain(() => { this.resetGame() }) this.sdk.onToggleMute((data) => { this.setMuted(data.isMuted) }) this.sdk.onGameStateUpdated((data) => { const { id, gameState } = data const newGameStateIsValid = this.validateGameState(gameState); if (newGameStateIsValid) { this.gameState = gameState } else { sdk.multiplayer.actions.refuteGameState({ gameStateId: id }); } }) sdk.onPurchaseComplete((data) => { if (data.success) { this.handlePurchaseSuccess() } }) } private async initialize() { await this.sdk.ready() this.gameState = this.sdk.gameState this.player = this.sdk.player this.players = this.sdk.players } private saveGameState(gameState: Record, nextTurnPlayerId: string) { sdk.multiplayer.actions.saveGameState({ gameState, alertUserIds: [nextTurnPlayerId], }) } private gameOver(scores: { playerId: string, score: number }[]) { sdk.multiplayer.actions.gameOver({ scores }) } private async purchaseItem(itemId: string) { try { const result = await sdk.multiplayer.actions.purchase({ item: itemId }) if (result.success) { console.log(`Successfully purchased ${itemId}`) } else { console.log(`Purchase failed for ${itemId}`) } } catch (error) { console.error('Purchase error:', error) } } } ``` -------------------------------- ### Register Purchase Complete Event Listener Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0?activeTab=versions Sets up a listener for purchase completion events. This callback is triggered when a purchase is finalized and provides the success status, useful for post-purchase logic or handling external purchases. ```javascript sdk.onPurchaseComplete(({ success }) => { console.log('Purchase completed:', success); // Update UI or grant items based on purchase success }); ``` -------------------------------- ### Initiate Multiplayer Purchase (JavaScript) Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0 Initiates the purchase of an in-game item for multiplayer games. This method is similar to the single-player purchase method and returns a promise that resolves with the success status of the purchase. ```javascript async () => { const result = await sdk.multiplayer.actions.purchase({ item: 'special_sword' }); if (result.success) { console.log('Item purchased successfully!'); } else { console.log('Purchase failed.'); } } ``` -------------------------------- ### Initiate In-Game Purchase Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0?activeTab=versions Initiates the purchase process for an in-game item. This method is used in multiplayer games and returns a promise that resolves with the purchase success status. ```javascript async () => { try { const result = await sdk.multiplayer.actions.purchase({ item: 'special_sword' }); if (result.success) { console.log('Purchase successful!'); } else { console.log('Purchase failed.'); } } catch (error) { console.error('Error during purchase:', error); } } ``` -------------------------------- ### Remix SDK API: Haptic Feedback Source: https://www.npmjs.com/package/@remix-gg/game-sdk/v/0.4.0 Demonstrates how to trigger haptic feedback on the user's device using the `sdk.hapticFeedback()` function. ```typescript private triggerHapticFeedback() { this.sdk.hapticFeedback() } ``` -------------------------------- ### Store and Purchase API Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0?activeTab=dependents Methods for managing in-game store items and checking user purchases. ```APIDOC ## sdk.hasItem(item: string) ### Description Checks if the current player has purchased a specific item. ### Parameters - **item** (string) - Required - The item identifier to check. ### Returns - **boolean** - True if purchased, false otherwise. ## sdk.getStoreItem(slug: string) ### Description Retrieves a specific store item definition by its slug. ### Parameters - **slug** (string) - Required - The store item slug. ### Returns - **StoreItem | undefined** - The matching store item object. ``` -------------------------------- ### Remix SDK API: Trigger Purchase Flow Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0?activeTab=versions Shows how to initiate the purchase flow for a specific item using the `purchase` method of the Remix SDK. This method triggers the platform's UI for item purchase and can be followed by checking updated purchased items. ```typescript await this.sdk.purchase({ item: itemId }) this.checkPurchasedItems() ``` -------------------------------- ### Handle Multiplayer Game State Updates Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0?activeTab=code Demonstrates how to process game state updates by replaying moves on a local chess instance and refuting the state if an error occurs. This ensures synchronization between players in a multiplayer session. ```javascript handleGameStateUpdate({ gameState }) { if (!gameState) return; const { id, gameState: { moves } } = gameState; try { this.chess.reset(); if (moves?.length > 0) { for (const move of moves) { this.chess.move(move); } } this.renderBoard(); this.updateStatus(); this.updateMoveHistory(); this.updateCapturedPieces(); } catch (error) { this.sdk.multiplayer.actions.refuteGameState({ gameStateId: id }); } } ``` -------------------------------- ### Initiate Multiplayer Purchase Source: https://www.npmjs.com/package/@remix-gg/game-sdk/v/0.4.0 Initiates the purchase of an in-game item within a multiplayer context. This method returns a promise that resolves with a success status. ```javascript async () => { try { const result = await sdk.multiplayer.actions.purchase({ item: 'special_sword' }); console.log('Purchase successful:', result.success); } catch (error) { console.error('Purchase failed:', error); } } ``` -------------------------------- ### Purchase Item Source: https://www.npmjs.com/package/@remix-gg/game-sdk/v/0.4.0 Initiate a purchase for an in-game item, sending a request to the Remix platform and receiving a promise with the purchase result. ```APIDOC ## POST /sdk/purchase ### Description Initiates a purchase for an in-game item. The `item` identifier must match an item added via the Remix web app. ### Method POST ### Endpoint /sdk/purchase ### Parameters #### Request Body - **item** (string) - Required - The identifier of the item to purchase. ### Request Example ```json { "item": "item-id-123" } ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates whether the purchase was successful. #### Response Example ```json { "success": true } ``` ### Flow 1. Call `purchase({ item: 'item-id' })`. 2. Platform handles transaction. 3. Promise resolves with `{ success: true }` or `{ success: false }`. 4. `purchasedItems` in `GameInfo` is updated automatically. ``` -------------------------------- ### Initiate In-Game Purchase Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0?activeTab=dependents Initiates the process of purchasing an in-game item. This method is applicable to both single-player and multiplayer contexts and returns a promise that resolves with the purchase status. ```typescript async () => { try { const result = await sdk.multiplayer.actions.purchase({ item: 'special_sword' }); if (result.success) { console.log('Item purchased successfully!'); } else { console.log('Purchase failed.'); } } catch (error) { console.error('Error during purchase:', error); } } ``` -------------------------------- ### Initiate In-Game Purchase Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0 Initiates a purchase request for a specific item identifier. Returns a promise that resolves with the success status of the transaction. ```typescript sdk.purchase({ item: 'item-id' }).then(result => { if (result.success) { console.log('Purchase successful'); } }); ``` -------------------------------- ### Remix SDK Properties and Getters Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0?activeTab=versions Provides access to game information, player data, and store details. ```APIDOC ## SDK Properties and Getters ### `sdk.ready(): Promise` This function will return when the SDK has received all the game information from Remix. You should await the call to this function before getting info from the SDK (sdk.player, sdk.gameState, etc). ### `sdk.isReady: boolean` Check if the SDK has received game info and is ready. More often, you will just await the call to `sdk.ready()`, but you may use this value if you prefer. ### `sdk.player: Player | undefined` Get the current player object. ### `sdk.players: Player[] | undefined` Get the list of all players in the game. This is useful for multiplayer games. In multiplayer games, it is essential that you use the `players` array so you can report scores with the associated player ids and notify players it is there turn. ### `sdk.gameState: GameState | null | undefined` Get the current game state. This will be `null` when there is no existing GameState for this game and user. ### `sdk.purchasedItems: string[]` Get the list of item IDs that the current player has purchased. This is a read-only property that reflects the `purchasedItems` array from the current player's `GameInfo`. ### `sdk.storeItems: StoreItem[]` Get the list of purchasable store items available for the current game session. ### `sdk.hasItem(item: string): boolean` Check if the current player has purchased a specific item. #### Parameters - **item** (string) - Required - The item identifier to check. #### Returns - `true` if the player has purchased the item, `false` otherwise. ### `sdk.getStoreItem(slug: string): StoreItem | undefined` Get a specific store item by slug. #### Parameters - **slug** (string) - Required - The store item slug to look up. #### Returns - The matching `StoreItem` object when found, otherwise `undefined`. ``` -------------------------------- ### Remix SDK API Reference - Properties and Getters Source: https://www.npmjs.com/package/@remix-gg/game-sdk/v/0.4.0 Details on the properties and getters available in the Remix SDK for accessing game information and state. ```APIDOC ## API Reference ### Properties and Getters #### `sdk.ready(): Promise` This function will return when the SDK has recieved all the game information from Remix. You should await the call to this function before getting info from the SDK (sdk.player, sdk.gameState, etc) #### `sdk.isReady: boolean` Check if the SDK has received game info and is ready. More often, you will just await the call to `sdk.ready()`, but you may use this value if you prefer. #### `sdk.player: Player | undefined` Get the current player object. #### `sdk.players: Player[] | undefined` Get the list of all players in the game. This is useful for multiplayer games. In multiplayer games, it is essential that you use the `players` array so you can report scores with the associated player ids and notify players it is there turn. #### `sdk.gameState: GameState | null | undefined` Get the current game state. This will be `null` when there is no existing GameState for this game and user. #### `sdk.purchasedItems: string[]` Get the list of item IDs that the current player has purchased. This is a read-only property that reflects the `purchasedItems` array from the current player's `GameInfo`. #### `sdk.storeItems: StoreItem[]` Get the list of purchasable store items available for the current game session. #### `sdk.hasItem(item: string): boolean` Check if the current player has purchased a specific item. Parameters: * `item`: The item identifier to check (string) Returns: * `true` if the player has purchased the item, `false` otherwise #### `sdk.getStoreItem(slug: string): StoreItem | undefined` Get a specific store item by slug. Parameters: * `slug`: The store item slug to look up (string) Returns: * The matching `StoreItem` object when found, otherwise `undefined` ``` -------------------------------- ### Purchase Item API Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0?activeTab=dependencies Initiates an in-game purchase request through the Remix platform. ```APIDOC ## POST sdk.purchase ### Description Initiates a purchase for an in-game item. The platform handles the transaction and returns the result via a promise. ### Method POST ### Endpoint sdk.purchase ### Parameters #### Request Body - **item** (string) - Required - The unique identifier of the item to purchase. ### Request Example { "item": "sword_001" } ### Response #### Success Response (200) - **success** (boolean) - Indicates whether the purchase was successful. #### Response Example { "success": true } ``` -------------------------------- ### Register Purchase Complete Listener (JavaScript) Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0 Registers a callback function that is executed upon the completion of a purchase. This allows for additional handling beyond the promise returned by the purchase method, and it also captures purchases initiated externally. ```javascript sdk.onPurchaseComplete(({ success }) => { if (success) { console.log('Purchase successful!'); // Grant item or update player inventory } else { console.log('Purchase failed.'); // Handle failed purchase scenario } }); ``` -------------------------------- ### Event Listeners Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0?activeTab=dependents Details the various event listeners available in the SDK for real-time game feedback. ```APIDOC ## Event Listeners ### Description The SDK offers both generic and specific event listeners. Using specific listeners is recommended for improved type safety and code clarity. #### `sdk.onPlayAgain(callback: () => void)` Registers a callback function that is invoked when a player indicates they want to play again. #### `sdk.onToggleMute(callback: (data: { isMuted: boolean }) => void)` Registers a callback function that is executed when mute state changes are received. The callback receives an object with an `isMuted` boolean property. #### `sdk.onGameStateUpdated(callback: (data: { id: string, gameState: Record } | null) => void)` Registers a callback function that is called when the game state is updated. This is crucial for multiplayer games to receive state changes from other players. The callback receives the game state data or `null` if the state is cleared. #### `sdk.onGameInfo(callback: (data: GameInfo) => void)` Registers a callback function that is invoked when game information is received. This typically occurs during game initialization but can also be used for subsequent updates. The callback receives a `GameInfo` object. #### `sdk.onPurchaseComplete(callback: (data: { success: boolean }) => void)` Registers a callback function that is executed upon the completion of a purchase. This listener is useful for additional post-purchase handling and receives the same success status as the `purchase()` promise. It also captures purchases initiated outside the game's direct `purchase` call. ``` -------------------------------- ### Purchase Item (Multiplayer) Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0?activeTab=dependencies Initiates a purchase for an in-game item in a multiplayer context. This method is identical in functionality to the single-player purchase method. ```APIDOC ## POST /api/purchase ### Description Initiates a purchase for an in-game item in a multiplayer game. ### Method POST ### Endpoint /api/purchase ### Parameters #### Request Body - **item** (string) - Required - The identifier of the item to purchase. ### Request Example ```json { "item": "sword_of_greatness" } ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates whether the purchase was successful. #### Response Example ```json { "success": true } ``` ``` -------------------------------- ### Purchase In-Game Items Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0?activeTab=versions Initiates a purchase request for a specific in-game item through the Remix platform. ```APIDOC ## POST /sdk/purchase ### Description Initiates a purchase flow for a specified in-game item. The platform handles payment processing and returns a success status. ### Method POST ### Parameters #### Request Body - **item** (string) - Required - The unique identifier of the item to purchase. ### Request Example { "item": "sword_001" } ### Response #### Success Response (200) - **success** (boolean) - Indicates if the purchase transaction was successful. #### Response Example { "success": true } ``` -------------------------------- ### Multiplayer Purchase Action Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0?activeTab=dependents Initiates a purchase for an in-game item in multiplayer games. This method is identical to the single-player purchase method. ```APIDOC ## POST /api/sdk/multiplayer/actions/purchase ### Description Initiates a purchase for an in-game item in a multiplayer context. This function mirrors the functionality of the single-player `purchase` method. ### Method POST ### Endpoint `/api/sdk/multiplayer/actions/purchase` ### Parameters #### Request Body - **item** (string) - Required - The identifier of the item to purchase. ### Request Example ```json { "item": "premium_currency_pack" } ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates whether the purchase was successful. #### Response Example ```json { "success": true } ``` ``` -------------------------------- ### Event Listeners Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0?activeTab=dependencies Details the various event listeners available in the SDK for handling player actions and game updates. ```APIDOC ## Event Listeners ### Description The SDK provides event listeners to react to various occurrences within the game, such as player requests to play again, mute state changes, game state updates, game information updates, and purchase completions. ### `sdk.onPlayAgain(callback: () => void)` Registers a callback function that is invoked when a player indicates they want to play again. ### `sdk.onToggleMute(callback: (data: { isMuted: boolean }) => void)` Registers a callback function that is called when the mute state changes. The callback receives an object indicating the current mute status. - **callback** (function) - Receives `{ isMuted: boolean }`. ### `sdk.onGameStateUpdated(callback: (data: { id: string, gameState: Record } | null) => void)` Registers a callback function that is invoked when the game state is updated. This is crucial for multiplayer games to synchronize state across players. The callback receives the game state data or null if the state is cleared. - **callback** (function) - Receives the game state update data or `null`. ### `sdk.onGameInfo(callback: (data: GameInfo) => void)` Registers a callback function that is called when game information is received. This typically occurs during game initialization but can also be triggered by updates. - **callback** (function) - Receives the `GameInfo` object. ### `sdk.onPurchaseComplete(callback: (data: { success: boolean }) => void)` Registers a callback function that is called when a purchase is completed. This listener can be used for additional logic after a purchase, complementing the promise returned by the `purchase()` method. It receives the same success status as the `purchase()` promise. - **callback** (function) - Receives `{ success: boolean }` indicating the purchase outcome. ``` -------------------------------- ### Remix SDK API: Trigger Haptic Feedback Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0?activeTab=versions Shows how to trigger haptic feedback on the user's device using the `hapticFeedback` method of the Remix SDK. This can be used to provide tactile confirmation for in-game actions. ```typescript this.sdk.hapticFeedback() ``` -------------------------------- ### Register Game Info Event Listener (JavaScript) Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0 Registers a callback function that is called when game information is received. This typically happens during game initialization but can also be triggered by subsequent updates. ```javascript sdk.onGameInfo((gameInfo) => { console.log('Received game info:', gameInfo); // Use gameInfo for initialization or display purposes }); ``` -------------------------------- ### Event Listeners Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0 Provides methods to register callback functions for various game events, enabling real-time updates and interactions. ```APIDOC ## Event Listeners ### Description Register callback functions to listen for specific game events. ### `sdk.onPlayAgain(callback: () => void)` Registers a callback function that is invoked when a player indicates they want to play again. ### `sdk.onToggleMute(callback: (data: { isMuted: boolean }) => void)` Registers a callback function that is invoked when the mute state of the game changes. * **callback** (Function) - Receives an object `{ isMuted: boolean }` indicating the current mute state. ### `sdk.onGameStateUpdated(callback: (data: { id: string, gameState: Record } | null) => void)` Registers a callback function that is invoked when the game state is updated. This is crucial for multiplayer games to synchronize state across players. * **callback** (Function) - Receives an object containing the game state update data (`{ id: string, gameState: Record }`) or `null` if the game state is cleared. ### `sdk.onGameInfo(callback: (data: GameInfo) => void)` Registers a callback function that is invoked when game information is received. Typically called during game initialization. * **callback** (Function) - Receives the `GameInfo` object. ### `sdk.onPurchaseComplete(callback: (data: { success: boolean }) => void)` Registers a callback function that is invoked when a purchase is completed. This can be used for additional logic after a purchase, complementing the promise returned by the `purchase()` method. * **callback** (Function) - Receives an object `{ success: boolean }` indicating the outcome of the purchase. ``` -------------------------------- ### Event Listeners Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0?activeTab=readme Methods to register callbacks for various game events such as state updates, purchases, and UI interactions. ```APIDOC ## Event Listeners ### sdk.onPlayAgain(callback) Registers a callback for when a player requests to play again. ### sdk.onToggleMute(callback) Registers a callback for mute state changes. - **callback**: Function receiving `{ isMuted: boolean }` ### sdk.onGameStateUpdated(callback) Registers a callback for multiplayer game state synchronization. - **callback**: Function receiving `{ id: string, gameState: Record } | null` ### sdk.onGameInfo(callback) Registers a callback for receiving initial or updated game information. - **callback**: Function receiving `GameInfo` object ### sdk.onPurchaseComplete(callback) Registers a callback for when a purchase process completes. - **callback**: Function receiving `{ success: boolean }` ``` -------------------------------- ### Register Purchase Complete Event Listener Source: https://www.npmjs.com/package/%40remix-gg/game-sdk/v/0.4.0?activeTab=dependents Registers a callback function that is executed upon the completion of an in-game purchase. This listener complements the promise returned by the purchase method, handling cases where purchases might occur outside the direct SDK call. ```typescript sdk.onPurchaseComplete(({ success }) => { if (success) { console.log('Purchase completed successfully!'); } else { console.log('Purchase failed.'); } }); ``` -------------------------------- ### Multiplayer Purchase Action Source: https://www.npmjs.com/package/@remix-gg/game-sdk/v/0.4.0 Initiates a purchase for an in-game item in multiplayer games. This method is similar to the single-player purchase method. ```APIDOC ## POST /api/sdk/multiplayer/purchase ### Description Initiates a purchase for an in-game item in a multiplayer context. This action is analogous to the single-player purchase functionality. ### Method POST ### Endpoint /api/sdk/multiplayer/purchase ### Parameters #### Request Body - **item** (string) - Required - The identifier of the item to purchase. ### Request Example ```json { "item": "premium_currency_pack" } ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates whether the purchase was successful. #### Response Example ```json { "success": true } ``` ```