-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.html
49 lines (44 loc) · 1.95 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Sample Litemint App</title>
</head>
<body>
<h1 id="greeting"></h1>
<h3 id="scoreResult"></h3>
<p id="userInfo"></p>
<script src="litemint.api.min.js"></script>
<script>
window.addEventListener('DOMContentLoaded', (event) => {
// Call once when your app is ready to display
// (e.g. in DOMContentLoaded event).
// Optionally, pass your API KEY when initializing from server.
Litemint.initialize();
// Retrieve the current user token.
Litemint.getToken().then(token => {
// If the token is valid a user object is returned.
// Optional set onlyFederated to true if your game requires accounts with gamer ID.
const onlyFederated = false;
Litemint.validateToken(token, onlyFederated)
.then(user => {
document.getElementById("greeting").innerHTML = "Hello " + (user.id || user.address);
document.getElementById("userInfo").innerHTML = JSON.stringify(user);
// Submit a score to the leaderboards.
// It is recommended to do so from your game server to prevent cheating.
const scoreToSubmit = 700;
Litemint.submitScore(token, scoreToSubmit, onlyFederated).then(result => {
document.getElementById("scoreResult").innerHTML =
result.error ? "Failed to submit Score." : "Score submitted successfully.";
});
})
.catch(err => {
document.getElementById("greeting").innerHTML = err;
});
});
// Call to explicitly close your app.
// Litemint.close();
});
</script>
</body>
</html>