1
1
import Scene from "@/components/Scene.tsx"
2
2
import { AnimatePresence } from "framer-motion"
3
- import { ReactElement , useCallback , useEffect , useState } from "react"
3
+ import { ReactElement , useCallback , useEffect , useRef , useState } from "react"
4
4
import { ModalControlProvider , useModalManager } from "@/ui/ModalContext"
5
5
import { PanelControlProvider , usePanelManager } from "@/ui/PanelContext"
6
6
import { useTheme } from "@/ui/ThemeContext"
@@ -65,9 +65,10 @@ import GlobalUIComponent from "./ui/components/GlobalUIComponent.tsx"
65
65
import InitialConfigPanel from "./ui/panels/configuring/initial-config/InitialConfigPanel.tsx"
66
66
import WPILibConnectionStatus from "./ui/components/WPILibConnectionStatus.tsx"
67
67
import AutoTestPanel from "./ui/panels/simulation/AutoTestPanel.tsx"
68
+ import MainMenuModal from "@/modals/MainMenuModal"
68
69
69
70
function Synthesis ( ) {
70
- const { openModal, closeModal, getActiveModalElement } = useModalManager ( initialModals )
71
+ const { openModal, closeModal, getActiveModalElement, registerModal } = useModalManager ( initialModals )
71
72
const { openPanel, closePanel, closeAllPanels, getActivePanelElements } = usePanelManager ( initialPanels )
72
73
const { showTooltip } = useTooltipManager ( )
73
74
@@ -82,34 +83,44 @@ function Synthesis() {
82
83
const panelElements = getActivePanelElements ( )
83
84
const modalElement = getActiveModalElement ( )
84
85
86
+ const mainLoopHandle = useRef ( 0 )
87
+ registerModal ( "main-menu" , {
88
+ id : "main-menu" ,
89
+ component : (
90
+ < MainMenuModal
91
+ key = "main-menu"
92
+ modalId = "main-menu"
93
+ startSingleplayerCallback = { ( ) => {
94
+ World . InitWorld ( )
95
+
96
+ if ( ! PreferencesSystem . getGlobalPreference < boolean > ( "ReportAnalytics" ) && ! import . meta. env . DEV ) {
97
+ setConsentPopupDisable ( false )
98
+ }
99
+
100
+ const mainLoop = ( ) => {
101
+ mainLoopHandle . current = requestAnimationFrame ( mainLoop )
102
+ World . UpdateWorld ( )
103
+ }
104
+ mainLoop ( )
105
+
106
+ World . SceneRenderer . UpdateSkyboxColors ( defaultTheme )
107
+ } }
108
+ />
109
+ ) ,
110
+ } )
111
+
85
112
useEffect ( ( ) => {
86
113
const urlParams = new URLSearchParams ( document . location . search )
87
114
if ( urlParams . has ( "code" ) ) {
88
115
window . opener . convertAuthToken ( urlParams . get ( "code" ) )
89
116
window . close ( )
90
117
return
91
118
}
92
-
93
- World . InitWorld ( )
94
-
95
- if ( ! PreferencesSystem . getGlobalPreference < boolean > ( "ReportAnalytics" ) && ! import . meta. env . DEV ) {
96
- setConsentPopupDisable ( false )
97
- }
98
-
99
- let mainLoopHandle = 0
100
- const mainLoop = ( ) => {
101
- mainLoopHandle = requestAnimationFrame ( mainLoop )
102
-
103
- World . UpdateWorld ( )
104
- }
105
- mainLoop ( )
106
-
107
- World . SceneRenderer . UpdateSkyboxColors ( defaultTheme )
108
-
119
+ openModal ( "main-menu" )
109
120
// Cleanup
110
121
return ( ) => {
111
122
// TODO: Teardown literally everything
112
- cancelAnimationFrame ( mainLoopHandle )
123
+ cancelAnimationFrame ( mainLoopHandle . current )
113
124
World . DestroyWorld ( )
114
125
// World.SceneRenderer.RemoveAllSceneObjects();
115
126
}
0 commit comments