-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
152 lines (130 loc) · 3.79 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<!DOCTYPE html>
<html>
<head>
<style>
html,
body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
font-family: sans-serif;
font-size: 11px;
}
body {
display: grid;
grid-template-columns: 1fr;
grid-template-rows: auto 1fr;
}
#svgOutput {
display: flex;
align-items: center;
justify-content: center;
}
line {
stroke-linecap: round;
visibility: hidden;
}
line.one-sided {
stroke: #000;
}
line.two-sided {
stroke: #aaa;
}
header {
display: grid;
background-color: #f0f0f0;
padding: 4px 12px;
grid-gap: 12px;
grid-auto-flow: column;
grid-template-columns: auto auto auto 1fr auto auto;
grid-template-rows: auto;
justify-content: start;
align-items: center;
border-bottom: 1px solid #ddd;
}
#level {
min-width: 100px;
}
</style>
</head>
<body>
<header>
Wad: <input id="wfInput" type="file" />
<select id="level" disabled></select>
<input id="showLine" type="range" min="1" disabled />
<button id="stop" disabled>■</button>
<button id="play" disabled>▶</button>
</header>
<div id="svgOutput"></div>
<script type="module">
import { Wad } from './wadparser.js';
const fr = new FileReader();
const wfInput = document.getElementById('wfInput');
const svgOutput = document.getElementById('svgOutput');
const level = document.getElementById('level');
const showLine = document.getElementById('showLine');
const play = document.getElementById('play');
const stop = document.getElementById('stop');
let wad = null;
let handle = null;
const baseSpeed = 100;
let speed = baseSpeed;
play.addEventListener('click', () => {
if (handle) {
window.clearInterval(handle);
speed = speed / 2;
} else {
speed = baseSpeed;
}
handle = window.setInterval(() => {
showLine.value = parseInt(showLine.value, 10) + 1;
if (showLine.value === showLine.max) {
showLine.value = 1;
}
updateVisibility();
}, speed);
});
stop.addEventListener('click', () => {
window.clearInterval(handle);
handle = null;
});
const updateLevel = () => {
let lnum = parseInt(level.value);
if (Number.isFinite(lnum)) {
const { width, height } = svgOutput.getBoundingClientRect();
svgOutput.innerHTML = wad.levels[lnum].asSvg(width, height);
showLine.max = wad.levels[lnum].lines.length;
stop.disabled = play.disabled = showLine.disabled = false;
showLine.value = showLine.max;
updateVisibility();
}
};
level.addEventListener('change', updateLevel);
fr.onload = event => {
const buf = event.target.result;
wad = new Wad(buf);
level.innerHTML = wad.levels.map(
(l, i) => `<option value="${i}">${l.name}</option>`
);
updateLevel();
};
wfInput.addEventListener('change', () => {
if (wfInput.files[0]) {
fr.readAsArrayBuffer(wfInput.files[0]);
level.disabled = false;
}
});
let lineRuleIndex = -1;
const updateVisibility = () => {
if (lineRuleIndex > -1) {
document.styleSheets[0].deleteRule(lineRuleIndex);
}
lineRuleIndex = document.styleSheets[0].insertRule(`
svg line:nth-child(-n+${showLine.value}) { visibility: visible; }
`);
};
showLine.addEventListener('input', updateVisibility);
</script>
</body>
</html>