From 7be5921ef633485615278040673a5269a6e42120 Mon Sep 17 00:00:00 2001 From: Jonas Kappa Date: Fri, 2 Jan 2026 02:59:40 +0100 Subject: [PATCH] Added Editor Game and Wall Display --- src/lib/DisplayState.svelte.ts | 10 +- src/lib/Textfield.svelte | 18 ++ src/lib/Types.ts | 52 ++++- src/lib/Wall.svelte | 103 ++++++++-- src/lib/games/games.ts | 8 +- .../connected/games/[game]/+page.svelte | 8 +- src/routes/editor/+page.svelte | 4 +- src/routes/editor/[gameid]/+page.svelte | 192 ++++++++++++++++++ .../[gameid]/EditorSimpleQuestion.svelte | 15 ++ 9 files changed, 372 insertions(+), 38 deletions(-) create mode 100644 src/lib/Textfield.svelte create mode 100644 src/routes/editor/[gameid]/+page.svelte create mode 100644 src/routes/editor/[gameid]/EditorSimpleQuestion.svelte diff --git a/src/lib/DisplayState.svelte.ts b/src/lib/DisplayState.svelte.ts index 452230e..7228c8c 100644 --- a/src/lib/DisplayState.svelte.ts +++ b/src/lib/DisplayState.svelte.ts @@ -1,4 +1,4 @@ -import type { Game, Wall } from "./games/games"; +import type { FullGame, FullWall } from "./games/games"; interface Player { name: string; @@ -9,9 +9,9 @@ const baseRoute = "/connected/display/running"; let players: Player[] = $state([]); let currentPlayer: string = $state(""); // eslint-disable-next-line prefer-const -let game: Game | undefined = undefined; +let game: FullGame | undefined = undefined; let gameIndex: number = -1; -let wall: Wall | undefined = undefined; +let wall: FullWall | undefined = undefined; let wallIndex: number = -1; export default { @@ -29,7 +29,7 @@ export default { currentPlayer = str; }, baseRoute, - get game(): Game | undefined { + get game(): FullGame | undefined { return game; }, // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -42,7 +42,7 @@ export default { set gameIndex(i: number) { gameIndex = i; }, - get wall(): Wall | undefined { + get wall(): FullWall | undefined { return wall; }, // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/src/lib/Textfield.svelte b/src/lib/Textfield.svelte new file mode 100644 index 0000000..f45296e --- /dev/null +++ b/src/lib/Textfield.svelte @@ -0,0 +1,18 @@ + + + + + diff --git a/src/lib/Types.ts b/src/lib/Types.ts index f110eb4..a295528 100644 --- a/src/lib/Types.ts +++ b/src/lib/Types.ts @@ -1,3 +1,13 @@ +import type { + AudioMultipleChoiceQuestion, + AudioQuestion, + FullWall, + ImageMultipleChoiceQuestion, + ImageQuestion, + MultipleChoiceQuestion, + SimpleQuestion +} from "./games/games"; + export type VisitedQuestions = number[][]; export type Directory = { @@ -23,13 +33,49 @@ export function isRessource(ressource: Ressource | Directory): ressource is Ress return (ressource as Directory).isDir === undefined; } -export type GameId = string; +export type _id = string; + +export type GameId = _id; export type Game = { name: string; - owner: string; + owner: _id; _id: GameId; walls: WallId[]; }; -export type WallId = string; +export type WallId = _id; + +export type Wall = { + _id: WallId; + name: string; + owner: _id; + categories: CategoryId[]; +}; + +export function isWall(wall: Wall | FullWall): wall is Wall { + return (wall as Wall)._id !== undefined; +} + +export function isFullWall(wall: Wall | FullWall): wall is FullWall { + return !Object.hasOwn(wall, "_id"); +} + +export type CategoryId = _id; + +export type Category = { + _id: CategoryId; + name: string; + owner: _id; + questions: { _id: QuestionId; points: number }[]; +}; + +export type QuestionId = _id; + +export type GeneralQuestion = + | SimpleQuestion + | MultipleChoiceQuestion + | ImageQuestion + | ImageMultipleChoiceQuestion + | AudioQuestion + | AudioMultipleChoiceQuestion; diff --git a/src/lib/Wall.svelte b/src/lib/Wall.svelte index 63a1f2d..38ca88e 100644 --- a/src/lib/Wall.svelte +++ b/src/lib/Wall.svelte @@ -1,10 +1,21 @@ {#if wall != undefined}
- {#each wall.categories as category, catIndex} -
-
{category.name}
-
- {#each category.questions as question, queIndex} - -
{ - if (onclick) onclick(catIndex, queIndex); - }} - > -
{question.points}
+ {#if isWall(wall)} + {#each categories as category, catIndex} +
+
{category.name}
+ {#each category.questions as question, queIndex} + +
{ + if (onclickIds) onclickIds(category._id, question._id); + }} + > +
+ {question.points >= 0 ? question.points : "???"} +
+
+ {/each} {/each} - {/each} + {:else} + {#each wall.categories as category, catIndex} +
+
{category.name}
+
+ {#each category.questions as question, queIndex} + +
{ + if (onclick) onclick(catIndex, queIndex); + }} + > +
+ {question.points >= 0 ? question.points : "???"} +
+
+ {/each} + {/each} + {/if}
{:else}

Wall is undefined

diff --git a/src/lib/games/games.ts b/src/lib/games/games.ts index 5b6359a..cc03410 100644 --- a/src/lib/games/games.ts +++ b/src/lib/games/games.ts @@ -1425,16 +1425,16 @@ export type Category = { )[]; }; -export type Wall = { +export type FullWall = { name: string; categories: Category[]; }; -export type Game = { +export type FullGame = { name: string; - walls: Wall[]; + walls: FullWall[]; }; -export type Games = Game[]; +export type Games = FullGame[]; export default games; diff --git a/src/routes/connected/games/[game]/+page.svelte b/src/routes/connected/games/[game]/+page.svelte index a87159e..2b9bd9a 100644 --- a/src/routes/connected/games/[game]/+page.svelte +++ b/src/routes/connected/games/[game]/+page.svelte @@ -6,10 +6,10 @@ isMultipleChoiceQuestion, isSimpleQuestion, isImageQuestion, - type Game, isAudioQuestion, isAudioMultipleChoiceQuestion, - isImageMultipleChoiceQuestion + isImageMultipleChoiceQuestion, + type FullGame } from "$lib/games/games"; import ws from "$lib/websocket.svelte"; import { page } from "$app/state"; @@ -57,7 +57,7 @@ class GameManager { public state: GameState = $state(GameState.INIT); - public game: Game; + public game: FullGame; public players: Player[] = $state([ { name: "Player 1", @@ -83,7 +83,7 @@ public questionIsShowing = $state(false); public isBuzzed = $state(false); - constructor(game: Game) { + constructor(game: FullGame) { this.game = game; } diff --git a/src/routes/editor/+page.svelte b/src/routes/editor/+page.svelte index 5d463de..d4a683e 100644 --- a/src/routes/editor/+page.svelte +++ b/src/routes/editor/+page.svelte @@ -79,11 +79,13 @@
-
+

Editor

+
+
{#if games.length > 0}
diff --git a/src/routes/editor/[gameid]/+page.svelte b/src/routes/editor/[gameid]/+page.svelte new file mode 100644 index 0000000..e7f5f4c --- /dev/null +++ b/src/routes/editor/[gameid]/+page.svelte @@ -0,0 +1,192 @@ + + +
+
+

{game ? game.name : "Spiel"}

+
+ +
+
+ +
+
+ +
+ {#each walls as wall} + + +
{ + selectedWall = wall; + }} + > +
+ {wall.name} +
+ + +
+ {/each} +
+ + {#if selectedWall} +
+ { + console.log(catId, queId); + if (selectedWall) + goto( + `/editor/${page.params.gameid}/${selectedWall._id}/${catId}/${queId}` + ); + }} + > +
+ {/if} +
+
+ + + {#snippet header()} +

Neue Wand

+ {/snippet} +
+ +
+ +
+ {#if error.length > 0} +
{error}
+ {/if} +
+
+ + + {#snippet header()} +

Wand löschen

+ {/snippet} + +
Soll die Wand {wallToDelete?.name} wirklich gelöscht werden?
+ {#if error.length > 0} +
{error}
+ {/if} +
diff --git a/src/routes/editor/[gameid]/EditorSimpleQuestion.svelte b/src/routes/editor/[gameid]/EditorSimpleQuestion.svelte new file mode 100644 index 0000000..addffff --- /dev/null +++ b/src/routes/editor/[gameid]/EditorSimpleQuestion.svelte @@ -0,0 +1,15 @@ + + +
+ + +