forked from lazygyu/roulette
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
341 lines (311 loc) · 9.64 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
<!DOCTYPE html>
<html lang="en">
<head>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-5899C1DJM0"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-5899C1DJM0');
</script>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="apple-touch-icon" sizes="57x57" href="assets/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="assets/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="assets/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="assets/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="assets/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="assets/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="assets/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="assets/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="assets/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="assets/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="assets/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="assets/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="assets/favicon-16x16.png">
<link rel="manifest" href="assets/manifest.json">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-TileImage" content="assets/ms-icon-144x144.png">
<meta name="theme-color" content="#ffffff">
<title>Marble Roulette</title>
<style>
* {
box-sizing: border-box;
}
canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
.settings {
position: absolute;
inset: 1rem;
bottom: auto;
padding: 1rem;
border-radius: 0.75em;
box-shadow: inset 0 0 6rem 4px green;
border: 2px solid lightgreen;
background: rgba(0, 0, 0, 0.4);
backdrop-filter: blur(10px);
color: #fff;
font-family:'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-size: 1rem;
font-weight: bold;
z-index: 10;
}
.hide {
display: none !important;
}
.settings:focus-within {
box-shadow: inset 0 0 2rem 4px green;
}
.settings textarea {
width: 100%;
min-height: 4rem;
background-color: transparent;
border: none;
outline: none;
font: inherit;
color: inherit;
}
.settings .actions {
font-size: 0.8rem;
text-align: right;
}
.settings .actions label {
margin-bottom: 0.5rem;
display: block;
}
.settings .text {
margin-top: 0;
font-size: 0.8rem;
font-weight: normal;
color: lightgreen;
}
input[type=number] {
width: 3rem;
text-align: center;
background-color: transparent;
border: none;
outline: none;
font: inherit;
color: inherit;
}
@media screen and (min-width: 768px) {
.settings {
top: auto;
bottom: 24px;
max-width: 50%;
}
#inGame {
width: fit-content;
}
.settings .actions label {
margin: 0 0.5rem 0;
display: inline-block;
}
}
div.copyright {
position: fixed;
bottom: 0;
left: 50%;
transform: translateX(-50%);
color: white;
font-size: 12px;
z-index: 999;
}
div.copyright a {
color: white;
}
#btnShake {
font-size: 2em;
}
div#notice {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 999;
background: rgba(255, 255, 255, 0.8);
padding: 1em;
display: flex;
flex-direction: column;
max-width: 100%;
width: 40em;
}
div#notice button {
width: 50%;
padding: 1em;
align-self: flex-end;
}
div#notice dt {
font-weight: bold;
}
div#notice dd {
list-style: disc;
padding-bottom: .5em;
}
</style>
</head>
<body>
<script type="module" src="./src/index.ts"></script>
<script type="text/javascript">
function getNames() {
const value = document.querySelector('#in_names').value.trim();
return value.split(/[,\r\n]/g).map(v => v.trim()).filter(v => !!v);
}
function parseName(nameStr) {
const weightRegex = /(\/\d+)/;
const countRegex = /(\*\d+)/;
const hasWeight = weightRegex.test(nameStr);
const hasCount = countRegex.test(nameStr);
const name = /^\s*([^\/*]+)?/.exec(nameStr)[1];
const weight = hasWeight ? parseInt(weightRegex.exec(nameStr)[1].replace('/', '')) : 1;
const count = hasCount ? parseInt(countRegex.exec(nameStr)[1].replace('*', '')) : 1;
return {
name,
weight,
count,
};
}
function getReady() {
const names = getNames();
window.roullete.setMarbles(names);
ready = names.length > 0;
}
function setWinnerRank(rank) {
document.querySelector('#in_winningRank').value = rank;
window.options.winningRank = rank - 1;
window.roullete.setWinningRank(window.options.winningRank);
}
let ready = false;
document.addEventListener('DOMContentLoaded', () => {
document.querySelector('#in_names').addEventListener('input', () => {
getReady();
});
document.querySelector('#in_names').addEventListener('blur', () => {
const nameSource = getNames();
const nameSet = new Set();
const nameCounts = {};
nameSource.forEach(nameSrc => {
const name = parseName(nameSrc);
const key = name.weight > 1 ? `${name.name}/${name.weight}` : name.name;
if (!nameSet.has(key)) {
nameSet.add(key);
nameCounts[key] = 0;
}
nameCounts[key] += name.count;
});
const result = [];
Object.keys(nameCounts).forEach(key => {
if (nameCounts[key] > 1) {
result.push(`${key}*${nameCounts[key]}`);
} else {
result.push(key);
}
});
document.querySelector('#in_names').value = result.join(',');
getReady();
});
document.querySelector('#btnShuffle').addEventListener('click', () => {
getReady();
});
document.querySelector('#btnStop').addEventListener('click', () => {
window.roullete.reset();
ready = false;
});
document.querySelector('#btnStart').addEventListener('click', () => {
if (!ready) return;
gtag('event', 'start', {
'event_category': 'roulette',
'event_label': 'start',
'value': window.roullete.getCount(),
});
window.roullete.start();
document.querySelector('#settings').classList.add('hide');
});
document.querySelector('#chkSkill').addEventListener('change', (e) => {
window.options.useSkills = e.target.matches(':checked');
window.roullete.setWinningRank(window.options.winningRank);
});
document.querySelector('#in_winningRank').addEventListener('change', (e) => {
const v = parseInt(e.target.value, 10);
setWinnerRank(isNaN(v) ? 0 : v);
});
document.querySelector('#btnRandomWinner').addEventListener('click', () => {
const total = window.roullete.getCount();
const rank = Math.floor(Math.random() * total + 1);
setWinnerRank(rank);
});
document.querySelector('#btnShake').addEventListener('click', () => {
window.roullete.shake();
gtag('event', 'shake', {
'event_category': 'roulette',
'event_label': 'shake',
'value': 1,
});
});
window.roullete.addEventListener('goal', () => {
ready = false;
document.querySelector('#settings').classList.remove('hide');
});
window.roullete.addEventListener('shakeAvailableChanged', (e) => {
document.querySelector('#inGame').classList.toggle('hide', !e.detail);
});
document.querySelector('#btnShuffle').click();
const currentNotice = 20230802;
const closed = parseInt(localStorage.getItem('noticeClose') || '0', 10);
if (closed < currentNotice) {
document.querySelector('#notice').classList.remove('hide');
}
document.querySelector('#btnNoticeClose').addEventListener('click', () => {
document.querySelector('#notice').classList.add('hide');
localStorage.setItem('noticeClose', String(currentNotice));
});
});
</script>
<div id="notice" class="hide">
<h3>Change logs</h3>
<dl>
<dt>2023-08-02</dt>
<dd>Now the names will not cover the whole screen if there are many. You can scroll the names with your mouse wheel.</dd>
<dt>2023-07-29</dt>
<dd>Adjusted the map to prevent a marble stays too long in a specific place.</dd>
<dt>2023-07-21</dt>
<dd>Show change logs when there is a new update.</dd>
<dd>Improve the performance when there are too many marbles in the game.</dd>
<dd>Fixed the issue that the slow motion is not smooth.</dd>
<dd>Now end the game immediately if only one marble survives and the winning rank is the last.</dd>
<dt>2023-05-29</dt>
<dd>Now you can shake the game if the marbles are stuck for over 3 seconds.</dd>
</dl>
<button type="button" id="btnNoticeClose">Close</button>
</div>
<div id="settings" class="settings">
<p class="text">
You can set weight values for each member by putting a number after each name with a slash. (ex: Tom/2, Jane/5)<br />
You can set the count of each member by putting a number after each name with a star. (ex: Tom*2, Jane*5)
</p>
<textarea id="in_names" placeholder="Input names saparated by commas or line feed here">짱구*5, 짱아*10, 흰둥이*3</textarea>
<div class="actions">
<label>
The winner is #<input type="number" id="in_winningRank" value="1" min="1" />
</label>
<button id="btnRandomWinner">Random Winner</button>
<label>
<input type="checkbox" id="chkSkill" checked />
Using skills
</label>
<button id="btnStop">Stop</button>
<button id="btnStart">Start</button>
<button id="btnShuffle">Shuffle</button>
</div>
</div>
<div id="inGame" class="settings hide">
<button id="btnShake">Shake!</button>
</div>
<div class="copyright">© 2023.<a href="https://lazygyu.net" target="_blank">lazygyu</a></div>
</body>
</html>