From ad6f907d17c982c07b6be4fbd1f3984745eeb120 Mon Sep 17 00:00:00 2001 From: Alexander Bentkamp Date: Tue, 20 Dec 2022 12:06:35 +0100 Subject: [PATCH] load number of levels from server --- client/src/components/Level.tsx | 6 +++-- client/src/components/Welcome.tsx | 36 +++++++++++++++++++++----- client/src/state/api.ts | 1 + server/leanserver/GameServer/Game.lean | 9 ++++--- server/testgame/TestGame.lean | 3 +-- 5 files changed, 41 insertions(+), 14 deletions(-) diff --git a/client/src/components/Level.tsx b/client/src/components/Level.tsx index 9ce5701..6069b1a 100644 --- a/client/src/components/Level.tsx +++ b/client/src/components/Level.tsx @@ -20,7 +20,7 @@ import './level.css' import { ConnectionContext } from '../connection'; import Infoview from './Infoview'; import { useParams } from 'react-router-dom'; -import { useLoadLevelQuery } from '../state/api'; +import { useGetGameInfoQuery, useLoadLevelQuery } from '../state/api'; import { codeEdited, selectCode } from '../state/progress'; import { useAppDispatch } from '../hooks'; import { useSelector } from 'react-redux'; @@ -121,6 +121,8 @@ function Level() { const connection = React.useContext(ConnectionContext) + const gameInfo = useGetGameInfoQuery() + const level = useLoadLevelQuery({world: worldId, level: levelId}) const dispatch = useAppDispatch() @@ -171,7 +173,7 @@ function Level() { - +
diff --git a/client/src/components/Welcome.tsx b/client/src/components/Welcome.tsx index 017b9c2..d9a4d4d 100644 --- a/client/src/components/Welcome.tsx +++ b/client/src/components/Welcome.tsx @@ -30,6 +30,34 @@ function Welcome() { const padding = 10 + const svgElements = [] + + if (gameInfo.data) { + for (let edge of gameInfo.data.worlds.edges) { + svgElements.push( + + ) + } + for (let id in nodes) { + let position: cytoscape.Position = nodes[id] + + svgElements.push( + + + {id} + + ) + + for (let i = 1; i <= gameInfo.data.worldSize[id]; i++) { + svgElements.push( + + + + ) + } + } + } + return
{ gameInfo.isLoading? @@ -43,13 +71,7 @@ function Welcome() { - {gameInfo.data ? gameInfo.data.worlds.edges.map((edge) => - ) : null} - {Object.entries(nodes).map(([id, position]) => - - - {id} - )} + {svgElements}
diff --git a/client/src/state/api.ts b/client/src/state/api.ts index 5ee564a..e66921b 100644 --- a/client/src/state/api.ts +++ b/client/src/state/api.ts @@ -5,6 +5,7 @@ interface GameInfo { title: null|string, introduction: null|string, worlds: null|{nodes: string[], edges: string[][]}, + worldSize: null|{[key: string]: number}, authors: null|string[], conclusion: null|string, } diff --git a/server/leanserver/GameServer/Game.lean b/server/leanserver/GameServer/Game.lean index b709fb4..cea1e91 100644 --- a/server/leanserver/GameServer/Game.lean +++ b/server/leanserver/GameServer/Game.lean @@ -24,13 +24,16 @@ open Lsp open JsonRpc open IO -def getGame (game : Name): GameServerM Game := do +def getGame (game : Name): GameServerM Json := do let some game ← getGame? game | throwServerError "Game not found" - return game + let gameJson : Json := toJson game + -- Add world sizes to Json object + let worldSize := game.worlds.nodes.toList.map (fun (n, w) => (n.toString, w.levels.size)) + let gameJson := gameJson.mergeObj (Json.mkObj [("worldSize", Json.mkObj worldSize)]) + return gameJson /-- - Fields: - description: Lemma in mathematical language. - descriptionGoal: Lemma printed as Lean-Code. diff --git a/server/testgame/TestGame.lean b/server/testgame/TestGame.lean index 5dc716b..2904de7 100644 --- a/server/testgame/TestGame.lean +++ b/server/testgame/TestGame.lean @@ -63,8 +63,7 @@ aber eigenständig sein) ### Spieler-Führung -- Keine Möglichkeit zurück zu gehen und nach dem letzten Level kann man trotzdem -\"Next Level\" klicken +- Keine Möglichkeit zurück zu gehen - Fehlermeldungen sind nicht besonders Benutzerfreundlich: Ganz unverständliche sammeln, damit wir diese später modifizieren können. - Kann man Taktiken blockieren?