Coding Style Guide¶
CONTEXT: AEROBEAT¶
- Target Engine: Godot 4.6
- Priority: Timing accuracy, signal safety, and static typing.
- Style: Godot 2.0 (GDScript 2) Standard.
This guide contains rules for .gdscript files in AeroBeat.
SYNTAX RULES (GODOT 4.x ONLY)¶
-
NO LEGACY ANNOTATIONS: Always use '@' prefix (e.g., @onready, @export, @tool, @icon). Never use 'onready var' or 'export var'.
-
SIGNAL CONNECTIVITY: Use the Callable-based syntax:
signal_name.connect(target_method). Never use the old string-based.connect("signal", self, "method"). -
INSTANTIATION: Use
.instantiate(). Never use.instance(). -
COROUTINES: Use
await. Never useyield. -
PROPERTY ACCESS: Use direct properties (e.g.,
node.name = "X") instead of setters (e.g.,node.set_name("X")) unless a setter is specifically required for logic. -
TYPED ARRAYS: Always use typed arrays for rhythm data:
var notes: Array[NoteResource] = [].
Additional Syntax Rules¶
- Typed Variables: ALWAYS use explicit types.
- ❌
var score = 0 - ✅
var score: int = 0
- ❌
- Private Methods: Prefix internal functions with
_.- ✅
func _calculate_score() -> void:
- ✅
- Inferred Types: Use
:=only for unambiguous types (Vector2, String).
Architectural Patterns¶
- Composition over Inheritance: Use components (
Nodechildren) rather than deepextendschains. - Signal Up, Call Down:
- Children emit Signals to talk to Parents.
- Parents call Functions to talk to Children.
- NEVER let a Child node access
get_parent().
AeroBeat Specifics¶
- Input: NEVER use
Input.is_action_pressed(). ALWAYS useAeroInputProvider. - Time: NEVER use
deltafor rhythm sync. ALWAYS useAudioServer.get_dsp_time().
File Structure & Organization¶
- Docstring:
##Description of the class. - Class Definition:
class_namethenextends. - Regions: Organize code in this order using
#region:SIGNALSENUMS & CONSTANTSEXPORTSPUBLIC VARIABLESPRIVATE VARIABLES(_)ONREADYLIFECYCLE(_ready,_process)PUBLIC APIPRIVATE API(_)
Documentation & Formatting¶
- Docstrings: Use
##for all classes and public functions (required for auto-docs). - Separators: Use
# ---------------------------------------------for major blocks. - Spacing: Two empty lines between functions.
Godot Syntax Rules¶
- Prefixes: All core classes must start with
Aero(e.g.,AeroSessionContext). - Extensions: Use
.gdfor logic,.tscnfor scenes,.tresfor data. - Strict Typing: All GDScript must be static typed (e.g.,
func get_name() -> String:).
ANTI-HALLUCINATION PROTOCOL¶
-
STOICISM: If you are unsure if a method exists in Godot 4.x, do not guess. State "API_UNKNOWN: [Method Name]" and ask for clarification.
-
STATIC TYPING: Every variable and function return MUST be explicitly typed (e.g.,
func _process(delta: float) -> void:). This prevents type-inference hallucinations. -
PLAN-THEN-CODE: Before writing any code, provide a 1-sentence logic plan.
- Example: "Plan: I will use a Tween to handle the hit-sprite fade to ensure it doesn't interrupt the physics thread."
ERROR HANDLING¶
If the user provides an error log, analyze it using "Step-Back" reasoning:
-
What node owns the script?
-
Is the signal connected?
-
Is the variable null?