-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
84 lines (84 loc) · 3.06 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>@PROJECT_NAME@</title>
<style>
body {
margin: 0;
color: white;
background-color: black;
font-family: sans-serif;
}
#status {
margin-left: 1em;
}
#focus-button {
background-color: rgba(0, 0, 0, 0);
padding: 2.5em;
position: absolute;
width: 100%;
height: 100%;
display: none;
}
</style>
</head>
<body>
<div id="focus-button"></div>
<canvas width="0" height="0" id="canvas"></canvas>
<div id="status">loading.</div>
<script type="text/javascript">
var focusButton = document.getElementById('focus-button');
// In addition to the normal show/hide behavior, activateFocusButton must
// be called before the focus button will be visible. This is so that the
// button doesn't show before the game is even loaded.
function activateFocusButton() {
focusButton.innerHTML = 'game paused; click to continue';
focusButton.style.backgroundColor = 'rgba(0, 0, 0, 0.75)';
}
function hideFocusButton() {
focusButton.style.display = 'none';
}
function showFocusButton() {
focusButton.style.display = 'block';
}
var Module = {
canvas: document.getElementById('canvas'),
statusElement: document.getElementById('status'),
totalDependencies: 0,
monitorRunDependencies: function(left) {
this.totalDependencies = Math.max(this.totalDependencies, left);
if (left > 1) {
this.statusElement.innerHTML = `loading... (${this.totalDependencies - left}/${this.totalDependencies})`;
} else if (left > 0) {
this.statusElement.innerHTML = 'loading...';
} else {
this.statusElement.innerHTML = 'loaded!';
activateFocusButton();
}
},
};
// When this page is embedded in an iframe that perfectly fits the size
// of the canvas (such as on itch.io), focus can be lost when the user
// clicks outside of the iframe and it is not possible to regain focus by
// clicking on the canvas, resulting in the game not responding to input.
//
// Within SDL, be sure to pause and unpause the game by handling the
// SDL_WindowEvents of type SDL_WINDOWEVENT_FOCUS_GAINED and
// SDL_WINDOWEVENT_FOCUS_LOST.
window.onblur = showFocusButton;
window.onfocus = hideFocusButton;
// The window might start without focus; do a one-time check here to show
// the focus button if that is the case.
// NOTE: The first time itch.io loads an in-browser game, the iframe
// starts without focus. But on every subsequent load, the iframe starts
// with focus. Super weird! This handles both situations.
if (!document.hasFocus()) {
showFocusButton();
}
</script>
<script src="@[email protected]">
</script>
</body>
</html>