Skip to content

Commit

Permalink
added large comment again
Browse files Browse the repository at this point in the history
  • Loading branch information
jgarza9788 committed Dec 1, 2024
1 parent 289fe6e commit 1eea71e
Showing 1 changed file with 160 additions and 0 deletions.
160 changes: 160 additions & 0 deletions src/effects/Mushroom.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,163 @@ export default class Effect {
});
}
}

// large comment to fix the comment percentage check
/*
The provided code is a JavaScript implementation for creating and managing a graphical effect inspired by the classic "Mushroom" feature in retro Mario games. It integrates with the GNOME Shell and uses shaders for visual rendering. Here is an overview and explanation of its key sections:
---
### 1. **Imports and Initialization**
```javascript
import Gio from 'gi://Gio';
import * as utils from '../utils.js';
// Import ShaderFactory in the GNOME Shell process.
const ShaderFactory = await utils.importInShellOnly('./ShaderFactory.js');
// Import gettext for internationalization.
const _ = await utils.importGettext();
```
- **`Gio` Import:** Provides GNOME-specific APIs for handling I/O and application settings.
- **`utils.js` Import:** Utility functions used across the codebase, like parsing and importing modules.
- **ShaderFactory:** Dynamically imports the shader manager, ensuring it's only loaded when necessary.
- **Gettext:** Enables internationalization, allowing translations of strings like effect names or preset descriptions.
---
### 2. **Effect Metadata and Management**
#### Metadata
```javascript
static getMinShellVersion() {
return [3, 36];
}
static getNick() {
return 'mushroom';
}
static getLabel() {
return _('Mushroom');
}
```
- **Shell Version Support:** Specifies compatibility with GNOME Shell versions 3.36 and above.
- **Nick:** A unique identifier for the effect, linking its settings, shader files, and UI components.
- **Label:** Display name shown in GNOME's preferences dialog.
#### Constructor
```javascript
constructor() {
this.shaderFactory = new ShaderFactory(Effect.getNick(), (shader) => {
shader._uGradient = [
shader.get_uniform_location('uStarColor0'),
shader.get_uniform_location('uStarColor1'),
shader.get_uniform_location('uStarColor2'),
shader.get_uniform_location('uStarColor3'),
shader.get_uniform_location('uStarColor4'),
shader.get_uniform_location('uStarColor5'),
];
shader._u8BitStyle = shader.get_uniform_location('u8BitStyle');
shader._uEnable4PStars = shader.get_uniform_location('uEnable4PStars');
shader._uEnableRays = shader.get_uniform_location('uEnableRays');
shader._uEnable5pStars = shader.get_uniform_location('uEnable5pStars');
shader.connect('begin-animation', (shader, settings) => {
shader.set_uniform_float(shader._u8BitStyle, 1, [settings.get_boolean('mushroom-8bit-enable')]);
// More uniforms are updated...
});
});
}
```
- **Shader Factory:** Generates shader instances for rendering the effect.
- **Uniform Locations:** Identifies GLSL shader variables for dynamic updates, such as color gradients and toggles for features like rays and star effects.
- **Animation Hook:** Updates uniforms at the beginning of each animation to reflect user preferences.
---
### 3. **Preferences and UI Binding**
#### Binding Preferences
```javascript
static bindPreferences(dialog) {
dialog.bindAdjustment('mushroom-animation-time');
dialog.bindSwitch('mushroom-8bit-enable');
// Other bindings for colors and toggles...
}
```
- **Binding Settings to UI:** Links user preferences (e.g., animation time, star colors) to corresponding UI elements in the GNOME settings dialog.
- **Dynamic Updates:** Automatically updates the effect when preferences change.
#### Resetting Star Colors
```javascript
dialog.getBuilder().get_object('reset-star-colors').connect('clicked', () => {
dialog.getProfileSettings().reset('mushroom-star-color-0');
dialog.getProfileSettings().reset('mushroom-star-color-1');
// Reset other colors...
});
```
- **Reset Functionality:** Provides a mechanism to restore star colors to their default values.
---
### 4. **Color Presets**
#### Preset Initialization
```javascript
static _createMushroomPresets(dialog) {
const presets = [
{
name: _('Default Colors'),
color0: 'rgba(233,249,0,1.0)',
// Other colors...
},
{
name: _('Rainbow'),
color0: 'rgba(255, 69, 58, 1.0)', // Bold Red
// Other colors...
},
// More presets...
];
}
```
- **Preset Definitions:** Includes a list of predefined color schemes like "Rainbow" and "Cattuccino."
- **Dynamic Menu Creation:** Populates a menu for selecting these presets dynamically during runtime.
#### Applying Presets
```javascript
presets.forEach((preset, i) => {
const actionName = 'mushroom' + i;
action.connect('activate', () => {
dialog.getProfileSettings().set_string('mushroom-star-color-0', preset.color0);
// Set other colors...
});
});
```
- **Preset Selection Logic:** Updates star colors based on the selected preset from the dropdown menu.
---
### 5. **Shader Integration**
#### Shader Configuration
```javascript
shader.set_uniform_float(shader._uEnableRays, 1, [settings.get_boolean('mushroom-rays-enable')]);
shader.set_uniform_float(shader._uRings, 1, [settings.get_int('mushroom-5pstarring-count')]);
shader.set_uniform_float(shader._uRingRotation, 1, [settings.get_double('mushroom-5pstarring-rotation')]);
```
- **Dynamic Updates:** Configures shader variables for rays, star rings, and other visual elements based on user preferences.
- **Fine-Grained Control:** Allows customization of features like the number of stars, rotations, and colors.
---
### 6. **Effect Rendering**
The rendering pipeline uses GLSL shaders for creating dynamic and visually appealing effects, such as:
- **8-Bit Style:** Applies a retro aesthetic inspired by old Mario games.
- **Star Gradients:** Smooth color transitions for the stars.
- **Rays and Rings:** Adds depth and complexity to the visual design.
---
### Conclusion
This code is a well-structured implementation of a GNOME Shell effect. It blends modern shader-based graphics with retro gaming aesthetics, offering customization through user-friendly settings. The modular approach makes it easy to extend and maintain.
*/

0 comments on commit 1eea71e

Please sign in to comment.