-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
142 lines (113 loc) · 3.51 KB
/
index.html
File metadata and controls
142 lines (113 loc) · 3.51 KB
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
133
134
135
136
137
138
139
140
141
142
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Lode Runner</title>
<style>
html,
body {
height: 100%;
}
#dos {
width: 100%;
height: 100%;
}
</style>
<!-- js-dos style sheet -->
<link rel="stylesheet" href="./js-dos.css">
<!-- js-dos -->
<script src="./js-dos.js"></script>
<!-- Hammer.js for gesture handling -->
<script src="./hammer.min.js"></script>
</head>
<body>
<div id="dos" style="width: 100%; height: 100%"></div>
<script type="text/javascript">
// Get the container element
var el = document.getElementById("dos");
// Initialize Hammer.js on the container
var hm = new Hammer.Manager(el);
// Initialize js-dos instance
const dosInstance = Dos(el, {
url: "./lr.jsdos",
pathPrefix: "./emulators/",
theme: "dark",
kiosk: false,
autoStart: true,
noCursor: true,
noCloud: true,
noNetworking: true,
onEvent: (event, arg) => {
console.log("Event", event, arg);
if (event === "ci-ready") {
window.ci = arg;
}
},
});
// Key codes for gesture mapping
const KEY_ENT = 257;
const KEY_F1 = 290;
const KEY_F2 = 291;
const KEY_P2 = 322;
const KEY_P4 = 324;
const KEY_P5 = 325;
const KEY_P6 = 326;
const KEY_P8 = 328;
// Prevent default touch actions like scrolling and refreshing
el.addEventListener('touchmove', function (e) {
e.preventDefault();
}, { passive: false });
hm.add(new Hammer.Tap({ event: "singletap", taps: 1 }));
hm.on("singletap", function (e) {
var rect = el.getBoundingClientRect();
var centerX = rect.left + rect.width / 2.0;
var centerY = rect.top + rect.height / 2.0;
var x = e.center.x - centerX;
var y = e.center.y - centerY;
var r = Math.min(rect.width, rect.height) / 2.0;
var k = KEY_ENT;
if (x * x + y * y < r * r) {
k = KEY_ENT;
} else if (x < 0) {
k = KEY_F1;
} else {
k = KEY_F2;
}
window.ci.sendKeyEvent(k, true);
window.ci.sendKeyEvent(k, false);
});
hm.add(new Hammer.Pan({ event: "pan" }));
hm.get("pan").set({ direction: Hammer.DIRECTION_ALL });
var lastPan = "none";
hm.on("panstart panend pancancel", function (e) {
lastPan = "none";
});
hm.on("panleft panright panup pandown", function (e) {
if (e.type == lastPan) {
return;
}
lastPan = e.type;
var k = KEY_P5;
switch (e.type) {
case "panleft":
k = KEY_P4;
break;
case "panright":
k = KEY_P6;
break;
case "panup":
k = KEY_P8;
break;
case "pandown":
k = KEY_P2;
break;
default:
k = KEY_P5;
break;
}
window.ci.sendKeyEvent(k, true);
window.ci.sendKeyEvent(k, false);
});
</script>
</body>
</html>