import { useEffect, useState } from 'react' import { proxy, useSnapshot } from 'valtio' import { filesize } from 'filesize' import { getAvailableServerPlugins } from '../clientMods' import { showModal } from '../globalState' import Input from './Input' import Screen from './Screen' import Button from './Button' import SelectGameVersion from './SelectGameVersion' import styles from './createWorld.module.css' import { InputOption, showInputsModal, showOptionsModal } from './SelectOption' // const worldTypes = ['default', 'flat', 'largeBiomes', 'amplified', 'customized', 'buffet', 'debug_all_block_states'] const worldTypes = ['default', 'flat', 'empty', 'nether', 'all_the_blocks'] const gameModes = ['survival', 'creative'/* , 'adventure', 'spectator' */] export const creatingWorldState = proxy({ title: '', type: worldTypes[0], gameMode: gameModes[0], version: '', plugins: [] as string[] }) export default ({ cancelClick, createClick, customizeClick, versions, defaultVersion }) => { const [quota, setQuota] = useState('') const { title, type, version, gameMode, plugins } = 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' /> { return { value: obj.version, label: obj.version } })} selected={{ value: defaultVersion, label: defaultVersion }} onChange={(value) => { creatingWorldState.version = value ?? defaultVersion }} containerStyle={{ width: '100px' }} /> { 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] }} > Game Mode: {gameMode} { const availableServerPlugins = await getAvailableServerPlugins() const availableModNames = availableServerPlugins.map(mod => mod.name) const choices: Record = Object.fromEntries(availableServerPlugins.map(mod => [mod.name, { type: 'checkbox' as const, defaultValue: creatingWorldState.plugins.includes(mod.name), label: mod.name }])) choices.installMore = { type: 'button' as const, onButtonClick () { showModal({ reactType: 'mods' }) } } const choice = await showInputsModal('Select server plugins from mods to install:', choices) if (!choice) return creatingWorldState.plugins = availableModNames.filter(modName => choice[modName]) }} >Use Mods ({plugins.length}) { const index = gameModes.indexOf(gameMode) creatingWorldState.gameMode = gameModes[index === gameModes.length - 1 ? 0 : index + 1] }} disabled > Save Type: Java Default and other world types are WIP { cancelClick() }} >Cancel Create Note: save important worlds in folders on your hard drive! {quota} } export const WorldCustomize = ({ backClick }) => { const { type } = useSnapshot(creatingWorldState) return Back }