From 1b5b5e31acc3fc1b15ca810400827564249098f2 Mon Sep 17 00:00:00 2001 From: Mawoka Date: Mon, 18 Sep 2023 20:45:07 +0200 Subject: [PATCH] :recycle: Cleaned admin-game code up --- frontend/src/lib/admin.svelte | 196 ++---------------- .../popover/commandpalettenotice.svelte | 9 +- .../lib/components/popover/smalltop.svelte | 50 ++--- frontend/src/lib/play/admin/controls.svelte | 104 ++++++++++ frontend/src/lib/play/admin/question.svelte | 109 ++++++++++ frontend/src/routes/dashboard/+page.svelte | 2 +- frontend/src/routes/play/+page.svelte | 41 ++-- frontend/tsconfig.json | 3 +- simulate_players.py | 2 +- 9 files changed, 288 insertions(+), 228 deletions(-) create mode 100644 frontend/src/lib/play/admin/controls.svelte create mode 100644 frontend/src/lib/play/admin/question.svelte diff --git a/frontend/src/lib/admin.svelte b/frontend/src/lib/admin.svelte index 74cc96c2..8f1f97a8 100644 --- a/frontend/src/lib/admin.svelte +++ b/frontend/src/lib/admin.svelte @@ -11,16 +11,14 @@ SPDX-License-Identifier: MPL-2.0 import type { PlayerAnswer } from '$lib/admin.ts'; import { socket } from './socket'; import { QuizQuestionType } from '$lib/quiz_types'; - import { kahoot_icons } from './play/kahoot_mode_assets/kahoot_icons'; - import CircularTimer from '$lib/play/circular_progress.svelte'; import Spinner from '$lib/Spinner.svelte'; - import { get_foreground_color } from '$lib/helpers'; - import MediaComponent from '$lib/editor/MediaComponent.svelte'; + import Controls from '$lib/play/admin/controls.svelte'; + import Question from '$lib/play/admin/question.svelte'; export let game_token: string; export let quiz_data: QuizData; - export let game_mode; - export let bg_color; + export let game_mode: string; + export let bg_color: string; const { t } = getLocalization(); const default_colors = ['#D6EDC9', '#B07156', '#7F7057', '#4E6E58']; @@ -37,10 +35,6 @@ SPDX-License-Identifier: MPL-2.0 export let player_scores; - const set_question_number = (q_number: number) => { - socket.emit('set_question_number', q_number.toString()); - }; - socket.on('get_question_results', () => { console.log('get_question_results'); }); @@ -54,20 +48,6 @@ SPDX-License-Identifier: MPL-2.0 answer_count = 0; timer(timer_res); }); - const get_question_results = () => { - socket.emit('get_question_results', { - game_id: game_token, - question_number: shown_question_now - }); - }; - const show_solutions = () => { - socket.emit('show_solutions', {}); - timer_res = '0'; - }; - - const get_final_results = () => { - socket.emit('get_final_results', {}); - }; socket.on('solutions', (_) => { timer_res = '0'; @@ -109,97 +89,33 @@ SPDX-License-Identifier: MPL-2.0 timer_res = seconds.toString(); }, 1000); }; - let circular_progress = 0; - $: { - try { - circular_progress = - 1 - - ((100 / quiz_data.questions[selected_question].time) * parseInt(timer_res)) / 100; - } catch { - circular_progress = 0; - } - } {#if control_visible} -
-

- {selected_question === -1 ? '0' : selected_question + 1} - /{quiz_data.questions.length} -

-
- {#if selected_question + 1 === quiz_data.questions.length && ((timer_res === '0' && question_results !== null) || quiz_data?.questions?.[selected_question]?.type === QuizQuestionType.SLIDE)} - {#if JSON.stringify(final_results) === JSON.stringify([null])} - - {/if} - {:else if timer_res === '0' || selected_question === -1} - {#if (selected_question + 1 !== quiz_data.questions.length && question_results !== null) || selected_question === -1} - - {/if} - {#if question_results === null && selected_question !== -1} - {#if quiz_data.questions[selected_question].type === QuizQuestionType.SLIDE} - - {:else} - - {/if} - {/if} - {:else if selected_question !== -1} - {#if quiz_data.questions[selected_question].type === QuizQuestionType.SLIDE} - - {:else} - - {/if} - {:else} - - {/if} -
-
+ {/if} {#if timer_res !== '0' && selected_question >= 0} {/if}
{#if timer_res !== undefined && !final_results_clicked && !question_results} + {#if quiz_data.questions[selected_question].type === QuizQuestionType.SLIDE} {#await import('$lib/play/admin/slide.svelte')} @@ -210,81 +126,7 @@ SPDX-License-Identifier: MPL-2.0 /> {/await} {:else} -
-

- {@html quiz_data.questions[selected_question].question} -

- -
- -
- -
-

- {$t('admin_page.answers_submitted', { answer_count: answer_count })} -

-
-
- {#if quiz_data.questions[selected_question].image !== null} -
- -
- {/if} - {#if quiz_data.questions[selected_question].type === QuizQuestionType.ABCD || quiz_data.questions[selected_question].type === QuizQuestionType.VOTING || quiz_data.questions[selected_question].type === QuizQuestionType.CHECK} -
- {#each quiz_data.questions[selected_question].answers as answer, i} -
- icon - {answer.answer} - -
- {/each} -
- {:else if quiz_data.questions[selected_question].type === QuizQuestionType.TEXT} - {#if timer_res === '0'} -
- {#each quiz_data.questions[selected_question].answers as answer, i} -
- {answer.answer} - -
- {/each} -
- {:else} -
-

{$t('admin_page.enter_answer_into_field')}

-
- {/if} - {/if} + {/if} {/if}
diff --git a/frontend/src/lib/components/popover/commandpalettenotice.svelte b/frontend/src/lib/components/popover/commandpalettenotice.svelte index 562e04e4..4f419d10 100644 --- a/frontend/src/lib/components/popover/commandpalettenotice.svelte +++ b/frontend/src/lib/components/popover/commandpalettenotice.svelte @@ -4,7 +4,7 @@ SPDX-FileCopyrightText: 2023 Marlon W (Mawoka) SPDX-License-Identifier: MPL-2.0 --> - - + diff --git a/frontend/src/lib/components/popover/smalltop.svelte b/frontend/src/lib/components/popover/smalltop.svelte index 0f967375..469c7de8 100644 --- a/frontend/src/lib/components/popover/smalltop.svelte +++ b/frontend/src/lib/components/popover/smalltop.svelte @@ -4,7 +4,7 @@ SPDX-FileCopyrightText: 2023 Marlon W (Mawoka) SPDX-License-Identifier: MPL-2.0 --> - {#if open} -
+