-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.html
115 lines (97 loc) · 4.94 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Achtung, die Kurve!</title>
<meta charset="UTF-8" />
<meta name="author" content="Simon Alling" />
<meta name="description" content="A clone of the classic DOS game from 1995 that runs in the browser." />
<meta name="keywords" content="Achtung, Kurve, Zatacka, KONEC, HRY, HTML, JavaScript, DOS" />
<meta property="og:url" content="http://kurve.se" />
<meta property="og:title" content="Achtung, die Kurve!" />
<meta property="og:description" content="A clone of the classic DOS game from 1995 that runs in the browser." />
<meta property="og:image" content="http://kurve.se/resources/kurve-share.png" />
<link rel="stylesheet" href="css/Zatacka.css" />
<link rel="apple-touch-icon" sizes="57x57" href="resources/icon/apple-icon-57x57.png" />
<link rel="apple-touch-icon" sizes="60x60" href="resources/icon/apple-icon-60x60.png" />
<link rel="apple-touch-icon" sizes="72x72" href="resources/icon/apple-icon-72x72.png" />
<link rel="apple-touch-icon" sizes="76x76" href="resources/icon/apple-icon-76x76.png" />
<link rel="apple-touch-icon" sizes="114x114" href="resources/icon/apple-icon-114x114.png" />
<link rel="apple-touch-icon" sizes="120x120" href="resources/icon/apple-icon-120x120.png" />
<link rel="apple-touch-icon" sizes="144x144" href="resources/icon/apple-icon-144x144.png" />
<link rel="apple-touch-icon" sizes="152x152" href="resources/icon/apple-icon-152x152.png" />
<link rel="apple-touch-icon" sizes="180x180" href="resources/icon/apple-icon-180x180.png" />
<link rel="icon" type="image/png" sizes="192x192" href="resources/icon/android-icon-192x192.png" />
<link rel="icon" type="image/png" sizes="32x32" href="resources/icon/favicon-32x32.png" />
<link rel="icon" type="image/png" sizes="96x96" href="resources/icon/favicon-96x96.png" />
<link rel="icon" type="image/png" sizes="16x16" href="resources/icon/favicon-16x16.png" />
<link rel="manifest" href="manifest.json" />
<meta name="msapplication-TileColor" content="#ffffff" />
<meta name="msapplication-TileImage" content="resources/icon/ms-icon-144x144.png" />
<meta name="theme-color" content="#ffffff" />
</head>
<body>
<h1>Achtung, die Kurve!</h1>
<div id="elm-node"></div>
<script src="./build/ZATACKA.js"></script>
<script>
const app = Elm.Main.init({ node: document.getElementById("elm-node") });
function drawSquare(canvas, { position: { leftEdge, topEdge }, thickness, color }) {
const context = canvas.getContext("2d");
context.fillStyle = color;
context.fillRect(leftEdge, topEdge, thickness, thickness);
}
function clearRectangleIfCanvasExists(canvas, { x, y, width, height }) {
const context = canvas?.getContext("2d");
context?.clearRect(x, y, width, height);
}
app.ports.render.subscribe(squares => {
const canvas_main = document.getElementById("canvas_main");
for (const square of squares) {
drawSquare(canvas_main, square);
}
});
app.ports.clear.subscribe(rectangle => {
const canvas_main = document.getElementById("canvas_main");
clearRectangleIfCanvasExists(canvas_main, rectangle);
});
app.ports.renderOverlay.subscribe(squares => {
const canvas_overlay = document.getElementById("canvas_overlay");
clearRectangleIfCanvasExists(canvas_overlay, { x: 0, y: 0, width: canvas_overlay?.width, height: canvas_overlay?.height }); // Very large numbers don't work; see the commit that added this comment.
for (const square of squares) {
drawSquare(canvas_overlay, square);
}
});
document.addEventListener("keydown", event => {
const isDeveloperCommand = (
["F5", "F12"].includes(event.key)
||
(event.ctrlKey && event.key === "r") // Ctrl + R
||
(event.metaKey && event.key === "r") // Cmd + R on macOS 👀
);
if (!isDeveloperCommand) {
event.preventDefault();
}
if (!event.repeat) {
app.ports.onKeydown.send(event.code);
}
});
document.addEventListener("keyup", event => {
// Traditionally we never prevented default on keyup.
app.ports.onKeyup.send(event.code);
});
document.addEventListener("mousedown", event => {
app.ports.onMousedown.send(event.button);
});
document.addEventListener("mouseup", event => {
app.ports.onMouseup.send(event.button);
});
document.addEventListener("contextmenu", event => {
event.preventDefault();
});
window.addEventListener("blur", () => {
app.ports.focusLost.send(null);
});
</script>
</body>
</html>