diff --git a/docs/02-guides/01-platform/05-enjin-farmer-sample-game/01-setup-guide.md b/docs/02-guides/01-platform/05-enjin-farmer-sample-game/01-setup-guide.md new file mode 100644 index 0000000..e6deb90 --- /dev/null +++ b/docs/02-guides/01-platform/05-enjin-farmer-sample-game/01-setup-guide.md @@ -0,0 +1,179 @@ +--- +title: "Enjin Farmer: Setup Guide" +sidebar_label: "Setup Guide" +slug: "setup-guide" +description: "Follow our step-by-step guide to set up a sample Unity game with full Enjin NFT integration. Learn how to configure a client, server, and wallet to mint, transfer, and manage blockchain assets in a hands-on project." +--- + +import GlossaryTerm from '@site/src/components/GlossaryTerm'; + +Welcome! This guide will walk you through setting up and running the Enjin Farm Game, a sample project demonstrating how to integrate Enjin's NFT technology into a Unity game. + +In this simple farming game, you'll plant seeds, harvest crops, and collect resources. Some resources are special and will be minted as NFTs directly to your in-game wallet. You can then view these NFTs in your inventory, them, or transfer them to an external wallet. + +### System Architecture + +The project consists of four main components that work together: + + - **[Game Client (Unity)](https://github.com/enjin/platform-sample-game-client-unity):** The game itself, where you play and interact with items. + - **[Game Server (Node.js)](https://github.com/enjin/platform-sample-game-server):** A backend API that the game client communicates with to handle all NFT-related actions like minting and transferring. + - **:** The cloud-based service that provides the core NFT infrastructure. + - **Wallet Daemon:** A secure application that manages a wallet on behalf of the game to automatically sign and approve transactions. + +----- + +## Prerequisites + +Before you begin, make sure you have the following installed: + + - ✅ **Unity Hub** with **Unity Editor version `6000.0.24f1`**. + - ✅ **Node.js** (which includes `npm`). + - ✅ **Git** for cloning the repositories. + - ✅ An **Enjin Platform account**. If you don't have one, you can create it [here](https://platform.canary.enjin.io/). + - ✅ Some cENJ tokens (can be aquired from the [cENJ Faucet](https://faucet.canary.enjin.io/)) + +----- + +## Step 1: Download Project Files + +First, you need to download the game client, the game server, and the Wallet Daemon. + +1. **Clone the Game Client:** Open a terminal or command prompt and run: + + ```bash + git clone https://github.com/enjin/platform-sample-game-client-unity.git + ``` + +2. **Clone the Game Server:** In the same terminal, run: + + ```bash + git clone https://github.com/enjin/platform-sample-game-server.git + ``` + +3. **Download the Wallet Daemon:** Download the latest executable for your operating system from the [Wallet Daemon releases page](https://github.com/enjin/wallet-daemon-ui/releases). + +----- + +## Step 2: Configure Enjin Services + +Next, you'll set up your Enjin Platform account and the Wallet Daemon. + +### Enjin Platform + +1. Log in to your [Enjin Platform](https://platform.canary.enjin.io/) account. +2. Head over to your [account settings page](https://platform.canary.enjin.io/settings). +3. Navigate to the **Daemon Wallet** section and create a new API Token. +4. Copy the **API Token**; you will need this in the next step. + +### Wallet Daemon + +1. Run the Wallet Daemon executable you downloaded. +2. Follow the on-screen instructions to configure it, and enter the **API Token** you just copied from the Enjin Platform into the Settings → Canary Matrixchain input field. For a detailed guide, see the [Wallet Daemon documentation](https://docs.enjin.io/getting-started/using-wallet-daemon#wallet-daemon-executable). +3. Select the Enjin Platform Canary in the network dropdown menu, and run the Wallet Daemon. +4. Once configured and running, the Wallet Daemon UI will display a wallet address. **Copy this wallet address** for the next step. + +----- + +## Step 3: Configure and Run the Game Server + +Now, let's set up the backend server that powers the game's NFT features. + +1. Navigate into the game server directory you cloned: `cd platform-sample-game-server`. +2. Duplicate the `.env.example` file and rename the copy to `.env`. +3. Open the `.env` file and fill in the following variables: + - `PORT=3000` (You can change this if port 3000 is already in use). + - `JWT_SECRET`: Generate another secure, random string. This is used for authenticating players. + - `ENJIN_API_URL`: Keep the default `https://platform.canary.enjin.io/graphql` for testing on the Canary network. + - `ENJIN_API_KEY`: Paste the **API Key Token** from your Enjin Platform account. + - `DAEMON_WALLET_ADDRESS`: Paste the wallet address you copied from the Wallet Daemon UI. + - `ENJIN_COLLECTION_ID`: Leave this blank for now. +4. Install the server dependencies by running `npm install`. +5. Launch the server for the first time by running `npm run dev`. + +The server will now connect to the Enjin Platform, create a new NFT collection for your game, and create the NFT tokens for the in-game resources. + +:::info **Important** +Watch the terminal logs. Once the setup is complete, the server will log the new **Collection ID**. It will look something like this: `Collection and resource tokens are ready. Using collection ID: XXXXXX`. **Copy this Collection ID** and save it. You'll need it to configure the game client. +::: + +Keep the server and the Wallet Daemon running in the background. + +----- + +## Step 4: Configure the Unity Game Client + +It's time to set up the Unity project and connect it to your game server. + +1. Open **Unity Hub**. +2. Click `Add` → `Add project from disk` and select the `platform-sample-game-client` folder you cloned earlier. +3. Open the project. +4. Once the project is open in the Unity Editor, you need to configure two things. + +#### 1. Configure the NFT Items + + - In the `Project` window, navigate to `Assets/Enjin Integration/Scripts/Data/Items`. + - You will see three `Enjin Item` assets: `GemGreen`, `GoldCoin`, and `GoldCoinBlue`. +

+ +

+ - Click on **each one** of these items. + - In the `Inspector` window for each item, find the **Collection Id** field and paste the `Collection ID` you saved from the game server's terminal log. +

+ +

+ +#### 2. Configure the connection to the Game Server + +:::note +If you are running the game server and client on the same machine, and you haven't changed the default port of 3000, you can skip this step. +::: + + - In the `Project` window, navigate to `Assets/Enjin Integration/Prefabs/`. + - Select the **EnjinManager** prefab. + - In the `Inspector` window, find the `Enjin API Service (Script)` component and configure the host property to your game server URL. If you are running the game server and client on the same machine, the default `http://localhost:3000` is correct. + +

+ +

+ +----- + +## Step 5: Play the Game! 🎮 + +You're all set up and ready to play. + +1. In the Unity Editor's `Project` window, navigate to `Assets/HappyHarvest/Scenes`. +2. Double click on the `Farm_Outdoor` scene. +3. Press the **Play** button at the top of the Unity Editor to launch the game. +4. Look at the **Console** window in the editor. You should see a log message: `Server connection successful (Health Check: OK)`. +

+ +

+ :::warning + If you see an error, double-check that your server is running and that the `Host` and `App Key` in the `EnjinManager` are correct. + ::: +5. In the game, click the **Menu** button (top-right), then **Login**. +

+ +

+6. Enter an email and password and click **Login**. This will register a new user and create a managed wallet for your player on the Enjin Platform. +7. Close the menu and use the **W, A, S, D** keys to move your character. +8. Walk up to a crop and click on it to harvest it. Keep harvesting until a resource item pops out. +

+ +

+9. Click on the resource item to collect it. This action tells the game server to mint that item as an NFT to your player's wallet. +10. From the inventory, you can click **Melt** to destroy the NFT or enter another wallet address in the **Transfer Recipient** field and click **Send** to send it to someone else. +

+ +

