import { isMobile } from '../lib/simpleUtils' import useLongPress from './reactUtils' import { renderToDom } from '@zardoy/react-util' import { useEffect, useState } from 'react' import { proxy, useSnapshot } from 'valtio' import { Vec3 } from 'vec3' import { MobileControls } from './mobileControls' export const playgroundGlobalUiState = proxy({ scenes: [] as string[], selected: '', selectorOpened: false, actions: {} as Record void>, }) renderToDom(, { strictMode: false, selector: '#react-root', }) function Playground () { useEffect(() => { const style = document.createElement('style') style.innerHTML = /* css */ ` .lil-gui { top: 60px !important; right: 0 !important; } ` document.body.appendChild(style) // Hide the loading overlay once the playground UI is ready const loadingOverlay = document.getElementById('loading') if (loadingOverlay) { loadingOverlay.classList.add('hidden') } return () => { style.remove() } }, []) return
} function SceneSelector () { const mobile = isMobile() const { scenes, selected } = useSnapshot(playgroundGlobalUiState) const [hidden, setHidden] = useState(false) const longPressEvents = useLongPress(() => { playgroundGlobalUiState.selectorOpened = true }, () => { }) if (hidden) return null return
{scenes.map(scene =>
{ const qs = new URLSearchParams(window.location.search) qs.set('scene', scene) location.search = qs.toString() }} >{scene}
)}
setHidden(true)} >×
} const ActionsSelector = () => { const { actions, selectorOpened } = useSnapshot(playgroundGlobalUiState) if (!selectorOpened) return null return
{Object.entries({ ...actions, 'Close' () { playgroundGlobalUiState.selectorOpened = false } }).map(([name, action]) =>
{ action() playgroundGlobalUiState.selectorOpened = false }} >{name}
)}
} const Controls = () => { return }