|
3 | 3 | import { onMount } from 'svelte'; |
4 | 4 |
|
5 | 5 | interface Question { |
| 6 | + index: number; |
6 | 7 | points: string; |
7 | 8 | question: string; |
8 | 9 | answer: string; |
|
23 | 24 | let categories: string[] = []; |
24 | 25 | let questions: Question[][] = []; |
25 | 26 |
|
| 27 | + let currentFace = 1; |
| 28 | + let rolling = false; |
| 29 | + let rollInterval: string | number | NodeJS.Timeout | undefined; |
| 30 | +
|
26 | 31 | const defaultQuestion: Question = { |
| 32 | + index: 0, |
27 | 33 | points: '', |
28 | 34 | question: '', |
29 | 35 | answer: '', |
|
33 | 39 |
|
34 | 40 | const selectedQuestion = writable(defaultQuestion); |
35 | 41 | const showModal = writable(false); |
36 | | - const showFinalJeopardy = writable(false); |
37 | 42 |
|
38 | 43 | const handleFileUpload = async (event: Event) => { |
39 | 44 | const input = event.target as HTMLInputElement; |
|
51 | 56 | (categoryObject) => Object.keys(categoryObject)[0], |
52 | 57 | ); |
53 | 58 |
|
54 | | - questions = data[boardTitle].map((categoryObject) => { |
| 59 | + questions = data[boardTitle].map((categoryObject, categoryIndex) => { |
55 | 60 | const categoryName = Object.keys(categoryObject)[0]; |
56 | | - return categoryObject[categoryName].map((question) => ({ |
57 | | - points: question.points, |
58 | | - question: question.question, |
59 | | - answer: question.answer, |
60 | | - visited: false, |
61 | | - showAnswer: false, |
62 | | - })); |
| 61 | + return categoryObject[categoryName].map( |
| 62 | + (question, questionIndex) => ({ |
| 63 | + index: categoryIndex * 100 + questionIndex + 1, |
| 64 | + points: question.points, |
| 65 | + question: question.question, |
| 66 | + answer: question.answer, |
| 67 | + visited: false, |
| 68 | + showAnswer: false, |
| 69 | + }), |
| 70 | + ); |
63 | 71 | }); |
64 | 72 | }; |
65 | 73 |
|
|
70 | 78 | const selectQuestion = (question: Question, i: number, j: number) => { |
71 | 79 | selectedQuestion.set(question); |
72 | 80 | questions[i][j].visited = true; |
| 81 | + }; |
| 82 | +
|
| 83 | + const openModal = () => { |
73 | 84 | showModal.set(true); |
74 | 85 | }; |
75 | 86 |
|
|
87 | 98 |
|
88 | 99 | function downloadSample() { |
89 | 100 | const a = document.createElement('a'); |
90 | | - a.href = 'samples/trials-jeopardy-sample.json'; |
| 101 | + a.href = 'samples/trials-pursuit-sample.json'; |
91 | 102 | a.download = 'sample.json'; |
92 | 103 |
|
93 | 104 | document.body.appendChild(a); |
|
97 | 108 |
|
98 | 109 | // dice stuff |
99 | 110 |
|
100 | | - let currentFace = 1; |
101 | | - let rolling = false; |
102 | | - let rollInterval: string | number | NodeJS.Timeout | undefined; |
103 | | -
|
104 | 111 | const rollDice = () => { |
105 | 112 | if (rolling) return; |
106 | 113 |
|
107 | 114 | rolling = true; |
108 | | -
|
109 | 115 | rollInterval = setInterval(() => { |
110 | 116 | currentFace = Math.floor(Math.random() * 6) + 1; |
111 | 117 | }, 100); |
|
149 | 155 | ); |
150 | 156 | </script> |
151 | 157 |
|
152 | | -<button class="back-button" on:click={() => goBack()}>{'< back'}</button> |
| 158 | +<button class="back-button hov-btn" on:click={() => goBack()}>{'< back'}</button> |
153 | 159 |
|
154 | 160 | {#if false} |
155 | 161 | <div class="container"> |
|
178 | 184 | <div class="dice-container"> |
179 | 185 | <h1>{boardTitle}</h1> |
180 | 186 | <div |
181 | | - class="dice" |
| 187 | + class="dice hov-btn" |
182 | 188 | aria-label="Roll the dice" |
183 | 189 | role="button" |
184 | 190 | tabindex="0" |
|
194 | 200 | Rolled a {currentFace} ! |
195 | 201 | {/if} |
196 | 202 | </div> |
| 203 | + |
| 204 | + <div> |
| 205 | + <button class="show-question-btn hov-btn" on:click={openModal}> |
| 206 | + show question! |
| 207 | + </button> |
| 208 | + </div> |
197 | 209 | </div> |
198 | 210 |
|
199 | 211 | <!-- main board --> |
|
214 | 226 | </div> |
215 | 227 | {/if} |
216 | 228 |
|
| 229 | +{#if $showModal} |
| 230 | + <div |
| 231 | + class="modal-overlay" |
| 232 | + role="button" |
| 233 | + tabindex="0" |
| 234 | + on:click={closeModal} |
| 235 | + on:keydown={closeModal} |
| 236 | + > |
| 237 | + <div |
| 238 | + class="modal" |
| 239 | + role="button" |
| 240 | + tabindex="0" |
| 241 | + on:click|stopPropagation |
| 242 | + on:keydown|stopPropagation |
| 243 | + > |
| 244 | + {#if $selectedQuestion} |
| 245 | + <h4>[{$selectedQuestion.points} points]</h4> |
| 246 | + <br /> |
| 247 | + <h2>{$selectedQuestion.question}</h2> |
| 248 | + {#if $selectedQuestion.showAnswer} |
| 249 | + <p>{$selectedQuestion.answer}</p> |
| 250 | + {/if} |
| 251 | + <div class="button-set"> |
| 252 | + <button |
| 253 | + class="reveal-button hov-btn" |
| 254 | + on:click={() => |
| 255 | + ($selectedQuestion.showAnswer = !$selectedQuestion.showAnswer)} |
| 256 | + > |
| 257 | + reveal answer |
| 258 | + </button> |
| 259 | + <button class="close-button hov-btn" on:click={closeModal}>close</button> |
| 260 | + </div> |
| 261 | + {/if} |
| 262 | + </div> |
| 263 | + </div> |
| 264 | +{/if} |
| 265 | + |
217 | 266 | <style> |
218 | 267 | @import url('https://fonts.googleapis.com/css2?family=Fira+Mono:wght@400;500;700&family=Pixelify+Sans:wght@400..700&display=swap'); |
219 | 268 |
|
|
240 | 289 | .back-button { |
241 | 290 | font-family: 'Pixelify Sans', 'Comic Sans MS', 'Arial', sans-serif; |
242 | 291 | position: absolute; |
243 | | - top: 1rem; |
244 | | - left: 1rem; |
| 292 | + top: 2rem; |
| 293 | + left: 2rem; |
245 | 294 | padding: 0.5rem 1rem; |
246 | 295 | background-color: #333; |
247 | 296 | color: #f9f9f9; |
|
266 | 315 | width: 70%; |
267 | 316 | height: 100%; |
268 | 317 | background-color: #000; |
| 318 | + border-right: 10px solid #0a0a0a; |
| 319 | + } |
| 320 | + .board-container > * { |
| 321 | + border-right: none; |
269 | 322 | } |
270 | 323 |
|
271 | 324 | .dice-container { |
|
290 | 343 | cursor: pointer; |
291 | 344 | background-color: #783333; |
292 | 345 | box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2); |
| 346 | + } |
| 347 | +
|
| 348 | + .hov-btn { |
293 | 349 | transition: transform 0.2s; |
294 | 350 | } |
295 | 351 |
|
296 | | - .dice:hover { |
| 352 | + .hov-btn:hover { |
297 | 353 | transform: scale(1.15); |
298 | 354 | } |
299 | 355 |
|
300 | | - .dice:active { |
| 356 | + .hov-btn:active { |
301 | 357 | transform: scale(0.95); |
302 | 358 | } |
303 | 359 |
|
|
306 | 362 | font-size: 2rem; |
307 | 363 | } |
308 | 364 |
|
309 | | - .score-container { |
310 | | - flex: 1; |
311 | | - flex-basis: 30%; |
312 | | - width: 30%; |
313 | | - background-color: #242e2b; |
314 | | - border-left: 10px solid #101212; |
315 | | - padding: 2rem; |
316 | | - } |
317 | | -
|
318 | 365 | /* board */ |
319 | 366 |
|
320 | 367 | .board { |
321 | 368 | display: grid; |
322 | 369 | grid-template-columns: repeat(5, 10rem); |
323 | 370 | grid-template-rows: repeat(5, 10rem); |
324 | | - gap: 2px; |
| 371 | + gap: 1rem; |
325 | 372 | margin: 20px auto; |
326 | 373 | } |
327 | 374 |
|
|
333 | 380 | justify-content: center; |
334 | 381 | background-color: #000000; |
335 | 382 | border: 2px solid #000000; |
336 | | - border-radius: 8px; |
| 383 | + border-radius: 1rem; |
337 | 384 | font-size: 2rem; |
338 | 385 | } |
339 | 386 |
|
|
342 | 389 | color: rgb(0, 0, 0); |
343 | 390 | font-weight: bold; |
344 | 391 | } |
| 392 | +
|
| 393 | + .show-question-btn { |
| 394 | + font-family: 'Pixelify Sans', 'Comic Sans MS', 'Arial', sans-serif; |
| 395 | + margin-top: 2rem; |
| 396 | + padding: 0.5rem 1rem; |
| 397 | + background-color: #64355b; |
| 398 | + color: #fff; |
| 399 | + border: 0.2rem solid #391f34; |
| 400 | + border-radius: 0.3rem; |
| 401 | + font-size: 1.5rem; |
| 402 | + cursor: pointer; |
| 403 | + font-weight: 500; |
| 404 | + transition: transform 0.2s; |
| 405 | + } |
| 406 | +
|
| 407 | + /* scores */ |
| 408 | +
|
| 409 | + .score-container { |
| 410 | + flex: 1; |
| 411 | + flex-basis: 30%; |
| 412 | + width: 30%; |
| 413 | + background-color: #242e2b; |
| 414 | + border-left: 10px solid #101212; |
| 415 | + padding: 2rem; |
| 416 | + } |
| 417 | +
|
| 418 | + /* modal */ |
| 419 | +
|
| 420 | + .modal-overlay { |
| 421 | + position: fixed; |
| 422 | + top: 0; |
| 423 | + left: 0; |
| 424 | + width: 100%; |
| 425 | + height: 100%; |
| 426 | + background: rgba(0, 0, 0, 0.8); |
| 427 | + display: flex; |
| 428 | + justify-content: center; |
| 429 | + align-items: center; |
| 430 | + } |
| 431 | +
|
| 432 | + .modal { |
| 433 | + background: #1a1a1a; |
| 434 | + padding: 2rem; |
| 435 | + border: 0.3rem solid white; |
| 436 | + border-radius: 0.3rem; |
| 437 | + text-align: center; |
| 438 | + align-items: center; |
| 439 | + color: #f9f9f9; |
| 440 | + max-width: 500px; |
| 441 | + width: 80%; |
| 442 | + font-size: 2rem; |
| 443 | + } |
| 444 | +
|
| 445 | + .button-set { |
| 446 | + display: flex; |
| 447 | + flex-direction: row; |
| 448 | + align-items: center; |
| 449 | + justify-content: center; |
| 450 | + gap: 2rem; |
| 451 | + } |
| 452 | +
|
| 453 | + .reveal-button { |
| 454 | + font-family: 'Pixelify Sans', 'Comic Sans MS', 'Arial', sans-serif; |
| 455 | + margin-top: 1rem; |
| 456 | + padding: 0.5rem 1rem; |
| 457 | + background-color: #465e4b; |
| 458 | + color: #fff; |
| 459 | + border: 0.3rem solid #1b291e; |
| 460 | + border-radius: 8px; |
| 461 | + font-size: 1.5rem; |
| 462 | + cursor: pointer; |
| 463 | + font-weight: 500; |
| 464 | + } |
| 465 | +
|
| 466 | + .close-button { |
| 467 | + font-family: 'Pixelify Sans', 'Comic Sans MS', 'Arial', sans-serif; |
| 468 | + margin-top: 1rem; |
| 469 | + padding: 0.5rem 1rem; |
| 470 | + background-color: #845454; |
| 471 | + color: #fff; |
| 472 | + border: 0.3rem solid #463131; |
| 473 | + border-radius: 8px; |
| 474 | + font-size: 1.5rem; |
| 475 | + cursor: pointer; |
| 476 | + font-weight: 500; |
| 477 | + } |
345 | 478 | </style> |
0 commit comments