Source code and scenarios in Winter Starfall
This tutorial contains instructions for downloading and running the source code for Winter Starfall, and a walkthrough of the code samples demonstrating best practices for login and purchase scenarios.Source code download
Prerequisites
- Install Node JS
- Install Visual Studio Code
Setup for local development
- Download the source code from GitHub.
- In VS Code, open the
/websitefolder and opt to install all the extensions it recommends. - In the
/websitedirectory, run npm install to install all dependencies. - Use
npm run devto start the site. Select the link it offers to view the site.
Azure credentials
To update the AZURE_CREDENTIALS secrets, run this command in the Azure Portal shell:az ad sp create-for-rbac --name "VanguardOutrider2" --role contributor --scopes /subscriptions/YOUR_SUBSCRIPTION_ID/resourceGroups/YOUR_RESOURCE_GROUP_NAME --json-auth
Login flow
The player authentication flow in Winter Starfall has two steps: the login call and post-login functions that are used to get the player’s information from the service and load them into the correct location in the story.Player authentication
For the login portion, the file use-login.ts defines a TypeScript wrapper function that handles the multiple authentication methods available to players. Lines 144-169 define the callback function for logging in with an email address, and call the post-login functions if login succeeds.Post login: Getting player data
Once the security token has been retrieved, it is used to run the post login functions to get the saved game state. Lines 340-378 define postLoginFunctions, which calls various Economy and PlayFab Services APIs to load the correct story location, inventory items, currency, etc based on the player.- First
ClientGetTitleDatagets the secret key needed for all API calls - Then
EconomySearchItemssearches the catalog for currency and item types - Which is used as input to
EconomyGetInventoryItemsto return the player’s inventory items - Then
ClientGetUserDataretrieves the value that stores the story location as part of a player’s data.
Purchase flow
At certain points in the game, the player has the option to purchase and sell inventory items from the store. The purchase flow is implemented in another wrapper function. In the file use-store.ts, lines 40-69 bring up the correct store that the player encounters at a specific location and populates the items for sale by searching the catalog.EconomyGetItem is defined in use-playfab.ts at lines 423-446, within which the PlayFab Economy API GetItems is used to search the catalog and return items.
PurchaseInventoryItems API is made. This is defined in use-playfab.ts at lines 540-565.
Selling items
The selling flow is an example of how to use Azure Functions driven CloudScript to extend the functionality of the Economy system. SellItem.cs defines the CloudScript function that executes when selling an item. Lines 49-61 are where PlayFab’sGetTitleData API is used to return the store multiplier and calculate the sale price.
To run Winter Starfall locally you’ll need an Azure account to support the CloudScript functions. You can sign up for a free Azure account and then follow the instructions above to reset the Azure credentials correctly.
See also
- Login flow
- Purchase flow
- Economy V2 documentation
- Another good next step to learning more about Economy V2 is to try out the crafting game tutorial, which focuses on building a sample game using the store and inventory functions.