+:::warning cENJ funds are required +New managed wallet have no funds. To melt or transfer tokens out of a managed wallet, you'll need to fund it with some cENJ, or set up a fuel tank. +To receive cENJ funds for testing, use the [cENJ faucet](https://faucet.canary.enjin.io/) +::: + +:::info Understanding the code +To learn more about the implementation and dive deep into the game client and server code, continue to the [Enjin Farmer: Implementation Breakdown page](/02-guides/01-platform/05-enjin-farmer-sample-game/03-implementation-breakdown.md). +::: + +Happy farming! \ No newline at end of file diff --git a/docs/02-guides/01-platform/05-enjin-farmer-sample-game/03-implementation-breakdown.md b/docs/02-guides/01-platform/05-enjin-farmer-sample-game/03-implementation-breakdown.md new file mode 100644 index 0000000..b59ebc0 --- /dev/null +++ b/docs/02-guides/01-platform/05-enjin-farmer-sample-game/03-implementation-breakdown.md @@ -0,0 +1,185 @@ +--- +title: "Enjin Farmer: Implementation Breakdown" +sidebar_label: "Implementation Breakdown" +slug: "implementation-breakdown" +description: "Dive deep into the code and architecture of the Enjin Farmer sample game. This technical breakdown explains the implementation flow, from the Unity client to the Node.js game server. Understand the key GraphQL mutations and API calls used to mint, transfer, and manage NFTs in your game." +--- + +import GlossaryTerm from '@site/src/components/GlossaryTerm'; + +The **Enjin Farmer** sample project demonstrates a basic Enjin Platform integration within a Unity game. It's built with a client-server architecture to ensure security and scalability. + +The project consists of two main components: + + * **🎮 Unity Game (Client):** The front-end game that players interact with. It handles gameplay, visuals, and user input, communicating with the game server to perform blockchain actions. + * **🖥️ Game Server (Backend):** A Node.js application that manages all Enjin Platform logic. It securely handles wallet creation, token minting, and other on-chain operations on behalf of the players. + +### 💡 Important Considerations + +Before you begin, please keep the following in mind: + + * **Demonstration Purpose:** This is a simplified example designed to showcase a basic integration. It is **not suitable for a production environment** as is. + * **WebSockets:** This implementation does not use [WebSocket events](/03-api-reference/03-websocket-events.md). In a real-world application, WebSockets can simplify the process of listening for transaction finalization and receiving real-time updates, such as when a user receives an NFT from an external source like the marketplace. + * **Wallet Funding:** New managed wallets are created without any funds. To cover network fees for actions like melting or transferring tokens, you must either fund each wallet individually or use a [Fuel Tank](/02-guides/01-platform/02-managing-users/04-using-fuel-tanks.md) to subsidize transactions for all your users. + +----- + +## 🖥️ Game Server + +The game server is a RESTful API built with Node.js and Express. It serves as the secure bridge between the game client and the Enjin Platform. The main entry point is the [`src/index.js` file](https://github.com/enjin/platform-sample-game-server/blob/4b84cf06df32bf2230197ffad14b2c7e0884e1f4/src/index.js). + +### Environment Variables + +The server is configured using the following environment variables: + +| Variable | Description | +| :--- | :--- | +| `PORT` | The port the server listens on. Defaults to `3000`. | +| `JWT_SECRET` | A secure, random string used for signing player authentication tokens. | +| `ENJIN_API_URL` | The Enjin Platform API URL. Use `https://platform.canary.enjin.io/graphql` for testing (Canary Network) or `https://platform.enjin.io/graphql` for production. | +| `ENJIN_API_KEY` | Your API Key Token obtained from the Enjin Platform. | +| `DAEMON_WALLET_ADDRESS` | The address of your Wallet Daemon. This wallet receives the initial supply of all created tokens. | +| `ENJIN_COLLECTION_ID` | The ID of the Enjin Farmer collection. If left blank, the server will create a new collection on startup. | + +### Server Initialization & Collection Setup + +On startup, the server performs a one-time setup to ensure the necessary blockchain assets exist. + +1. **Check for Collection:** The server first checks if an `ENJIN_COLLECTION_ID` has been provided. +2. **Create Collection:** If the ID is missing, the server calls the [`createCollection` function](https://github.com/enjin/platform-sample-game-server/blob/4b84cf06df32bf2230197ffad14b2c7e0884e1f4/src/services/enjinService.js#L69), which executes the `CreateCollection` mutation on the Enjin Platform. The automatically signs the request. + ```graphql + mutation CreateCollection($name: String!, ...) { + CreateCollection(...) { + id + method + state + } + } + ``` +3. **Monitor Transaction:** The mutation returns a request ID. The server then [polls the `GetTransaction` query](https://github.com/enjin/platform-sample-game-server/blob/4b84cf06df32bf2230197ffad14b2c7e0884e1f4/src/services/enjinService.js#L15) until the transaction `state` is `FINALIZED` and the `result` is `EXTRINSIC_SUCCESS`. + ```graphql + query GetTransaction($requestId: Int!) { + GetTransaction(id: $requestId) { + state + result + events { ... } + } + } + ``` +4. **Extract Collection ID:** Once finalized, the server [extracts the new collection ID from the transaction's events](https://github.com/enjin/platform-sample-game-server/blob/4b84cf06df32bf2230197ffad14b2c7e0884e1f4/src/services/enjinService.js#L43) and assigns it to the `ENJIN_COLLECTION_ID` variable. +5. **Create NFTs:** Using a similar process, the server then [creates the three resource NFTs](https://github.com/enjin/platform-sample-game-server/blob/4b84cf06df32bf2230197ffad14b2c7e0884e1f4/src/services/enjinService.js#L116) ([Gold Coin](https://github.com/enjin/platform-sample-game-server/blob/4b84cf06df32bf2230197ffad14b2c7e0884e1f4/src/services/enjinService.js#L6), [Gold Coin (Blue)](https://github.com/enjin/platform-sample-game-server/blob/4b84cf06df32bf2230197ffad14b2c7e0884e1f4/src/services/enjinService.js#L7), and [Green Gem](https://github.com/enjin/platform-sample-game-server/blob/4b84cf06df32bf2230197ffad14b2c7e0884e1f4/src/services/enjinService.js#L8)) within the collection by calling the `CreateToken` mutation for each and waiting for finalization. + ```graphql + mutation CreateToken($collectionId: BigInt!, $name: String!, ...) { + CreateToken(collectionId: $collectionId, params: { ... }) { + id + method + state + } + } + ``` + +After this setup is complete, the server starts listening for API requests. + +### API Endpoints + +The server exposes several endpoints to handle game actions. The `wallet` and `token` endpoints are protected by a [JWT authentication middleware](https://github.com/enjin/platform-sample-game-server/blob/4b84cf06df32bf2230197ffad14b2c7e0884e1f4/src/middlewares/jwtAuth.js), which verifies the player's identity before processing the request. + +#### Authentication + + * [`GET /api/auth/health-check`](https://github.com/enjin/platform-sample-game-server/blob/4b84cf06df32bf2230197ffad14b2c7e0884e1f4/src/routes/auth.js#L7): A simple endpoint to verify that the server is online. + * [`POST /api/auth/register`](https://github.com/enjin/platform-sample-game-server/blob/4b84cf06df32bf2230197ffad14b2c7e0884e1f4/src/routes/auth.js#L14): Creates a new player and an associated [managed wallet](/02-guides/01-platform/02-managing-users/03-using-managed-wallets.md). To create the wallet, it calls the [`CreateWallet` mutation](https://github.com/enjin/platform-sample-game-server/blob/4b84cf06df32bf2230197ffad14b2c7e0884e1f4/src/services/enjinService.js#L271), using the player's [email address as the unique `externalId`](https://github.com/enjin/platform-sample-game-server/blob/4b84cf06df32bf2230197ffad14b2c7e0884e1f4/src/routes/auth.js#L18). + ```graphql + mutation CreateWallet($externalId: String!) { + CreateWallet(externalId: $externalId) + } + ``` + * [`POST /api/auth/login`](https://github.com/enjin/platform-sample-game-server/blob/4b84cf06df32bf2230197ffad14b2c7e0884e1f4/src/routes/auth.js#L36): Logs in an existing player, returning their wallet address and a JWT. + +#### Wallet Management + + * [`POST /api/wallet/create`](https://github.com/enjin/platform-sample-game-server/blob/4b84cf06df32bf2230197ffad14b2c7e0884e1f4/src/routes/wallet.js#L28): Creates a new managed wallet + * [`POST /api/wallet/get`](https://github.com/enjin/platform-sample-game-server/blob/4b84cf06df32bf2230197ffad14b2c7e0884e1f4/src/routes/wallet.js#L8): Retrieves details for the authenticated player's managed wallet. + * [`GET /api/wallet/get-tokens`](https://github.com/enjin/platform-sample-game-server/blob/4b84cf06df32bf2230197ffad14b2c7e0884e1f4/src/routes/wallet.js#L48): Retrieves the player's managed wallet and all tokens it holds. It calls the [`GetWallet` query](https://github.com/enjin/platform-sample-game-server/blob/4b84cf06df32bf2230197ffad14b2c7e0884e1f4/src/services/enjinService.js#L208) (using [GraphQL Pagination](/01-getting-started/05-using-enjin-api/01-how-to-use-graphql.md#pagination) to loop through all pages of results, ensuring the complete inventory is fetched). + ```graphql + query GetWalletTokens($externalId: String!) { + GetWallet(externalId: $externalId) { + account { ... } + tokenAccounts(...) { ... } + } + } + ``` + +#### Token Actions + + * [`POST /api/token/mint`](https://github.com/enjin/platform-sample-game-server/blob/4b84cf06df32bf2230197ffad14b2c7e0884e1f4/src/routes/token.js#L8): Mints a token to the player's wallet. The server calls the [`MintToken` mutation](https://github.com/enjin/platform-sample-game-server/blob/4b84cf06df32bf2230197ffad14b2c7e0884e1f4/src/services/enjinService.js#L317). The recipient address is extracted from the player's authenticated session. + ```graphql + mutation mintToken($recipient: String!, $collectionId: BigInt!, ...) { + MintToken(recipient: $recipient, collectionId: $collectionId, ...) { + id + } + } + ``` + * [`POST /api/token/melt`](https://github.com/enjin/platform-sample-game-server/blob/4b84cf06df32bf2230197ffad14b2c7e0884e1f4/src/routes/token.js#L29): Melts a token from the player's wallet. This uses the [`Burn` mutation](https://github.com/enjin/platform-sample-game-server/blob/4b84cf06df32bf2230197ffad14b2c7e0884e1f4/src/services/enjinService.js#L371). Since the token needs to be melted from the managed wallet's account, it needs to be signed by the managed wallet. For that, the player's managed wallet address is specified as the `signingAccount`. ([Learn more about managed wallets here](/02-guides/01-platform/02-managing-users/03-using-managed-wallets.md)) + ```graphql + mutation burnToken($signingAccount: String!, $collectionId: BigInt!, ...) { + Burn(signingAccount: $signingAccount, collectionId: $collectionId, ...) { + id + } + } + ``` + * [`POST /api/token/transfer`](https://github.com/enjin/platform-sample-game-server/blob/4b84cf06df32bf2230197ffad14b2c7e0884e1f4/src/routes/token.js#L50): Transfers a token from the player's managed wallet to another address. This uses the [`SimpleTransferToken` mutation](https://github.com/enjin/platform-sample-game-server/blob/4b84cf06df32bf2230197ffad14b2c7e0884e1f4/src/services/enjinService.js#L425), again specifying the player's managed wallet as the `signingAccount`. + ```graphql + mutation transferToken($signingAccount: String!, $recipient: String!, ...) { + SimpleTransferToken(signingAccount: $signingAccount, recipient: $recipient, ...) { + id + } + } + ``` + +----- + +## 🎮 Unity Game + +The Unity game is the client-facing part of the project. It focuses on gameplay and user experience while offloading all sensitive blockchain operations to the game server. + +### Core Components + +The Enjin integration is managed by a few key scripts and a central prefab: + + * **`EnjinManager.prefab`**: The heart of the integration. This prefab is added to the `Farm_Outdoor` scene and configures the **Host URL** (e.g., `http://localhost:3000`) in the Inspector to connect to your game server. + * **[`EnjinManager.cs`](https://github.com/enjin/platform-sample-game-client-unity/blob/e154e83723a76861ca762f4b998ef8c8a44ee44f/Assets/Enjin%20Integration/Scripts/Core/EnjinManager.cs)**: A singleton controller that manages the player's session (auth token, wallet data) and exposes high-level methods like `MintToken()` for other game scripts to use. + * **[`EnjinApiService.cs`](https://github.com/enjin/platform-sample-game-client-unity/blob/e154e83723a76861ca762f4b998ef8c8a44ee44f/Assets/Enjin%20Integration/Scripts/API/EnjinApiService.cs)**: Handles all REST API communication with the game server using Unity's `UnityWebRequest`. + * **[`EnjinItem.cs`](https://github.com/enjin/platform-sample-game-client-unity/blob/e154e83723a76861ca762f4b998ef8c8a44ee44f/Assets/Enjin%20Integration/Scripts/Data/EnjinItem.cs)**: A `ScriptableObject` that represents the data of a blockchain item, such as its display name and its corresponding on-chain token ID. + * **UI Scripts** ([`BackpackUI.cs`](https://github.com/enjin/platform-sample-game-client-unity/blob/e154e83723a76861ca762f4b998ef8c8a44ee44f/Assets/Enjin%20Integration/Scripts/UI/BackpackUI.cs), [`BackpackItemController.cs`](https://github.com/enjin/platform-sample-game-client-unity/blob/e154e83723a76861ca762f4b998ef8c8a44ee44f/Assets/Enjin%20Integration/Scripts/UI/BackpackItemController.cs)): Scripts that manage the UI for viewing and interacting with the player's NFT inventory. + +### Initial Setup & Player Authentication + +1. **Health Check**: On launch, the client [calls the `/api/auth/health-check` endpoint](https://github.com/enjin/platform-sample-game-client-unity/blob/e154e83723a76861ca762f4b998ef8c8a44ee44f/Assets/Enjin%20Integration/Scripts/API/EnjinApiService.cs#L36) to ensure the server is available. +2. **Login/Register**: From the login screen, the player [clicks "Login"](https://github.com/enjin/platform-sample-game-client-unity/blob/e154e83723a76861ca762f4b998ef8c8a44ee44f/Assets/HappyHarvest/Common/UI/SettingMenu/Script/SettingMenu.cs#L145), which calls the [`EnjinManager.Instance.RegisterAndLogin()` method](https://github.com/enjin/platform-sample-game-client-unity/blob/e154e83723a76861ca762f4b998ef8c8a44ee44f/Assets/Enjin%20Integration/Scripts/Core/EnjinManager.cs#L141). +3. **API Request**: This triggers `EnjinApiService` to [send a POST request to the `/api/auth/register` endpoint](https://github.com/enjin/platform-sample-game-client-unity/blob/e154e83723a76861ca762f4b998ef8c8a44ee44f/Assets/Enjin%20Integration/Scripts/API/EnjinApiService.cs#L69). +4. **Store Auth Token**: The server responds with a JWT authentication token. The client [saves this token locally using `PlayerPrefs`](https://github.com/enjin/platform-sample-game-client-unity/blob/e154e83723a76861ca762f4b998ef8c8a44ee44f/Assets/Enjin%20Integration/Scripts/Core/EnjinManager.cs#L152) and [loads it on subsequent launches](https://github.com/enjin/platform-sample-game-client-unity/blob/e154e83723a76861ca762f4b998ef8c8a44ee44f/Assets/Enjin%20Integration/Scripts/Core/EnjinManager.cs#L40) for a seamless experience. + +### In-Game NFT Interactions + +All blockchain actions are initiated by the client but securely executed by the server. + +#### Harvesting and Minting Tokens + +When a player [harvests a crop with the Hoe tool](https://github.com/enjin/platform-sample-game-client-unity/blob/e154e83723a76861ca762f4b998ef8c8a44ee44f/Assets/HappyHarvest/Scripts/Items/Hoe.cs#L18), they have a chance to find a resource token. + +1. An `EnjinToken` GameObject [appears on the harvested tile](https://github.com/enjin/platform-sample-game-client-unity/blob/e154e83723a76861ca762f4b998ef8c8a44ee44f/Assets/Enjin%20Integration/Scripts/Core/EnjinManager.cs#L218). +2. When the player collects this GameObject, its [`InteractedWith()` method](https://github.com/enjin/platform-sample-game-client-unity/blob/e154e83723a76861ca762f4b998ef8c8a44ee44f/Assets/Enjin%20Integration/Scripts/Gameplay/EnjinToken.cs#L20) is triggered. +3. This calls [`EnjinItem.Collect()`](https://github.com/enjin/platform-sample-game-client-unity/blob/e154e83723a76861ca762f4b998ef8c8a44ee44f/Assets/Enjin%20Integration/Scripts/Data/EnjinItem.cs#L37), which in turn calls `EnjinManager.Instance.MintToken()`. +4. `EnjinManager` then uses `EnjinApiService` to [send a request to the `/api/token/mint` endpoint](https://github.com/enjin/platform-sample-game-client-unity/blob/e154e83723a76861ca762f4b998ef8c8a44ee44f/Assets/Enjin%20Integration/Scripts/API/EnjinApiService.cs#L97). + +#### Viewing the Wallet (Backpack UI) + +1. Clicking the backpack icon opens the inventory screen, managed by `BackpackUI.cs`. +2. The UI [calls `EnjinManager.Instance.GetManagedWalletTokens()`](https://github.com/enjin/platform-sample-game-client-unity/blob/e154e83723a76861ca762f4b998ef8c8a44ee44f/Assets/Enjin%20Integration/Scripts/UI/BackpackUI.cs#L47), which [sends a request to the `/api/wallet/get-tokens` endpoint](https://github.com/enjin/platform-sample-game-client-unity/blob/e154e83723a76861ca762f4b998ef8c8a44ee44f/Assets/Enjin%20Integration/Scripts/API/EnjinApiService.cs#L205). +3. The server saves the list of tokens, and the `BackpackUI` [populates the view with the data](https://github.com/enjin/platform-sample-game-client-unity/blob/e154e83723a76861ca762f4b998ef8c8a44ee44f/Assets/Enjin%20Integration/Scripts/UI/BackpackUI.cs#L81). +4. The `BackpackUI` also [subscribes to the `EnjinManager.Instance.OnWalletUpdated` event](https://github.com/enjin/platform-sample-game-client-unity/blob/e154e83723a76861ca762f4b998ef8c8a44ee44f/Assets/Enjin%20Integration/Scripts/UI/BackpackUI.cs#L39) to automatically refresh the inventory after a token is [minted](https://github.com/enjin/platform-sample-game-client-unity/blob/e154e83723a76861ca762f4b998ef8c8a44ee44f/Assets/Enjin%20Integration/Scripts/Core/EnjinManager.cs#L95), [melted](https://github.com/enjin/platform-sample-game-client-unity/blob/e154e83723a76861ca762f4b998ef8c8a44ee44f/Assets/Enjin%20Integration/Scripts/Core/EnjinManager.cs#L107), or [transferred](https://github.com/enjin/platform-sample-game-client-unity/blob/e154e83723a76861ca762f4b998ef8c8a44ee44f/Assets/Enjin%20Integration/Scripts/Core/EnjinManager.cs#L119). + +#### Melting and Transferring Tokens + + * **Melting**: The player [clicks "Melt" in the backpack](https://github.com/enjin/platform-sample-game-client-unity/blob/e154e83723a76861ca762f4b998ef8c8a44ee44f/Assets/Enjin%20Integration/Scripts/UI/BackpackItemController.cs#L38). This flows through [`EnjinManager`](https://github.com/enjin/platform-sample-game-client-unity/blob/e154e83723a76861ca762f4b998ef8c8a44ee44f/Assets/Enjin%20Integration/Scripts/Core/EnjinManager.cs#L100) and sends a request to the [`/api/token/melt` endpoint](https://github.com/enjin/platform-sample-game-client-unity/blob/e154e83723a76861ca762f4b998ef8c8a44ee44f/Assets/Enjin%20Integration/Scripts/API/EnjinApiService.cs#L126). + * **Transferring**: The player [clicks "Send"](https://github.com/enjin/platform-sample-game-client-unity/blob/e154e83723a76861ca762f4b998ef8c8a44ee44f/Assets/Enjin%20Integration/Scripts/UI/BackpackItemController.cs#L59), sending a request to the [`/api/token/transfer` endpoint](https://github.com/enjin/platform-sample-game-client-unity/blob/e154e83723a76861ca762f4b998ef8c8a44ee44f/Assets/Enjin%20Integration/Scripts/API/EnjinApiService.cs#L155). \ No newline at end of file diff --git a/docs/02-guides/01-platform/05-enjin-farmer-sample-game/_category_.json b/docs/02-guides/01-platform/05-enjin-farmer-sample-game/_category_.json new file mode 100644 index 0000000..d3d632f --- /dev/null +++ b/docs/02-guides/01-platform/05-enjin-farmer-sample-game/_category_.json @@ -0,0 +1,3 @@ +{ + "label": "Enjin Farmer Sample Game" +} \ No newline at end of file diff --git a/docs/02-guides/01-platform/05-enjin-discord-bot.md b/docs/02-guides/01-platform/06-enjin-discord-bot.md similarity index 100% rename from docs/02-guides/01-platform/05-enjin-discord-bot.md rename to docs/02-guides/01-platform/06-enjin-discord-bot.md diff --git a/static/img/guides/enjin-farmer-sample-game/backpack.png b/static/img/guides/enjin-farmer-sample-game/backpack.png new file mode 100644 index 0000000..1782f80 Binary files /dev/null and b/static/img/guides/enjin-farmer-sample-game/backpack.png differ diff --git a/static/img/guides/enjin-farmer-sample-game/configure-enjin-game-server-connection.png b/static/img/guides/enjin-farmer-sample-game/configure-enjin-game-server-connection.png new file mode 100644 index 0000000..a97a506 Binary files /dev/null and b/static/img/guides/enjin-farmer-sample-game/configure-enjin-game-server-connection.png differ diff --git a/static/img/guides/enjin-farmer-sample-game/configure-items-1.png b/static/img/guides/enjin-farmer-sample-game/configure-items-1.png new file mode 100644 index 0000000..a1f12bb Binary files /dev/null and b/static/img/guides/enjin-farmer-sample-game/configure-items-1.png differ diff --git a/static/img/guides/enjin-farmer-sample-game/configure-items-2.png b/static/img/guides/enjin-farmer-sample-game/configure-items-2.png new file mode 100644 index 0000000..7932eca Binary files /dev/null and b/static/img/guides/enjin-farmer-sample-game/configure-items-2.png differ diff --git a/static/img/guides/enjin-farmer-sample-game/connection-success.png b/static/img/guides/enjin-farmer-sample-game/connection-success.png new file mode 100644 index 0000000..77c333f Binary files /dev/null and b/static/img/guides/enjin-farmer-sample-game/connection-success.png differ diff --git a/static/img/guides/enjin-farmer-sample-game/harvesting.png b/static/img/guides/enjin-farmer-sample-game/harvesting.png new file mode 100644 index 0000000..76c425b Binary files /dev/null and b/static/img/guides/enjin-farmer-sample-game/harvesting.png differ diff --git a/static/img/guides/enjin-farmer-sample-game/menu-button.png b/static/img/guides/enjin-farmer-sample-game/menu-button.png new file mode 100644 index 0000000..3e1b6a9 Binary files /dev/null and b/static/img/guides/enjin-farmer-sample-game/menu-button.png differ