Skip to content

Commit 17e7c9b

Browse files
committed
Implemented level control from planets
1 parent 09151e4 commit 17e7c9b

3 files changed

Lines changed: 23 additions & 30 deletions

File tree

package-lock.json

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

src/pages/home/Home.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ import { main } from "./js/main.js";
55
import { useMouseMoving } from "../../hooks/useMouseMoving.js";
66

77
export default function Home() {
8-
const lvlNum = 4;
98
const canvasRef = useRef<HTMLCanvasElement | null>(null);
109
const zoomOutRef = useRef<(() => void) | null>(null);
11-
10+
const getLevelRef = useRef<(() => number) | null>(null);
1211
const [isVisible, setIsVisible] = useState(false);
1312
const [mountKey, setMountKey] = useState(0);
1413
const isMouseMoving = useMouseMoving(2500);
@@ -26,8 +25,9 @@ export default function Home() {
2625

2726
useEffect(() => {
2827
if (!canvasRef.current) return;
29-
const { zoomOut } = main(canvasRef.current, handleOpen);
28+
const { zoomOut, getLevel } = main(canvasRef.current, handleOpen);
3029
zoomOutRef.current = zoomOut;
30+
getLevelRef.current = getLevel;
3131
}, []);
3232

3333
return (
@@ -49,7 +49,7 @@ export default function Home() {
4949
<LevelComponent
5050
key={mountKey}
5151
onClose={() => handleClose()}
52-
lvl={lvlNum}
52+
lvl={getLevelRef.current ? getLevelRef.current() : 0}
5353
/>
5454
</div>
5555

src/pages/home/js/main.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ export function main( canvas, onPlanetFocus ) {
2424
const origin = new THREE.Vector3(0, 0, 0);
2525

2626

27+
function getLevel() {
28+
if (!focus.focusedPlanet) return 0;
29+
return focus.focusedPlanet.level;
30+
}
31+
2732
// --- Render loop ---
2833

2934
requestAnimationFrame(render);
@@ -36,8 +41,6 @@ export function main( canvas, onPlanetFocus ) {
3641

3742
renderer.render(scene, camera);
3843
requestAnimationFrame(render);
39-
40-
4144

4245
// --- Done! (the rest is defining these functions) ---
4346

@@ -85,14 +88,12 @@ export function main( canvas, onPlanetFocus ) {
8588
function updateFocusTarget() {
8689

8790
if (!focus.focusedPlanet) return;
88-
8991
const planetPosition = focus.focusedPlanet.mesh.position;
9092
const planetDirection = planetPosition.clone().normalize();
9193

9294
focus.cameraTarget = planetPosition.clone().add(planetDirection.multiplyScalar(focus.focusedPlanet.radius + ZOOM_DIST));
9395
focus.cameraTarget.y += focus.focusedPlanet.radius * 0.8;
9496
focus.lookAtTarget = planetPosition.clone();
95-
9697
}
9798

9899
function updateCameraTween () {
@@ -156,6 +157,6 @@ export function main( canvas, onPlanetFocus ) {
156157

157158
}
158159

159-
return { zoomOut };
160+
return { zoomOut, getLevel };
160161

161162
}

0 commit comments

Comments
 (0)