Player History
To allow the player to view the results of a previous round, the game should show the list of latests rounds and being able to show the round result from the data received from the connector.
Availability
First make sure you can show the history, you cannot show it on demo mode:
let canShowHistory: boolean = ETHEREAL.data.canShowHistoryButton();
Show the list of latests rounds
Using the Ethereal UI
You can use the Ethereal UI to show the list of latests rounds:
ETHEREAL.ui.openMenu(UiMenu.HISTORY);
Manually
Or you can show yourself the list that you obtain with the following code and then you can open the selected round on a new tab (you can obtain the roundId from any round on the list with round.id):
let historyPlugin: HistoryApiPlugin = await ETHEREAL.rgs.loadPlugin(HISTORY_PLUGIN_ID) as HistoryApiPlugin;
let rounds = await historyPlugin.getPlayerHistory(); // List of latests rounds
historyPlugin.openReplay(<roundId>)
Open the game in replay mode
In your game, before anything, you should check if the game is in replay mode:
let inReplay: boolean = ETHEREAL.rgs.data.getPlayMode() === PlayMode.REPLAY;
If the game is in replay, request the data for the round to show:
let historyPlugin: HistoryApiPlugin = await ETHEREAL.rgs.loadPlugin(HISTORY_PLUGIN_ID) as HistoryApiPlugin;
const data = await historyPlugin.prepareReplay();
From this point you can show the result manually using the data.plays information or tell the controller to mock the calls to simulate the same round:
// Obtain the session data from the replay data
await ETHEREAL.rgs.open();
// Obtain the init data from the replay
let initResponse: InitResponse = await ETHEREAL.rgs.init();
// Obtain what is going to be the request and total bet for the next play to prepare your game
let nextRequest = historyPlugin.getNextRequest();
let nextTotalBet = historyPlugin.getNextBet();
// Follow the normal flow of the game, the plays will return the replay round play responses in order, you don't need to specify request or bet on the plays.
let playResponse: PlayResponse = await ETHEREAL.rgs.play(undefined, undefined);
// Repeat the get request / bet / plays until the round end
let roundEnd = ETHEREAL.rgs.data.isRoundEnd();