Skip to content

Commit

Permalink
fixed build error for cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
Valery-a committed Oct 6, 2024
1 parent 7ff8e64 commit 5594175
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
8 changes: 6 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 9 additions & 8 deletions src/vr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<React.SetStateAction<boolean>>) {
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)
Expand All @@ -21,19 +22,18 @@ export async function initVR (viewer: any, setVrEnabled: React.Dispatch<React.Se

renderer.xr.addEventListener('sessionstart', () => {
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<React.SetStateAction<boolean>>): HTMLButtonElement {
function createCloseButton (vrButton: HTMLButtonElement, toggleVrEnabled: (enabled: boolean) => void): HTMLButtonElement {
const closeButton = document.createElement('button')
closeButton.textContent = 'X'
closeButton.style.position = 'absolute'
Expand All @@ -50,8 +50,9 @@ function createCloseButton (vrButton: HTMLButtonElement, setVrEnabled: React.Dis
closeButton.addEventListener('click', () => {
vrButton.remove()
closeButton.remove()
setVrEnabled(false)
toggleVrEnabled(false)
})

return closeButton
}

Expand Down

0 comments on commit 5594175

Please sign in to comment.