Skip to content

Commit d127eef

Browse files
dsymegithub-actions[bot]
authored andcommitted
The Code Commentor: Suggested comment improvements
1 parent 3ec5751 commit d127eef

File tree

1 file changed

+39
-10
lines changed

1 file changed

+39
-10
lines changed

src/main.ts

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ 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+
* Creates an atmospheric space background mesh with a gradient and subtle noise effects to simulate a nebula-like space atmosphere, including sparse distant stars.
17+
* @returns A THREE.Mesh representing the space background.
18+
*/
1619
function createSpaceBackground() {
1720
// Create background geometry - a large sphere that encompasses the scene
1821
const backgroundGeometry = new THREE.SphereGeometry(500, 32, 16);
@@ -112,7 +115,11 @@ function createSpaceBackground() {
112115
const spaceBackground = createSpaceBackground();
113116
scene.add(spaceBackground);
114117

115-
// Calculate responsive field of view based on screen size
118+
/**
119+
* Calculates a responsive field of view based on the current screen size.
120+
* Adjusts the FOV between a minimum and maximum value depending on the screen width.
121+
* @returns The calculated field of view value.
122+
*/
116123
function getResponsiveFOV(): number {
117124
const minFOV = 60; // Current desktop FOV
118125
const maxFOV = 100; // Wider view for small screens to fit more content
@@ -126,7 +133,10 @@ function getResponsiveFOV(): number {
126133
return fov;
127134
}
128135

129-
// Calculate responsive camera positions based on screen size
136+
/**
137+
* Calculates responsive camera positions for intro and game views based on the current screen size.
138+
* @returns An object containing the calculated introZ and gameZ camera positions.
139+
*/
130140
function getResponsiveCameraPositions() {
131141
const minIntroZ = 3.0; // Current desktop intro position
132142
const maxIntroZ = 4.0; // Further back for mobile
@@ -185,7 +195,11 @@ const composer = new EffectComposer(renderer);
185195
const renderPass = new RenderPass(scene, camera);
186196
composer.addPass(renderPass);
187197

188-
// Calculate responsive pixel size based on screen size
198+
/**
199+
* Calculates a responsive pixel size based on the current screen dimensions.
200+
* Returns a pixel size interpolated between minimum and maximum values depending on the screen width.
201+
* @returns The calculated responsive pixel size.
202+
*/
189203
function getResponsivePixelSize(): number {
190204
const minPixelSize = 2.0; // Smaller pixels for mobile
191205
const maxPixelSize = 8.0; // Current desktop pixel size
@@ -199,7 +213,10 @@ function getResponsivePixelSize(): number {
199213
return pixelSize;
200214
}
201215

202-
// Calculate responsive scanline size based on screen size
216+
/**
217+
* Calculates a responsive scanline size based on the current screen dimensions.
218+
* @returns The calculated scanline size rounded to the nearest integer.
219+
*/
203220
function getResponsiveScanlineSize(): number {
204221
const minScanlineSize = 2; // Thinner scanlines for mobile
205222
const maxScanlineSize = 5; // Current desktop scanline size
@@ -504,7 +521,10 @@ let musicGainNode: GainNode | null = null;
504521
let isMuted = false;
505522
let musicFadeTimeout: number | null = null; // Track fade timeout for cleanup
506523

507-
// Load and decode the background music
524+
/**
525+
* Loads and decodes the background music file, storing it in the music buffer.
526+
* Logs an error to the console if loading fails.
527+
*/
508528
async function loadBackgroundMusic() {
509529
if (!audioContext) return;
510530

@@ -517,7 +537,9 @@ async function loadBackgroundMusic() {
517537
}
518538
}
519539

520-
// Start playing background music
540+
/**
541+
* Starts playing the background music if not already playing. Handles fade-in, looping, and restarts music if it ends unexpectedly while the game is running.
542+
*/
521543
function startBackgroundMusic() {
522544
if (!audioContext || !musicBuffer || backgroundMusic) return;
523545

@@ -564,7 +586,9 @@ function startBackgroundMusic() {
564586
}
565587
}
566588

567-
// Stop background music
589+
/**
590+
* Stops the background music by fading it out over 0.6 seconds, then disconnects and cleans up the audio nodes.
591+
*/
568592
function stopBackgroundMusic() {
569593
if (!backgroundMusic || !musicGainNode || !audioContext) return;
570594

@@ -613,7 +637,9 @@ function stopBackgroundMusic() {
613637
}
614638
}
615639

616-
// Toggle mute state
640+
/**
641+
* Toggles the mute state for the music, fading the volume in or out over 0.3 seconds, and updates the mute button text accordingly.
642+
*/
617643
function toggleMute() {
618644
isMuted = !isMuted;
619645

@@ -646,7 +672,10 @@ function toggleMute() {
646672
}
647673
}
648674

649-
// Initialize audio context (must be done after user interaction)
675+
/**
676+
* Initializes the audio context if it has not been initialized yet.
677+
* Loads background music without starting playback.
678+
*/
650679
async function initializeAudio() {
651680
if (!isAudioInitialized) {
652681
try {

0 commit comments

Comments
 (0)