import { useEffect, useState } from 'react' import { proxy, useSnapshot } from 'valtio' import { filesize } from 'filesize' import Input from './Input' import Screen from './Screen' import Button from './Button' import styles from './createWorld.module.css' // const worldTypes = ['default', 'flat', 'largeBiomes', 'amplified', 'customized', 'buffet', 'debug_all_block_states'] const worldTypes = ['default', 'flat'/* , 'void' */] const gameModes = ['survival', 'creative'/* , 'adventure', 'spectator' */] export const creatingWorldState = proxy({ title: '', type: worldTypes[0], gameMode: gameModes[0], version: '' }) export default ({ cancelClick, createClick, customizeClick, versions, defaultVersion }) => { const [quota, setQuota] = useState('') const { title, type, version, gameMode } = useSnapshot(creatingWorldState) useEffect(() => { creatingWorldState.version = defaultVersion void navigator.storage?.estimate?.().then(({ quota, usage }) => { setQuota(`Storage usage: ${usage === undefined ? '?' : filesize(usage)} / ${quota ? filesize(quota) : '?'}`) }) }, []) return { e.preventDefault() createClick() }}> { creatingWorldState.title = value }} placeholder='World name' /> { creatingWorldState.version = value }}> {versions.map(({ version, label }) => { return {label} })} { const index = worldTypes.indexOf(type) creatingWorldState.type = worldTypes[index === worldTypes.length - 1 ? 0 : index + 1] }}>World Type: {type} {/* customizeClick()} disabled> Customize */} { const index = gameModes.indexOf(gameMode) creatingWorldState.gameMode = gameModes[index === gameModes.length - 1 ? 0 : index + 1] }}> Gamemode: {gameMode} Default and other world types are WIP { cancelClick() }}>Cancel Create Note: store important saves in folders on the drive! {quota} } export const WorldCustomize = ({ backClick }) => { const { type } = useSnapshot(creatingWorldState) return Back }