2024-04-15 12:04:17 -04:00
|
|
|
import { MouseEventHandler, useEffect, useRef } from 'react'
|
2024-04-03 19:38:16 +11:00
|
|
|
import { uuidv4 } from 'lib/utils'
|
2024-04-15 12:04:17 -04:00
|
|
|
import { useStore } from './useStore'
|
2023-02-21 10:28:34 +11:00
|
|
|
import { useHotKeyListener } from './hooks/useHotKeyListener'
|
2023-03-06 20:13:34 +11:00
|
|
|
import { Stream } from './components/Stream'
|
2023-09-14 10:47:55 +10:00
|
|
|
import { EngineCommand } from './lang/std/engineConnection'
|
2023-09-09 01:38:36 -04:00
|
|
|
import { throttle } from './lib/utils'
|
2023-07-13 07:22:08 -04:00
|
|
|
import { AppHeader } from './components/AppHeader'
|
2023-08-06 21:29:26 -04:00
|
|
|
import { useHotkeys } from 'react-hotkeys-hook'
|
2023-08-09 20:49:10 +10:00
|
|
|
import { getNormalisedCoordinates } from './lib/utils'
|
2024-02-12 18:11:47 -05:00
|
|
|
import { useLoaderData, useNavigate } from 'react-router-dom'
|
|
|
|
import { type IndexLoaderData } from 'lib/types'
|
|
|
|
import { paths } from 'lib/paths'
|
2024-03-11 20:26:13 -04:00
|
|
|
import { useSettingsAuthContext } from 'hooks/useSettingsAuthContext'
|
2024-02-11 12:59:00 +11:00
|
|
|
import { onboardingPaths } from 'routes/Onboarding/paths'
|
2023-09-15 04:35:48 -07:00
|
|
|
import { useEngineConnectionSubscriptions } from 'hooks/useEngineConnectionSubscriptions'
|
2024-03-22 16:55:30 +11:00
|
|
|
import { engineCommandManager } from 'lib/singletons'
|
2023-10-11 13:36:54 +11:00
|
|
|
import { useModelingContext } from 'hooks/useModelingContext'
|
2024-02-12 18:11:47 -05:00
|
|
|
import { useAbsoluteFilePath } from 'hooks/useAbsoluteFilePath'
|
|
|
|
import { isTauri } from 'lib/isTauri'
|
2024-03-11 17:50:31 -07:00
|
|
|
import { useLspContext } from 'components/LspProvider'
|
2024-04-02 10:29:34 -04:00
|
|
|
import { useRefreshSettings } from 'hooks/useRefreshSettings'
|
2024-04-15 12:04:17 -04:00
|
|
|
import { ModelingSidebar } from 'components/ModelingSidebar/ModelingSidebar'
|
2024-04-19 10:50:58 -04:00
|
|
|
import { LowerRightControls } from 'components/LowerRightControls'
|
2024-04-18 20:09:40 -07:00
|
|
|
import ModalContainer from 'react-modal-promise'
|
2022-11-22 09:06:08 +11:00
|
|
|
|
2023-06-22 16:43:33 +10:00
|
|
|
export function App() {
|
2024-04-02 10:29:34 -04:00
|
|
|
useRefreshSettings(paths.FILE + 'SETTINGS')
|
2023-11-07 14:29:50 +11:00
|
|
|
const { project, file } = useLoaderData() as IndexLoaderData
|
2024-02-12 18:11:47 -05:00
|
|
|
const navigate = useNavigate()
|
|
|
|
const filePath = useAbsoluteFilePath()
|
2024-03-11 17:50:31 -07:00
|
|
|
const { onProjectOpen } = useLspContext()
|
2024-04-11 13:15:49 -07:00
|
|
|
// We need the ref for the outermost div so we can screenshot the app for
|
|
|
|
// the coredump.
|
|
|
|
const ref = useRef<HTMLDivElement>(null)
|
2024-03-11 17:50:31 -07:00
|
|
|
|
2024-03-12 23:57:43 -07:00
|
|
|
const projectName = project?.name || null
|
|
|
|
const projectPath = project?.path || null
|
2024-03-11 17:50:31 -07:00
|
|
|
useEffect(() => {
|
2024-03-12 23:57:43 -07:00
|
|
|
onProjectOpen({ name: projectName, path: projectPath }, file || null)
|
|
|
|
}, [projectName, projectPath])
|
2023-09-09 01:38:36 -04:00
|
|
|
|
2023-02-21 10:28:34 +11:00
|
|
|
useHotKeyListener()
|
2024-04-15 12:04:17 -04:00
|
|
|
const { buttonDownInStream, didDragInStream, streamDimensions, setHtmlRef } =
|
|
|
|
useStore((s) => ({
|
|
|
|
buttonDownInStream: s.buttonDownInStream,
|
|
|
|
didDragInStream: s.didDragInStream,
|
|
|
|
streamDimensions: s.streamDimensions,
|
|
|
|
setHtmlRef: s.setHtmlRef,
|
|
|
|
}))
|
2023-08-28 20:31:49 -04:00
|
|
|
|
2024-04-11 13:15:49 -07:00
|
|
|
useEffect(() => {
|
|
|
|
setHtmlRef(ref)
|
|
|
|
}, [ref])
|
|
|
|
|
2024-03-11 20:26:13 -04:00
|
|
|
const { settings } = useSettingsAuthContext()
|
2024-04-02 10:29:34 -04:00
|
|
|
const {
|
2024-04-15 12:04:17 -04:00
|
|
|
app: { onboardingStatus },
|
2024-04-02 10:29:34 -04:00
|
|
|
} = settings.context
|
2023-10-11 13:36:54 +11:00
|
|
|
const { state, send } = useModelingContext()
|
2023-08-06 21:29:26 -04:00
|
|
|
|
2023-10-11 13:36:54 +11:00
|
|
|
useHotkeys('esc', () => send('Cancel'))
|
2024-02-15 14:25:26 -05:00
|
|
|
useHotkeys('backspace', (e) => {
|
|
|
|
e.preventDefault()
|
|
|
|
})
|
2024-02-12 18:11:47 -05:00
|
|
|
useHotkeys(
|
|
|
|
isTauri() ? 'mod + ,' : 'shift + mod + ,',
|
|
|
|
() => navigate(filePath + paths.SETTINGS),
|
|
|
|
{
|
|
|
|
splitKey: '|',
|
|
|
|
}
|
|
|
|
)
|
2023-08-06 21:29:26 -04:00
|
|
|
|
2023-09-15 22:37:40 -04:00
|
|
|
const paneOpacity = [onboardingPaths.CAMERA, onboardingPaths.STREAMING].some(
|
2024-04-02 10:29:34 -04:00
|
|
|
(p) => p === onboardingStatus.current
|
2023-09-15 22:37:40 -04:00
|
|
|
)
|
|
|
|
? 'opacity-20'
|
|
|
|
: didDragInStream
|
|
|
|
? 'opacity-40'
|
|
|
|
: ''
|
2023-08-06 21:29:26 -04:00
|
|
|
|
2023-09-15 04:35:48 -07:00
|
|
|
useEngineConnectionSubscriptions()
|
2023-07-31 06:33:10 -04:00
|
|
|
|
2023-08-06 21:29:26 -04:00
|
|
|
const debounceSocketSend = throttle<EngineCommand>((message) => {
|
2024-02-11 12:59:00 +11:00
|
|
|
engineCommandManager.sendSceneCommand(message)
|
|
|
|
}, 1000 / 15)
|
2023-09-08 10:13:35 -04:00
|
|
|
const handleMouseMove: MouseEventHandler<HTMLDivElement> = (e) => {
|
2024-02-11 12:59:00 +11:00
|
|
|
if (state.matches('Sketch')) {
|
|
|
|
return
|
|
|
|
}
|
2023-08-09 20:49:10 +10:00
|
|
|
|
|
|
|
const { x, y } = getNormalisedCoordinates({
|
2023-09-08 10:13:35 -04:00
|
|
|
clientX: e.clientX,
|
|
|
|
clientY: e.clientY,
|
|
|
|
el: e.currentTarget,
|
2023-08-09 20:49:10 +10:00
|
|
|
...streamDimensions,
|
|
|
|
})
|
2023-08-06 21:29:26 -04:00
|
|
|
|
2023-08-09 20:49:10 +10:00
|
|
|
const newCmdId = uuidv4()
|
2023-09-13 08:36:47 +10:00
|
|
|
if (buttonDownInStream === undefined) {
|
2024-02-11 12:59:00 +11:00
|
|
|
debounceSocketSend({
|
|
|
|
type: 'modeling_cmd_req',
|
|
|
|
cmd: {
|
|
|
|
type: 'highlight_set_entity',
|
|
|
|
selected_at_window: { x, y },
|
|
|
|
},
|
|
|
|
cmd_id: newCmdId,
|
|
|
|
})
|
2023-08-09 20:49:10 +10:00
|
|
|
}
|
|
|
|
}
|
2023-08-06 21:29:26 -04:00
|
|
|
|
2022-11-12 13:11:54 +11:00
|
|
|
return (
|
2023-08-06 21:29:26 -04:00
|
|
|
<div
|
2023-10-11 13:36:54 +11:00
|
|
|
className="relative h-full flex flex-col"
|
2023-08-06 21:29:26 -04:00
|
|
|
onMouseMove={handleMouseMove}
|
2024-04-11 13:15:49 -07:00
|
|
|
ref={ref}
|
2023-08-06 21:29:26 -04:00
|
|
|
>
|
|
|
|
<AppHeader
|
|
|
|
className={
|
2023-08-07 17:07:28 -04:00
|
|
|
'transition-opacity transition-duration-75 ' +
|
|
|
|
paneOpacity +
|
2023-09-08 10:13:35 -04:00
|
|
|
(buttonDownInStream ? ' pointer-events-none' : '')
|
2023-08-06 21:29:26 -04:00
|
|
|
}
|
2023-10-16 13:28:41 -04:00
|
|
|
project={{ project, file }}
|
2023-08-18 10:27:01 -04:00
|
|
|
enableMenu={true}
|
2023-08-06 21:29:26 -04:00
|
|
|
/>
|
2024-04-18 20:09:40 -07:00
|
|
|
<ModalContainer />
|
2024-04-15 12:04:17 -04:00
|
|
|
<ModelingSidebar paneOpacity={paneOpacity} />
|
2023-08-06 21:29:26 -04:00
|
|
|
<Stream className="absolute inset-0 z-0" />
|
2024-02-11 12:59:00 +11:00
|
|
|
{/* <CamToggle /> */}
|
2024-04-19 10:50:58 -04:00
|
|
|
<LowerRightControls />
|
2022-11-12 13:11:54 +11:00
|
|
|
</div>
|
2022-11-26 08:34:23 +11:00
|
|
|
)
|
2022-11-12 13:11:54 +11:00
|
|
|
}
|