Skip to content

Commit b730b22

Browse files
authored
Merge pull request #9 from mstop4/chocolate-bnuuy
2.0.0 - Add support for multiple worlds
2 parents 9d4a6de + 9aa2c66 commit b730b22

File tree

20 files changed

+2279
-1670
lines changed

20 files changed

+2279
-1670
lines changed

package-lock.json

Lines changed: 1550 additions & 1436 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "mc-3d-path-map",
33
"private": true,
4-
"version": "1.1.1",
4+
"version": "2.0.0",
55
"type": "module",
66
"scripts": {
77
"prepare": "husky install",
@@ -13,24 +13,24 @@
1313
"preview": "vite preview"
1414
},
1515
"devDependencies": {
16-
"@types/colorbrewer": "^1.0.30",
17-
"@types/dat.gui": "^0.7.10",
18-
"@types/three": "^0.156.0",
19-
"@typescript-eslint/eslint-plugin": "^6.7.4",
20-
"@typescript-eslint/parser": "^6.7.4",
21-
"eslint": "^8.51.0",
22-
"eslint-config-prettier": "^9.0.0",
23-
"eslint-plugin-prettier": "^5.0.0",
24-
"husky": "^8.0.3",
25-
"lint-staged": "^14.0.1",
26-
"prettier": "^3.0.3",
27-
"typescript": "^5.2.2",
28-
"vite": "^4.4.11"
16+
"@types/colorbrewer": "^1.0.32",
17+
"@types/dat.gui": "^0.7.13",
18+
"@types/three": "^0.166.0",
19+
"@typescript-eslint/eslint-plugin": "^7.15.0",
20+
"@typescript-eslint/parser": "^7.15.0",
21+
"eslint": "^8.56.0",
22+
"eslint-config-prettier": "^9.1.0",
23+
"eslint-plugin-prettier": "^5.1.3",
24+
"husky": "^9.0.11",
25+
"lint-staged": "^15.2.7",
26+
"prettier": "^3.3.2",
27+
"typescript": "^5.5.3",
28+
"vite": "^5.3.3"
2929
},
3030
"dependencies": {
31-
"colorbrewer": "^1.5.3",
31+
"colorbrewer": "^1.5.6",
3232
"dat.gui": "^0.7.9",
3333
"simplify-3d": "^1.0.0",
34-
"three": "^0.157.0"
34+
"three": "^0.164.1"
3535
}
3636
}

src/components/objects/gui.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
import dataManifest from '../../data/manifest.json';
2+
3+
export const allWorldKeys: Record<string, string> = {};
4+
for (const world of dataManifest) {
5+
allWorldKeys[world.id] = world.name;
6+
}
7+
18
export const allColourModeKeys: Record<string, string> = {
29
default: 'Full',
310
cbf: 'Colourblind-friendly',

src/components/objects/gui.ts

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { type Line2 } from 'three/addons/lines/Line2.js';
22
import { type CSS2DObject } from 'three/addons/renderers/CSS2DRenderer.js';
33
import { GUI } from 'dat.gui';
4-
import { getMapObjects, toggleDeprecatedDoors } from '../objects/mapObjects';
4+
import { toggleDeprecatedDoors } from '../objects/mapObjects';
55
import { cameraControls, loadCameraState } from '../setup/camera';
6+
import { getCurrentWorld, getWorld, setCurrentWorld } from '../setup/mapScene';
67
import { hideLegend, showLegend, switchLegend } from './legend';
78
import {
89
allColourModeKeys,
@@ -12,23 +13,34 @@ import {
1213
allLabelFilters,
1314
activeLabelFilters,
1415
labelFiltersAvailable,
16+
allWorldKeys,
1517
} from './gui.config';
18+
import { startingWorldKey } from '../../config/urlParamsHelper';
19+
import { WorldData } from '../setup/mapScene.types';
1620

1721
let gui: GUI;
22+
const sceneSwitchDelay = 1000 / 60;
1823

1924
const options = {
2025
visible: {
2126
labelVisibility: true,
2227
deprecatedPaths: true,
2328
legend: true,
2429
},
30+
currentWorld: allWorldKeys[startingWorldKey],
2531
colourMode: activeColourModes[colourModesAvailable[0]],
2632
cameraPosition: allCameraPositionsKeys.isometric,
2733
labelFilter: activeLabelFilters[labelFiltersAvailable[0]],
2834
};
2935

3036
export function setupGUI() {
3137
gui = new GUI();
38+
39+
gui
40+
.add(options, 'currentWorld', Object.values(allWorldKeys))
41+
.name('World')
42+
.onChange(changeWorld);
43+
3244
gui
3345
.add(options, 'colourMode', Object.values(activeColourModes))
3446
.name('Colour Mode')
@@ -60,35 +72,43 @@ export function setupGUI() {
6072
.onChange(toggleLegend);
6173
}
6274

63-
function _toggleLabelVisibility(labels: CSS2DObject[]) {
75+
function _toggleLabelVisibility(labels: CSS2DObject[], visibility: boolean) {
6476
for (const label of labels) {
65-
label.visible = options.visible.labelVisibility;
77+
label.visible = visibility;
6678
}
6779
}
6880

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+
6990
function toggleAllLabelVisibility() {
70-
const { roomLabels, pathLabels, portalLabels, doorLabels } = getMapObjects();
91+
const world = getCurrentWorld();
92+
const { labelVisibility } = options.visible;
7193

72-
_toggleLabelVisibility(roomLabels);
73-
_toggleLabelVisibility(pathLabels);
74-
_toggleLabelVisibility(portalLabels);
75-
_toggleLabelVisibility(doorLabels);
94+
_toggleWorldLabelVisibility(world, labelVisibility);
7695
}
7796

7897
function toggleDeprecatedPaths() {
79-
const { pathObjects } = getMapObjects();
98+
const world = getCurrentWorld();
99+
const { pathObjects } = world;
80100

81101
for (const path of pathObjects) {
82102
if (path.userData.deprecated) {
83103
path.visible = options.visible.deprecatedPaths;
84104
}
85105
}
86106

87-
toggleDeprecatedDoors(options.visible.deprecatedPaths);
107+
toggleDeprecatedDoors(world, options.visible.deprecatedPaths);
88108
}
89109

90110
function changeColourMode() {
91-
const { pathObjects } = getMapObjects();
111+
const { pathObjects } = getCurrentWorld();
92112
let materialKey;
93113

94114
switch (options.colourMode) {
@@ -126,7 +146,7 @@ function changeColourMode() {
126146
}
127147

128148
function changeLabelFilter() {
129-
const { portalLabels, roomLabels } = getMapObjects();
149+
const { portalLabels, roomLabels } = getCurrentWorld();
130150

131151
for (const label of portalLabels) {
132152
label.element.className = 'portalLabel';
@@ -189,6 +209,34 @@ function changeCameraPosition() {
189209
}
190210
}
191211

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+
192240
function toggleLegend() {
193241
if (options.visible.legend) {
194242
showLegend();
@@ -198,6 +246,7 @@ function toggleLegend() {
198246
}
199247

200248
function toggleCameraPostion(index: number, autoRotate: boolean) {
201-
loadCameraState(index);
249+
const world = getCurrentWorld();
250+
loadCameraState(world, index);
202251
cameraControls.autoRotate = autoRotate;
203252
}

0 commit comments

Comments
 (0)