2024-07-03 09:22:46 +10:00
|
|
|
import { MouseEventHandler, useEffect, useMemo, useRef } from 'react'
|
2024-04-03 19:38:16 +11:00
|
|
|
import { uuidv4 } from 'lib/utils'
|
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'
|
2024-08-03 18:08:51 +10:00
|
|
|
import { EngineCommand } from 'lang/std/artifactGraph'
|
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'
|
2024-08-09 02:47:25 -04:00
|
|
|
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-08-14 17:56:28 -07:00
|
|
|
import { codeManager, 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'
|
2024-08-16 07:15:42 -04:00
|
|
|
import { isDesktop } from 'lib/isDesktop'
|
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'
|
2024-05-20 20:52:33 -07:00
|
|
|
import useHotkeyWrapper from 'lib/hotkeyWrapper'
|
2024-05-24 13:00:15 +10:00
|
|
|
import Gizmo from 'components/Gizmo'
|
2024-06-28 18:06:40 -07:00
|
|
|
import { CoreDumpManager } from 'lib/coredump'
|
2024-07-05 18:40:43 -04:00
|
|
|
import { UnitsMenu } from 'components/UnitsMenu'
|
2024-09-09 18:17:45 -04:00
|
|
|
import { reportRejection } from 'lib/trap'
|
2022-11-22 09:06:08 +11:00
|
|
|
|
2023-06-22 16:43:33 +10:00
|
|
|
export function App() {
|
2023-11-07 14:29:50 +11:00
|
|
|
const { project, file } = useLoaderData() as IndexLoaderData
|
2024-08-16 07:15:42 -04:00
|
|
|
useRefreshSettings(PATHS.FILE + 'SETTINGS')
|
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-07-17 18:58:01 +10:00
|
|
|
const { context, state } = useModelingContext()
|
2024-04-11 13:15:49 -07:00
|
|
|
|
2024-06-28 18:06:40 -07:00
|
|
|
const { auth, settings } = useSettingsAuthContext()
|
|
|
|
const token = auth?.context?.token
|
|
|
|
|
2024-07-03 09:22:46 +10:00
|
|
|
const coreDumpManager = useMemo(
|
2024-08-14 17:56:28 -07:00
|
|
|
() => new CoreDumpManager(engineCommandManager, codeManager, token),
|
2024-07-03 09:22:46 +10:00
|
|
|
[]
|
|
|
|
)
|
2024-06-28 18:06:40 -07:00
|
|
|
|
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-08-06 21:29:26 -04:00
|
|
|
|
2024-02-15 14:25:26 -05:00
|
|
|
useHotkeys('backspace', (e) => {
|
|
|
|
e.preventDefault()
|
|
|
|
})
|
2024-05-20 20:52:33 -07:00
|
|
|
useHotkeyWrapper(
|
2024-08-16 07:15:42 -04:00
|
|
|
[isDesktop() ? 'mod + ,' : 'shift + mod + ,'],
|
2024-08-09 02:47:25 -04:00
|
|
|
() => navigate(filePath + PATHS.SETTINGS),
|
2024-02-12 18:11:47 -05:00
|
|
|
{
|
|
|
|
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'
|
2024-07-02 17:16:27 +10:00
|
|
|
: context.store?.didDragInStream
|
2023-09-15 22:37:40 -04:00
|
|
|
? '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-09-09 18:17:45 -04:00
|
|
|
engineCommandManager.sendSceneCommand(message).catch(reportRejection)
|
2024-02-11 12:59:00 +11:00
|
|
|
}, 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,
|
2024-07-02 17:16:27 +10:00
|
|
|
...context.store?.streamDimensions,
|
2023-08-09 20:49:10 +10:00
|
|
|
})
|
2023-08-06 21:29:26 -04:00
|
|
|
|
2023-08-09 20:49:10 +10:00
|
|
|
const newCmdId = uuidv4()
|
2024-09-09 19:59:36 +03:00
|
|
|
if (state.matches({ idle: 'showPlanes' })) return
|
2024-08-03 07:05:35 +10:00
|
|
|
if (context.store?.buttonDownInStream !== undefined) return
|
|
|
|
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 +
|
2024-07-02 17:16:27 +10:00
|
|
|
(context.store?.buttonDownInStream ? ' pointer-events-none' : '')
|
2023-08-06 21:29:26 -04:00
|
|
|
}
|
2024-08-29 10:38:13 -04:00
|
|
|
// Override the electron window draggable region behavior as well
|
|
|
|
// when the button is down in the stream
|
|
|
|
style={
|
2024-09-05 15:18:32 -04:00
|
|
|
isDesktop() && context.store?.buttonDownInStream
|
|
|
|
? ({
|
|
|
|
'-webkit-app-region': 'no-drag',
|
|
|
|
} as React.CSSProperties)
|
|
|
|
: {}
|
2024-08-29 10:38:13 -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} />
|
2024-06-18 16:08:41 +10:00
|
|
|
<Stream />
|
2024-02-11 12:59:00 +11:00
|
|
|
{/* <CamToggle /> */}
|
2024-06-28 18:06:40 -07:00
|
|
|
<LowerRightControls coreDumpManager={coreDumpManager}>
|
2024-07-05 18:40:43 -04:00
|
|
|
<UnitsMenu />
|
2024-05-24 13:00:15 +10:00
|
|
|
<Gizmo />
|
|
|
|
</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
|
|
|
}
|