From 5594175b8a743397f338e3555854b0b13b002225 Mon Sep 17 00:00:00 2001 From: Valery-a Date: Sun, 6 Oct 2024 07:29:42 +0300 Subject: [PATCH] fixed build error for cypress --- src/index.ts | 8 ++++++-- src/vr.ts | 17 +++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/index.ts b/src/index.ts index 9989e73ee..7abbcc61d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -701,8 +701,12 @@ async function connect (connectOptions: ConnectOptions) { bot.on('physicsTick', () => updateCursor()) - const [vrEnabled, setVrEnabled] = useState(false) - void initVR(viewer, setVrEnabled) + //ghost func + const toggleVrEnabled = (isEnabled: boolean) => { + console.log(`VR mode is now ${isEnabled ? 'enabled' : 'disabled'}`) + } + + void initVR(viewer, toggleVrEnabled) renderWrapper.postRender = () => { viewer.setFirstPersonCamera(null, bot.entity.yaw, bot.entity.pitch) diff --git a/src/vr.ts b/src/vr.ts index 2944f96d7..500fae030 100644 --- a/src/vr.ts +++ b/src/vr.ts @@ -5,14 +5,15 @@ import { buttonMap as standardButtonsMap } from 'contro-max/build/gamepad' import * as THREE from 'three' import { activeModalStack, hideModal } from './globalState' -export async function initVR (viewer: any, setVrEnabled: React.Dispatch>) { +export async function initVR (viewer: any, toggleVrEnabled: (enabled: boolean) => void) { const { renderer } = viewer if (!('xr' in navigator)) return - const isSupported = await navigator.xr?.isSessionSupported('immersive-vr') && !!XRSession.prototype.updateRenderState // e.g. android webview doesn't support updateRenderState if (!isSupported) return + + const isSupported = await navigator.xr?.isSessionSupported('immersive-vr') && !!XRSession.prototype.updateRenderState // e.g. android webview doesn't support updateRenderState if (!isSupported) return if (!isSupported) return // VR Button const vrButton = VRButton.createButton(renderer) as HTMLButtonElement - const closeButton = createCloseButton(vrButton, setVrEnabled) + const closeButton = createCloseButton(vrButton, toggleVrEnabled) document.body.appendChild(vrButton) document.body.appendChild(closeButton) @@ -21,19 +22,18 @@ export async function initVR (viewer: any, setVrEnabled: React.Dispatch { viewer.cameraObjectOverride = viewer.user - for (const _modal of activeModalStack) { - hideModal(undefined, {}, { force: true }) - } + toggleVrEnabled(true) }) renderer.xr.addEventListener('sessionend', () => { viewer.cameraObjectOverride = undefined + toggleVrEnabled(false) }) return { vrButton, closeButton } } -function createCloseButton (vrButton: HTMLButtonElement, setVrEnabled: React.Dispatch>): HTMLButtonElement { +function createCloseButton (vrButton: HTMLButtonElement, toggleVrEnabled: (enabled: boolean) => void): HTMLButtonElement { const closeButton = document.createElement('button') closeButton.textContent = 'X' closeButton.style.position = 'absolute' @@ -50,8 +50,9 @@ function createCloseButton (vrButton: HTMLButtonElement, setVrEnabled: React.Dis closeButton.addEventListener('click', () => { vrButton.remove() closeButton.remove() - setVrEnabled(false) + toggleVrEnabled(false) }) + return closeButton }