The wallet feature is holding a users virtual balance of a particular currency. E.g. the user has 100 coins in his wallet. A wallet can contain multiple currencies, e.g. coins and diamonds.
A user can buy items or bundles (a pack of multiple items) with his virtual currency. Let’s say a user can buy a sword with 100 coins.
When a user bought an item in the in-game shop it will be added to his personal inventory.
Before talking about the actual calls for these features it’s good to know the structure of the objects that the Spil SDK uses to manage these features:
- Spil Game Data
- Spil Player Data
Spil Game Data
The Spil Game Data contains the information about the game. Like which currencies, Items, Bundles, Shop and Shop Promotions a game might have. See below the details:
- Currencies â this list contains all the currencies present in the game and defined in the Spil SLOT interface; each Currency of this list has an id, a name and a type (0 = premium and 1 = non-premium)
- Items â this list contains all the items present in the game and defined in the Spil SLOT interface; each Item of this list has an id, a name and a type (0 = Consumable, 1 = Booster and 2 = Permanent)
- Bundles â this list contains all the bundles present in the game and defined in the Spil SLOT interface; each Bundle contains an id, a name, a list of one or more Items that will be gained by the player when he buys the bundle and a list of one or more prices that relate to the Currencies.
- Shop â this object contains a configuration of the shop as defined in SLOT interface; the object contains a list of Tabs that the define the shop layout; each Tab contains a name, a position and a list of Entries; each Entry in the list has a label that would be displayed in the shop, a position and a Bundle id which points to the received Bundles
- Promotions â this list contains all the promotions that would be associated with the Shop and configured in the SLOT interface; each Promotion contains a Bundle id which would point to the received Bundles, an amount value which would represent how many amounts of the bundle will be in the promotion, an updated prices list, a discount label and a start and end date
Spil Player Data
A Player Data contains the information related to what the user owns, the users Wallet and Inventory. See below the details:
- Wallet â this object contains the information regarding the userâs balance; the Wallet contains a list of Currencies that match the Currencies defined in the Spil Game Data with the addition of having a current balance and a delta, an offset which informs the Spil server which version of the wallet the game is currently having and a logic field which could either be CLIENT or SERVER (for now CLIENT logic is fully implemented)
- Inventory â similar object to the Wallet except it holds information about the current Items that the user have
Step 1) Default values
If there is no network connection, then the SDK will use the latest known defaults.
In exceptional cases, people will open the app for the first time and donât have an Internet connection. For this specific case we need to add two defaults JSON files in the Root folder of the project:
Add a file named âdefaultGameData.jsonâ in the assets/streaming assets folder of your project.
Here is an example of a simple example file:
Add a file named âdefaultPlayerData.jsonâ in the assets/streaming assets folder of your project.
Here is an example of a simple example file:
Step 2) Register Callbacks
The second step that needs to be done is to register the two callbacks using the following code:
For the Spil Game Data:
For the Player Data:
Step 3) Retrieve the data
After everything has been setup you can use the following method to retrieve the full Spil Game Data (contains information regarding Currencies, Items, Bundles, Shop and Promotions):
In order to retrieve the Wallet data use the following code:
Step 4) Update the Wallet / Inventory
The last step is to use one of the following operations to update your Users Wallet or Inventory:
Item and Bundles Image Processing and Loading
The Items and Bundles objects provided by the SDK can also contain images that can be displayed inside your game.
In order to download and display these images use the following information:
The Spil SDK does also support Gacha Boxes, they are handled like normal items, they can be added towards the inventory and bought from an ingame store, to open a gacha from the inventory call: