Added Image Questions

This commit is contained in:
2025-09-11 19:06:01 +02:00
parent fd4b2fd341
commit b98e25d4e7
7 changed files with 127 additions and 7 deletions

View File

@@ -3,11 +3,12 @@
import { page } from "$app/state";
import { error } from "@sveltejs/kit";
import SimpleQuestionComponent from "$lib/SimpleQuestionComponent.svelte";
import { isMultipleChoiceQuestion, isSimpleQuestion } from "$lib/games/games";
import { isImageQuestion, isMultipleChoiceQuestion, isSimpleQuestion } from "$lib/games/games";
import ws from "$lib/websocket.svelte";
import { MessageType } from "$lib/MessageType";
import { untrack } from "svelte";
import MultipleChoiceQuestionComponent from "$lib/MultipleChoiceQuestionComponent.svelte";
import ImageQuestionComponent from "$lib/ImageQuestionComponent.svelte";
console.log("wall:", page.params.wall);
@@ -60,6 +61,7 @@
let showAnswer = $state(false);
let showQuestion = $state(false);
let isBuzzed = $state(false);
$effect(() => {
if (ws.messageNum <= 0) return;
@@ -92,6 +94,18 @@
showAnswer = false;
});
}
if (json.type == MessageType.BUZZER_PRESSED) {
ws.nextMessage();
untrack(() => {
isBuzzed = true;
});
}
if (json.type == MessageType.BUZZER_RELEASED) {
ws.nextMessage();
untrack(() => {
isBuzzed = false;
});
}
} catch (e) {}
});
</script>
@@ -110,6 +124,8 @@
<SimpleQuestionComponent {question} {showAnswer} {showQuestion} />
{:else if isMultipleChoiceQuestion(question)}
<MultipleChoiceQuestionComponent {question} {showAnswer} {showQuestion} />
{:else if isImageQuestion(question)}
<ImageQuestionComponent {question} {showAnswer} {showQuestion} {isBuzzed} />
{:else}
<p>Type of question unknown</p>
{/if}

View File

@@ -5,8 +5,8 @@
import {
isMultipleChoiceQuestion,
isSimpleQuestion,
type Game,
type Question
isImageQuestion,
type Game
} from "$lib/games/games";
import ws from "$lib/websocket.svelte";
import { page } from "$app/state";
@@ -17,6 +17,7 @@
import PlusMinusButton from "$lib/PlusMinusButton.svelte";
import type { VisitedQuestions } from "$lib/Types.js";
import MultipleChoiceQuestionComponent from "$lib/MultipleChoiceQuestionComponent.svelte";
import ImageQuestionComponent from "$lib/ImageQuestionComponent.svelte";
let startDisabled = $state(true);
@@ -67,6 +68,7 @@
public answerIsShowing = $state(false);
public questionIsShowing = $state(false);
public isBuzzed = $state(false);
constructor(game: Game) {
this.game = game;
@@ -166,6 +168,20 @@
});
}
buzzerPressed() {
this.isBuzzed = true;
ws.sendMessage({
type: MessageType.BUZZER_PRESSED
});
}
buzzerReleased() {
this.isBuzzed = false;
ws.sendMessage({
type: MessageType.BUZZER_RELEASED
});
}
showQuestion() {
this.questionIsShowing = true;
ws.sendMessage({
@@ -209,6 +225,7 @@
setupGoingBack(): void {
this.answerIsShowing = false;
this.questionIsShowing = false;
this.isBuzzed = false;
}
finishQuestion(): void {
@@ -342,6 +359,13 @@
showAnswer={true}
showQuestion={true}
/>
{:else if isImageQuestion(gameManager.question)}
<ImageQuestionComponent
question={gameManager.question}
showAnswer={true}
showQuestion={true}
isBuzzed={false}
/>
{:else}
<p>Type of question unknown</p>
{/if}
@@ -366,6 +390,15 @@
>Antwort aufdecken</button
>
{/if}
{#if gameManager.isBuzzed}
<button class="btn" onclick={() => gameManager.buzzerReleased()}
>Entbuzzern</button
>
{:else}
<button class="btn" onclick={() => gameManager.buzzerPressed()}
>Buzzern</button
>
{/if}
{#each gameManager.players as player}
<PlusMinusButton
label={player.name}