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

@@ -0,0 +1,55 @@
<script lang="ts">
import type { ImageQuestion } from "./games/games";
const path = "/images/";
interface Props {
question: ImageQuestion;
showAnswer: boolean;
showQuestion: boolean;
isBuzzed: boolean;
[key: string]: unknown;
}
let { question, showAnswer, showQuestion, isBuzzed }: Props = $props();
</script>
<div class="mb-4 flex w-full grow flex-col items-center gap-2 text-6xl">
{#if showQuestion || showAnswer}
<div class="flex grow items-center">
<div class="text-center">{question.data.question}</div>
</div>
<div class="container grow-6">
<img
src={path + question.data.image}
alt={path + question.data.image}
class={isBuzzed ? "blurry" : ""}
/>
</div>
{/if}
{#if showAnswer}
<div class="flex grow items-center text-center">
{question.data.answer}
</div>
{/if}
</div>
<style>
.container {
position: relative;
}
.container > img {
position: absolute;
top: 50%;
left: 50%;
max-height: 100%;
max-width: 100%;
display: block;
transform: translate(-50%, -50%);
}
.blurry {
filter: blur(60px);
}
</style>

View File

@@ -6,5 +6,7 @@ export enum MessageType {
HIDE_ANSWER = "HIDE_ANSWER",
SHOW_QUESTION = "SHOW_QUESTION",
HIDE_QUESTION = "HIDE_QUESTION",
BUZZER_PRESSED = "BUZZER_PRESSED",
BUZZER_RELEASED = "BUZZER_RELEASED",
VISITED_QUESTIONS = "VISITED_QUESTIONS"
}

View File

@@ -28,17 +28,19 @@ const games: Games = [
},
{
points: 200,
type: "SIMPLE",
type: "IMAGE",
data: {
question: "Question 2?",
image: "firstImage.jpg",
answer: "Answer 2"
}
},
{
points: 300,
type: "SIMPLE",
type: "IMAGE",
data: {
question: "Question 3?",
image: "test/secondImage.jpg",
answer: "Answer 3"
}
},
@@ -1222,7 +1224,7 @@ const games: Games = [
}
];
export type QuestionType = "SIMPLE" | "MULTIPLE_CHOICE";
export type QuestionType = "SIMPLE" | "MULTIPLE_CHOICE" | "IMAGE";
export type Question = {
points: number;
@@ -1248,16 +1250,28 @@ export type MultipleChoiceQuestion = Question & {
};
};
export type ImageQuestion = Question & {
type: "IMAGE";
data: {
question: string;
image: string;
answer: string;
};
};
export function isSimpleQuestion(question: Question): question is SimpleQuestion {
return (question as SimpleQuestion).type === "SIMPLE";
}
export function isMultipleChoiceQuestion(question: Question): question is MultipleChoiceQuestion {
return (question as MultipleChoiceQuestion).type === "MULTIPLE_CHOICE";
}
export function isImageQuestion(question: Question): question is ImageQuestion {
return (question as ImageQuestion).type === "IMAGE";
}
export type Category = {
name: string;
questions: (SimpleQuestion | MultipleChoiceQuestion)[];
questions: (SimpleQuestion | MultipleChoiceQuestion | ImageQuestion)[];
};
export type Wall = {