Skip to content

genai-commentor: Suggested comment improvements #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 39 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import { UnrealBloomPass } from "three/examples/jsm/postprocessing/UnrealBloomPa
// Set up the scene
const scene = new THREE.Scene();

// Create atmospheric space background
/**
* Creates an atmospheric space background mesh with a gradient and subtle noise effects to simulate a nebula-like space atmosphere, including sparse distant stars.
* @returns A THREE.Mesh representing the space background.
*/
function createSpaceBackground() {
// Create background geometry - a large sphere that encompasses the scene
const backgroundGeometry = new THREE.SphereGeometry(500, 32, 16);
Expand Down Expand Up @@ -112,7 +115,11 @@ function createSpaceBackground() {
const spaceBackground = createSpaceBackground();
scene.add(spaceBackground);

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

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

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

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

// Load and decode the background music
/**
* Loads and decodes the background music file, storing it in the music buffer.
* Logs an error to the console if loading fails.
*/
async function loadBackgroundMusic() {
if (!audioContext) return;

Expand All @@ -517,7 +537,9 @@ async function loadBackgroundMusic() {
}
}

// Start playing background music
/**
* 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.
*/
function startBackgroundMusic() {
if (!audioContext || !musicBuffer || backgroundMusic) return;

Expand Down Expand Up @@ -564,7 +586,9 @@ function startBackgroundMusic() {
}
}

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

Expand Down Expand Up @@ -613,7 +637,9 @@ function stopBackgroundMusic() {
}
}

// Toggle mute state
/**
* Toggles the mute state for the music, fading the volume in or out over 0.3 seconds, and updates the mute button text accordingly.
*/
function toggleMute() {
isMuted = !isMuted;

Expand Down Expand Up @@ -646,7 +672,10 @@ function toggleMute() {
}
}

// Initialize audio context (must be done after user interaction)
/**
* Initializes the audio context if it has not been initialized yet.
* Loads background music without starting playback.
*/
async function initializeAudio() {
if (!isAudioInitialized) {
try {
Expand Down