1
1
import { type Line2 } from 'three/addons/lines/Line2.js' ;
2
2
import { type CSS2DObject } from 'three/addons/renderers/CSS2DRenderer.js' ;
3
3
import { GUI } from 'dat.gui' ;
4
- import { getMapObjects , toggleDeprecatedDoors } from '../objects/mapObjects' ;
4
+ import { toggleDeprecatedDoors } from '../objects/mapObjects' ;
5
5
import { cameraControls , loadCameraState } from '../setup/camera' ;
6
+ import { getCurrentWorld , getWorld , setCurrentWorld } from '../setup/mapScene' ;
6
7
import { hideLegend , showLegend , switchLegend } from './legend' ;
7
8
import {
8
9
allColourModeKeys ,
@@ -12,23 +13,34 @@ import {
12
13
allLabelFilters ,
13
14
activeLabelFilters ,
14
15
labelFiltersAvailable ,
16
+ allWorldKeys ,
15
17
} from './gui.config' ;
18
+ import { startingWorldKey } from '../../config/urlParamsHelper' ;
19
+ import { WorldData } from '../setup/mapScene.types' ;
16
20
17
21
let gui : GUI ;
22
+ const sceneSwitchDelay = 1000 / 60 ;
18
23
19
24
const options = {
20
25
visible : {
21
26
labelVisibility : true ,
22
27
deprecatedPaths : true ,
23
28
legend : true ,
24
29
} ,
30
+ currentWorld : allWorldKeys [ startingWorldKey ] ,
25
31
colourMode : activeColourModes [ colourModesAvailable [ 0 ] ] ,
26
32
cameraPosition : allCameraPositionsKeys . isometric ,
27
33
labelFilter : activeLabelFilters [ labelFiltersAvailable [ 0 ] ] ,
28
34
} ;
29
35
30
36
export function setupGUI ( ) {
31
37
gui = new GUI ( ) ;
38
+
39
+ gui
40
+ . add ( options , 'currentWorld' , Object . values ( allWorldKeys ) )
41
+ . name ( 'World' )
42
+ . onChange ( changeWorld ) ;
43
+
32
44
gui
33
45
. add ( options , 'colourMode' , Object . values ( activeColourModes ) )
34
46
. name ( 'Colour Mode' )
@@ -60,35 +72,43 @@ export function setupGUI() {
60
72
. onChange ( toggleLegend ) ;
61
73
}
62
74
63
- function _toggleLabelVisibility ( labels : CSS2DObject [ ] ) {
75
+ function _toggleLabelVisibility ( labels : CSS2DObject [ ] , visibility : boolean ) {
64
76
for ( const label of labels ) {
65
- label . visible = options . visible . labelVisibility ;
77
+ label . visible = visibility ;
66
78
}
67
79
}
68
80
81
+ function _toggleWorldLabelVisibility ( world : WorldData , visibility : boolean ) {
82
+ const { roomLabels, pathLabels, portalLabels, doorLabels } = world ;
83
+
84
+ _toggleLabelVisibility ( roomLabels , visibility ) ;
85
+ _toggleLabelVisibility ( pathLabels , visibility ) ;
86
+ _toggleLabelVisibility ( portalLabels , visibility ) ;
87
+ _toggleLabelVisibility ( doorLabels , visibility ) ;
88
+ }
89
+
69
90
function toggleAllLabelVisibility ( ) {
70
- const { roomLabels, pathLabels, portalLabels, doorLabels } = getMapObjects ( ) ;
91
+ const world = getCurrentWorld ( ) ;
92
+ const { labelVisibility } = options . visible ;
71
93
72
- _toggleLabelVisibility ( roomLabels ) ;
73
- _toggleLabelVisibility ( pathLabels ) ;
74
- _toggleLabelVisibility ( portalLabels ) ;
75
- _toggleLabelVisibility ( doorLabels ) ;
94
+ _toggleWorldLabelVisibility ( world , labelVisibility ) ;
76
95
}
77
96
78
97
function toggleDeprecatedPaths ( ) {
79
- const { pathObjects } = getMapObjects ( ) ;
98
+ const world = getCurrentWorld ( ) ;
99
+ const { pathObjects } = world ;
80
100
81
101
for ( const path of pathObjects ) {
82
102
if ( path . userData . deprecated ) {
83
103
path . visible = options . visible . deprecatedPaths ;
84
104
}
85
105
}
86
106
87
- toggleDeprecatedDoors ( options . visible . deprecatedPaths ) ;
107
+ toggleDeprecatedDoors ( world , options . visible . deprecatedPaths ) ;
88
108
}
89
109
90
110
function changeColourMode ( ) {
91
- const { pathObjects } = getMapObjects ( ) ;
111
+ const { pathObjects } = getCurrentWorld ( ) ;
92
112
let materialKey ;
93
113
94
114
switch ( options . colourMode ) {
@@ -126,7 +146,7 @@ function changeColourMode() {
126
146
}
127
147
128
148
function changeLabelFilter ( ) {
129
- const { portalLabels, roomLabels } = getMapObjects ( ) ;
149
+ const { portalLabels, roomLabels } = getCurrentWorld ( ) ;
130
150
131
151
for ( const label of portalLabels ) {
132
152
label . element . className = 'portalLabel' ;
@@ -189,6 +209,34 @@ function changeCameraPosition() {
189
209
}
190
210
}
191
211
212
+ function changeWorld ( ) {
213
+ // Hide labels from current world
214
+ const currentWorld = getCurrentWorld ( ) ;
215
+ _toggleWorldLabelVisibility ( currentWorld , false ) ;
216
+
217
+ const worldId = Object . keys ( allWorldKeys ) . find (
218
+ id => allWorldKeys [ id ] === options . currentWorld ,
219
+ ) ;
220
+ if ( worldId !== undefined ) {
221
+ // Can't hide labels from previous world on the same frame as switching to new world
222
+ // Delay switching to new world slightly to prevent labels from previous world appearing in new world
223
+ setTimeout ( ( ) => {
224
+ setCurrentWorld ( worldId ) ;
225
+
226
+ // Update state of labels of new world
227
+ const { labelVisibility } = options . visible ;
228
+ const newWorld = getWorld ( worldId ) ;
229
+ _toggleWorldLabelVisibility ( newWorld , labelVisibility ) ;
230
+
231
+ // Update new world according to GUI settings
232
+ changeColourMode ( ) ;
233
+ changeCameraPosition ( ) ;
234
+ changeLabelFilter ( ) ;
235
+ toggleDeprecatedPaths ( ) ;
236
+ } , sceneSwitchDelay ) ;
237
+ }
238
+ }
239
+
192
240
function toggleLegend ( ) {
193
241
if ( options . visible . legend ) {
194
242
showLegend ( ) ;
@@ -198,6 +246,7 @@ function toggleLegend() {
198
246
}
199
247
200
248
function toggleCameraPostion ( index : number , autoRotate : boolean ) {
201
- loadCameraState ( index ) ;
249
+ const world = getCurrentWorld ( ) ;
250
+ loadCameraState ( world , index ) ;
202
251
cameraControls . autoRotate = autoRotate ;
203
252
}
0 commit comments