-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.html
132 lines (111 loc) · 4.1 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<html>
<head>
<title>GameRoy</title>
<link rel="icon"
href="data:image/svg+xml,%3Csvg version='1.1' viewBox='0 0 64 64' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='m8 56h-8v-48h8v-8h48v8h8v48h-8v8h-48z' fill='%23000f05'/%3E%3Cpath d='m24 8v16h-16v16h16v16h16v-16h16v-16h-16v-16z' fill='%2334ff30'/%3E%3C/svg%3E" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
* {
margin: 0;
padding: 0;
oveflow: hidden;
}
html, body {
width: 100%;
height: 100%;
}
body {
background-repeat: no-repeat;
background-attachment: fixed;
background-image: linear-gradient(#001000, #002000);
}
.centered {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
canvas {
outline: none;
-webkit-tap-highlight-color: rgba(255, 255, 255, 0);
/* mobile webkit */
display: block;
z-index: 0;
image-rendering: crisp-edges;
}
progress {
width: 350px;
height: 40px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 1;
-webkit-appearance: none;
appearance: none;
}
progress[value]::-webkit-progress-bar, progress {
background-color: #000800;
border-radius: 0px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.25) inset;
}
progress[value]::-webkit-progress-value {
background-color: #00ff00;
}
progress[value]::-moz-progress-bar {
background-color: #00ff00;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script defer type="module">
import init, { run, resize_canvas } from './pkg/gameroy_wasm.js';
let elem = document.getElementById('loading');
$.ajax({
url: './pkg/gameroy_wasm_bg.wasm',
xhr: function () {
var xhr = new window.XMLHttpRequest();
xhr.responseType = 'arraybuffer';
//Download progress
xhr.addEventListener("progress", function (evt) {
let percentComplete = 1;
if (evt.lengthComputable) {
percentComplete = evt.loaded / evt.total;
} else if (evt.loaded) {
percentComplete = evt.loaded / 3467246;
}
elem.value = Math.floor(percentComplete * 100);
}, false);
return xhr;
}
}).done(function (data, textStatus, jqXHR) {
init(data).then(() => {
elem.parentNode.removeChild(elem);
let canvas = document.getElementById('main_canvas');
function resize() {
let dpi = window.devicePixelRatio;
const vw = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0)
const vh = Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0)
canvas.width = vw;
canvas.height = vh;
console.log(dpi, canvas.width, canvas.height);
resize_canvas(canvas.width*dpi, canvas.height*dpi);
}
window.addEventListener('resize', function() {
resize();
});
resize();
run();
});
}).fail(function (jqXHR, settings, exception) {
console.log('could not load');
});
</script>
</head>
<body oncontextmenu="return false" scroll="no">
<div class="centered">
<canvas id="main_canvas" tabindex="0"></canvas>
<progress id="loading" max="100" value="50"></progress>
</div>
</body>
</html>