From 4f4dcba891dd23bbe1100c333f8acb430168aba2 Mon Sep 17 00:00:00 2001 From: Jon Eugster Date: Mon, 24 Jul 2023 16:28:23 +0200 Subject: [PATCH] improve world tree scale --- client/src/components/welcome.css | 8 +++++++ client/src/components/welcome.tsx | 35 ++++++++++++++++++++++--------- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/client/src/components/welcome.css b/client/src/components/welcome.css index 802b03d..59d66eb 100644 --- a/client/src/components/welcome.css +++ b/client/src/components/welcome.css @@ -77,6 +77,7 @@ svg .world-title, svg .level-title { color: white; margin: 0; padding: 0; + text-align: center; } svg .world-title { @@ -97,6 +98,13 @@ svg .disabled { cursor: default; } +.world-selection { + display: block; + margin-left: auto; + margin-right: auto; + margin-top: 2em; +} + /******************/ /* Privacy Button */ /******************/ diff --git a/client/src/components/welcome.tsx b/client/src/components/welcome.tsx index 34265ea..09da58e 100644 --- a/client/src/components/welcome.tsx +++ b/client/src/components/welcome.tsx @@ -22,11 +22,12 @@ import { store } from '../state/store'; cytoscape.use( klay ); -const N = 18 // max number of levels per world -const R = 800 // radius of a world -const r = 160 // radius of a level -const s = 120 // global scale -const padding = 2000 // padding of the graphic (on a different scale) +const N = 18 // max number of levels per world +const R = 64 // radius of a world +const r = 12 // radius of a level +const s = 10 // global scale +const padding = R + 2*r // padding of the graphic (on a different scale) +const ds = .75 // scale the resulting svg image function LevelIcon({ worldId, levelId, position, completed, available }) { const gameId = React.useContext(GameIdContext) @@ -85,6 +86,17 @@ function Welcome() { } }, [gameInfo.data?.title]) + // Scroll to playable world + useEffect(() => { + let elems = Array.from(document.getElementsByClassName("playable-world")) + if (elems.length) { + // It seems that the last element is the one furthest up in the tree + let elem = elems.pop() + console.debug(`scrolling to ${elem.textContent}`) + elem.scrollIntoView({block: "center"}) + } + }, [gameInfo]) + const svgElements = [] // For each `worldId` as index, this contains a list of booleans with indices @@ -155,7 +167,7 @@ function Welcome() { fill={worldCompleted ? "green" : worldUnlocked ? "#1976d2": "#999"}/> -
+

{nodes[worldId].data.title ? nodes[worldId].data.title : worldId}

@@ -166,13 +178,15 @@ function Welcome() { } } + let dx = bounds ? s*(bounds.x2 - bounds.x1) + 2*padding : null + return
{ gameInfo.isLoading? : - +
@@ -181,12 +195,13 @@ function Welcome() {
- + width={bounds ? `${ds * dx}` : ''} + viewBox={bounds ? `${s*bounds.x1 - padding} ${s*bounds.y1 - padding} ${dx} ${s*(bounds.y2 - bounds.y1) + 2 * padding}` : ''} + className="world-selection" + > {svgElements} -
{<>