Skip to content

Commit 8bfdee5

Browse files
dsymegithub-actions[bot]
authored andcommitted
Colin the Code Commentor: Suggested comment improvements
1 parent 1825a25 commit 8bfdee5

File tree

1 file changed

+52
-10
lines changed

1 file changed

+52
-10
lines changed

src/main.ts

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import { UnrealBloomPass } from "three/examples/jsm/postprocessing/UnrealBloomPa
1212
// Set up the scene
1313
const scene = new THREE.Scene();
1414

15-
// Create atmospheric space background
15+
/**
16+
* Create atmospheric space background as a large sphere with a nebula-like gradient and subtle star effects.
17+
* @returns background mesh to be added to the scene
18+
*/
19+
1620
function createSpaceBackground() {
1721
// Create background geometry - a large sphere that encompasses the scene
1822
const backgroundGeometry = new THREE.SphereGeometry(500, 32, 16);
@@ -112,7 +116,11 @@ function createSpaceBackground() {
112116
const spaceBackground = createSpaceBackground();
113117
scene.add(spaceBackground);
114118

115-
// Calculate responsive field of view based on screen size
119+
/**
120+
* Calculate responsive field of view based on screen size
121+
* @returns the calculated field of view value adjusted for screen dimensions
122+
*/
123+
116124
function getResponsiveFOV(): number {
117125
const minFOV = 60; // Current desktop FOV
118126
const maxFOV = 100; // Wider view for small screens to fit more content
@@ -126,7 +134,11 @@ function getResponsiveFOV(): number {
126134
return fov;
127135
}
128136

129-
// Calculate responsive camera positions based on screen size
137+
/**
138+
* Calculate responsive camera positions based on screen size
139+
* @returns an object containing introZ and gameZ camera positions adjusted for screen width
140+
*/
141+
130142
function getResponsiveCameraPositions() {
131143
const minIntroZ = 3.0; // Current desktop intro position
132144
const maxIntroZ = 4.0; // Further back for mobile
@@ -185,7 +197,12 @@ const composer = new EffectComposer(renderer);
185197
const renderPass = new RenderPass(scene, camera);
186198
composer.addPass(renderPass);
187199

188-
// Calculate responsive pixel size based on screen size
200+
/**
201+
* Calculate responsive pixel size based on screen width and height.
202+
* Returns a pixel size that scales between a minimum and maximum value depending on screen dimensions.
203+
* @returns responsive pixel size based on current screen size
204+
*/
205+
189206
function getResponsivePixelSize(): number {
190207
const minPixelSize = 2.0; // Smaller pixels for mobile
191208
const maxPixelSize = 8.0; // Current desktop pixel size
@@ -199,7 +216,11 @@ function getResponsivePixelSize(): number {
199216
return pixelSize;
200217
}
201218

202-
// Calculate responsive scanline size based on screen size
219+
/**
220+
* Calculate responsive scanline size based on screen size.
221+
* @returns the scanline size adjusted for the current screen dimensions.
222+
*/
223+
203224
function getResponsiveScanlineSize(): number {
204225
const minScanlineSize = 2; // Thinner scanlines for mobile
205226
const maxScanlineSize = 5; // Current desktop scanline size
@@ -467,7 +488,10 @@ const crtOverlay = document.createElement("div");
467488
crtOverlay.className = "crt-overlay";
468489
document.body.appendChild(crtOverlay);
469490

470-
// Function to update scanline size responsively
491+
/**
492+
* Function to update the scanline size responsively by adjusting the background size of the CRT overlay element.
493+
*/
494+
471495
function updateScanlineSize() {
472496
const scanlineSize = getResponsiveScanlineSize();
473497
if (crtOverlay) {
@@ -504,7 +528,10 @@ let musicGainNode: GainNode | null = null;
504528
let isMuted = false;
505529
let musicFadeTimeout: number | null = null; // Track fade timeout for cleanup
506530

507-
// Load and decode the background music
531+
/**
532+
* Load and decode the background music asynchronously.
533+
*/
534+
508535
async function loadBackgroundMusic() {
509536
if (!audioContext) return;
510537

@@ -517,7 +544,14 @@ async function loadBackgroundMusic() {
517544
}
518545
}
519546

520-
// Start playing background music
547+
/**
548+
* Start playing background music with fade-in and looping.
549+
* Clears any pending fade timeout before starting.
550+
* Creates gain node for volume control and sets initial volume to 0.
551+
* Connects audio nodes and starts playback with looping enabled.
552+
* Handles music end event to restart music if game is still running.
553+
*/
554+
521555
function startBackgroundMusic() {
522556
if (!audioContext || !musicBuffer || backgroundMusic) return;
523557

@@ -564,7 +598,12 @@ function startBackgroundMusic() {
564598
}
565599
}
566600

567-
// Stop background music
601+
/**
602+
* Stop background music with a fade out effect.
603+
* Clears any pending fade timeout, fades out the music gain over 0.6 seconds,
604+
* then stops and disconnects the background music and gain node.
605+
*/
606+
568607
function stopBackgroundMusic() {
569608
if (!backgroundMusic || !musicGainNode || !audioContext) return;
570609

@@ -613,7 +652,10 @@ function stopBackgroundMusic() {
613652
}
614653
}
615654

616-
// Toggle mute state
655+
/**
656+
* Toggle mute state and smoothly fade audio volume.
657+
*/
658+
617659
function toggleMute() {
618660
isMuted = !isMuted;
619661

0 commit comments

Comments
 (0)