import * as React from 'react'; import { useState, useEffect, useRef } from 'react'; import '@fontsource/roboto/300.css'; import '@fontsource/roboto/400.css'; import '@fontsource/roboto/500.css'; import '@fontsource/roboto/700.css'; import cytoscape, { LayoutOptions } from 'cytoscape' import klay from 'cytoscape-klay'; import { Link as RouterLink, useNavigate } from 'react-router-dom'; cytoscape.use( klay ); import { Box, Typography, Button, CircularProgress, Grid } from '@mui/material'; import { useGetGameInfoQuery } from '../state/api'; import { Link } from 'react-router-dom'; import Markdown from './Markdown'; function Welcome() { const navigate = useNavigate(); const gameInfo = useGetGameInfoQuery() const { nodes, bounds }: any = gameInfo.data ? computeWorldLayout(gameInfo.data?.worlds) : {nodes: []} useEffect(() => { if (gameInfo.data?.title) window.document.title = gameInfo.data.title }, [gameInfo.data?.title]) const padding = 10 return
{ gameInfo.isLoading? :
{gameInfo.data.introduction} {gameInfo.data ? gameInfo.data.worlds.edges.map((edge) => ) : null} {Object.entries(nodes).map(([id, position]) => {id} )}
}
} export default Welcome function computeWorldLayout(worlds) { let elements = [] for (let node of worlds.nodes) { elements.push({ data: { id: node } }) } for (let edge of worlds.edges) { elements.push({ data: { id: edge[0] + " --edge-to--> " + edge[1], source: edge[0], target: edge[1] } }) } const cy = cytoscape({ container: null, elements, headless: true, styleEnabled: false }) const layout = cy.layout({name: "klay", klay: {direction: "DOWN"}} as LayoutOptions).run() let nodes = {} cy.nodes().forEach((node, id) => { nodes[node.id()] = node.position() console.log(node.position()) }) const bounds = cy.nodes().boundingBox() console.log(bounds) return { nodes, bounds } }