-
Notifications
You must be signed in to change notification settings - Fork 11
/
template.html
79 lines (79 loc) · 2.4 KB
/
template.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
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Stunt Car Remake</title>
<style type="text/css">
html, body {
margin: 0;
}
.emscripten {
width: 100%;
height: 100%;
display: flex;
position: absolute;
align-items: center;
justify-content: center;
}
.game {
width: auto;
height: 100%;
}
.portrait{
width: 100%;
height: auto;
}
.loading {
position: absolute;
}
.game[width] + .loading {
display: none;
}
</style>
</head>
<body>
<div class="emscripten">
<canvas class="game portrait" oncontextmenu="event.preventDefault()"></canvas>
<div class="loading">Loading...</div>
</div>
<script type="text/javascript">
const $game = document.querySelector('.game');
const widthToHeight = 800 / 480;
const resize = () => {
if(window.innerWidth / window.innerHeight > widthToHeight === $game.classList.contains('portrait')) {
$game.classList.toggle('portrait');
}
}
var Module = {
print(text) {
console.log(Array.prototype.slice.call(arguments).join(' '));
},
printErr() {
console.error(Array.prototype.slice.call(arguments).join(' '));
},
canvas: $game
};
window.addEventListener('resize', resize, false);
resize();
// Work-around chromium autoplay policy
// https://github.com/emscripten-core/emscripten/issues/6511
function resumeAudio(e) {
if (typeof Module === 'undefined'
|| typeof Module.SDL2 == 'undefined'
|| typeof Module.SDL2.audioContext == 'undefined')
return;
if (Module.SDL2.audioContext.state == 'suspended') {
Module.SDL2.audioContext.resume();
}
if (Module.SDL2.audioContext.state == 'running') {
$game.removeEventListener('click', resumeAudio);
document.removeEventListener('keydown', resumeAudio);
}
}
$game.addEventListener('click', resumeAudio);
document.addEventListener('keydown', resumeAudio);
</script>
{{{ SCRIPT }}}
</body>
</html>