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}
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 @@