diff --git a/packages/app/src/components/app/play/index.jsx b/packages/app/src/components/app/play/index.jsx index dccec3f..4e8618d 100644 --- a/packages/app/src/components/app/play/index.jsx +++ b/packages/app/src/components/app/play/index.jsx @@ -66,6 +66,12 @@ function Play() { clearInterval(inputHandle); }; }, [selfEntity, socket]); + // Initial camera position snap. + useEffect(() => { + if (selfEntity) { + selfEntity.camera.realPosition = selfEntity.camera.position; + } + }, [selfEntity]); return ( <> diff --git a/packages/app/src/components/app/play/ui/index.jsx b/packages/app/src/components/app/play/ui/index.jsx index 23259ab..24412ec 100644 --- a/packages/app/src/components/app/play/ui/index.jsx +++ b/packages/app/src/components/app/play/ui/index.jsx @@ -1,11 +1,9 @@ import {Vector} from '@avocado/math'; +import {usePropertyChange} from '@avocado/react'; import {RoomUi} from '@avocado/topdown'; import { React, - useEffect, useFlecks, - useRef, - useState, } from '@flecks/react'; import { @@ -14,48 +12,22 @@ import { } from '../../../../hooks'; import Hotbar from './hotbar'; +const focus = (element) => { + element.focus(); +}; + const PlayUi = () => { - const flecks = useFlecks(); - const ref = useRef(); + const {config: {'@humus/app': {resolution}}} = useFlecks(); const room = useRoom(); const selfEntity = useSelfEntity(); - const [position, setPosition] = useState([0, 0]); - const [domScale, setDomScale] = useState([1, 1]); - // Handle camera changes. - useEffect(() => { - if (!room || !selfEntity) { - return undefined; - } - // Initial snap camera to position. - selfEntity.camera.realPosition = selfEntity.camera.position; - const onCameraRealOffsetChanged = () => { - setPosition(Vector.scale(selfEntity.camera.realOffset, -1)); - }; - const onCameraViewSizeChanged = () => { - setDomScale(Vector.div(flecks.get('@humus/app.resolution'), selfEntity.camera.viewSize)); - }; - onCameraRealOffsetChanged(); - onCameraViewSizeChanged(); - selfEntity.camera.on('realOffsetChanged', onCameraRealOffsetChanged); - selfEntity.camera.on('viewSizeChanged', onCameraViewSizeChanged); - return () => { - const {camera} = selfEntity; - if (camera) { - camera.off('realOffsetChanged', onCameraViewSizeChanged); - camera.off('viewSizeChanged', onCameraViewSizeChanged); - } - }; - }, [flecks, room, selfEntity]); - // Focus. - useEffect(() => { - if (ref.current) { - ref.current.focus(); - } - }); return ( // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex -
- +
+ {selfEntity && }
);