cleanup world_tree
This commit is contained in:
@@ -2,22 +2,23 @@
|
|||||||
* @fileOverview Define the menu displayed with the tree of worlds on the welcome page
|
* @fileOverview Define the menu displayed with the tree of worlds on the welcome page
|
||||||
*/
|
*/
|
||||||
import * as React from 'react'
|
import * as React from 'react'
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom'
|
||||||
import { useStore, useSelector } from 'react-redux';
|
import { useStore, useSelector } from 'react-redux'
|
||||||
|
import { Slider } from '@mui/material'
|
||||||
|
import cytoscape, { LayoutOptions } from 'cytoscape'
|
||||||
|
import klay from 'cytoscape-klay'
|
||||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||||
import { faDownload, faUpload, faEraser, faGlobe, faArrowLeft } from '@fortawesome/free-solid-svg-icons'
|
import { faDownload, faUpload, faEraser, faGlobe, faArrowLeft } from '@fortawesome/free-solid-svg-icons'
|
||||||
import { store } from '../state/store';
|
|
||||||
|
import { GameIdContext } from '../app'
|
||||||
|
import { useAppDispatch } from '../hooks'
|
||||||
|
import { deleteProgress, selectProgress, loadProgress, GameProgressState,
|
||||||
|
selectDifficulty, changedDifficulty, selectCompleted } from '../state/progress'
|
||||||
|
import { store } from '../state/store'
|
||||||
|
import { Button } from './button'
|
||||||
|
|
||||||
import './world_tree.css'
|
import './world_tree.css'
|
||||||
|
|
||||||
import { Button } from './button'
|
|
||||||
import { GameIdContext } from '../app';
|
|
||||||
import { useAppDispatch } from '../hooks';
|
|
||||||
import { deleteProgress, selectProgress, loadProgress, GameProgressState, selectDifficulty, changedDifficulty, selectCompleted } from '../state/progress';
|
|
||||||
import { Slider } from '@mui/material';
|
|
||||||
import cytoscape, { LayoutOptions } from 'cytoscape'
|
|
||||||
import klay from 'cytoscape-klay';
|
|
||||||
|
|
||||||
// Settings for the world tree
|
// Settings for the world tree
|
||||||
cytoscape.use( klay )
|
cytoscape.use( klay )
|
||||||
const N = 18 // max number of levels per world
|
const N = 18 // max number of levels per world
|
||||||
@@ -127,7 +128,8 @@ const downloadFile = ({ data, fileName, fileType } :
|
|||||||
a.remove()
|
a.remove()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The menu that is shown next to the world selection graph */
|
// TODO: I think this should be removed and that single button incorporated differently
|
||||||
|
/** Menu on desktop to go back to game server */
|
||||||
export function WelcomeMenu() {
|
export function WelcomeMenu() {
|
||||||
|
|
||||||
return <nav className="world-selection-menu">
|
return <nav className="world-selection-menu">
|
||||||
@@ -265,7 +267,6 @@ function WorldSelectionMenu() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function computeWorldLayout(worlds) {
|
export function computeWorldLayout(worlds) {
|
||||||
|
|
||||||
let elements = []
|
let elements = []
|
||||||
for (let id in worlds.nodes) {
|
for (let id in worlds.nodes) {
|
||||||
elements.push({ data: { id: id, title: worlds.nodes[id].title } })
|
elements.push({ data: { id: id, title: worlds.nodes[id].title } })
|
||||||
@@ -279,14 +280,12 @@ export function computeWorldLayout(worlds) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const cy = cytoscape({
|
const cy = cytoscape({
|
||||||
container: null,
|
container: null,
|
||||||
elements,
|
elements,
|
||||||
headless: true,
|
headless: true,
|
||||||
styleEnabled: false
|
styleEnabled: false
|
||||||
})
|
})
|
||||||
|
|
||||||
const layout = cy.layout({name: "klay", klay: {direction: "DOWN", nodePlacement: "LINEAR_SEGMENTS"}} as LayoutOptions).run()
|
const layout = cy.layout({name: "klay", klay: {direction: "DOWN", nodePlacement: "LINEAR_SEGMENTS"}} as LayoutOptions).run()
|
||||||
let nodes = {}
|
let nodes = {}
|
||||||
cy.nodes().forEach((node, id) => {
|
cy.nodes().forEach((node, id) => {
|
||||||
@@ -305,7 +304,6 @@ export function WorldTreePanel({worlds, worldSize}:
|
|||||||
worldSize: any}) {
|
worldSize: any}) {
|
||||||
const gameId = React.useContext(GameIdContext)
|
const gameId = React.useContext(GameIdContext)
|
||||||
const difficulty = useSelector(selectDifficulty(gameId))
|
const difficulty = useSelector(selectDifficulty(gameId))
|
||||||
|
|
||||||
const {nodes, bounds}: any = worlds ? computeWorldLayout(worlds) : {nodes: []}
|
const {nodes, bounds}: any = worlds ? computeWorldLayout(worlds) : {nodes: []}
|
||||||
|
|
||||||
// scroll to playable world
|
// scroll to playable world
|
||||||
@@ -321,7 +319,6 @@ export function WorldTreePanel({worlds, worldSize}:
|
|||||||
}
|
}
|
||||||
}, [worlds, worldSize])
|
}, [worlds, worldSize])
|
||||||
|
|
||||||
|
|
||||||
let svgElements = []
|
let svgElements = []
|
||||||
|
|
||||||
// for each `worldId` as index, this contains a list of booleans with indices
|
// for each `worldId` as index, this contains a list of booleans with indices
|
||||||
@@ -385,4 +382,4 @@ export function WorldTreePanel({worlds, worldSize}:
|
|||||||
{svgElements}
|
{svgElements}
|
||||||
</svg>
|
</svg>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user