Files
MusicPlayer/.vibe/skills/godot-gdscript-style-guide/Skill.md
T
Sansan acd8d65b95
Build / build (push) Successful in 1m6s
Publish / build (push) Failing after 1m16s
#29 Small fixes
2026-05-15 10:52:26 +02:00

49 lines
2.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
When writing or reviewing GDScript code, strictly follow the official Godot Engine GDScript style guide and file naming conventions:
---
### **Code Formatting**
1. **Indentation**: Use **4 spaces** (no tabs).
2. **Line Length**: Keep lines under **100 characters** where possible.
3. **Naming Conventions**:
- **Variables/functions**: `snake_case` (e.g., `player_health`, `calculate_damage()`).
- **Constants**: `UPPER_SNAKE_CASE` (e.g., `MAX_SPEED = 100`).
- **Class Names**: `PascalCase` (e.g., `class_name Player.gd`).
- **Signals**: `snake_case` (e.g., `signal player_died`).
4. **Spacing**:
- Add spaces around operators (`x = y + z`, not `x=y+z`).
- No space after `(` or before `)` in function calls (e.g., `func(a, b)`).
5. **Braces**: Open braces on the same line for `if`, `for`, `func`, etc.:
```gdscript
if x > 0:
print("Positive")
```
6. **Docstrings**: Use **Godots built-in docstring format** for functions:
```gdscript
## Calculates the player's speed based on input.
## @param delta: Time since last frame (float).
## @return: The adjusted speed (float).
func calculate_speed(delta: float) -> float:
return base_speed * delta
```
7. **Type Hints**: Always include type hints for parameters and return values (Godot 4+).
8. **Avoid Redundancy**: Omit redundant `self.` unless required for clarity.
---
### **File Naming Conventions**
1. **Script Files**:
- Use **`snake_case`** for `.gd` files (e.g., `player.gd`, `enemy_ai.gd`).
- Match the filename to the **class name** (if the script defines a class).
Example: If the class is `Player`, the file should be `player.gd`.
2. **Scene Files**:
- Use **`PascalCase`** for `.tscn` files (e.g., `Player.tscn`, `MainMenu.tscn`).
- Match the filename to the **root node** of the scene.
3. **Resource Files**:
- Use **`snake_case`** for `.tres` or `.res` files (e.g., `player_stats.tres`).
4. **Folders**:
- Use **`snake_case`** for directories (e.g., `scripts/`, `assets/sprites/`).
- Group related files logically (e.g., `player/` for `player.gd`, `player.tscn`).
---
**Reference**: [Godot GDScript Style Guide](https://docs.godotengine.org/en/stable/getting_started/scripting/gdscript/gdscript_styleguide.html).