Skip to content

Commit

Permalink
Merge pull request #9075 from skyace65/C#SignalInfo
Browse files Browse the repository at this point in the history
Unify C# naming notes and comments
  • Loading branch information
mhilbrunner committed Mar 10, 2024
2 parents 238d90a + 8916cbd commit 13ce923
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 5 deletions.
1 change: 1 addition & 0 deletions getting_started/first_2d_game/03.coding_the_player.rst
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ Next, add this code to the function:

.. code-tab:: csharp

// We also specified this function name in PascalCase in the editor's connection window.
private void OnBodyEntered(Node2D body)
{
Hide(); // Player disappears after being hit.
Expand Down
1 change: 1 addition & 0 deletions getting_started/first_2d_game/04.creating_the_enemy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ to the ``Mob`` and add this code:

.. code-tab:: csharp

// We also specified this function name in PascalCase in the editor's connection window.
private void OnVisibleOnScreenNotifier2DScreenExited()
{
QueueFree();
Expand Down
3 changes: 3 additions & 0 deletions getting_started/first_2d_game/05.the_main_game_scene.rst
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,13 @@ the other two timers. ``ScoreTimer`` will increment the score by 1.

.. code-tab:: csharp

// We also specified this function name in PascalCase in the editor's connection window.
private void OnScoreTimerTimeout()
{
_score++;
}

// We also specified this function name in PascalCase in the editor's connection window.
private void OnStartTimerTimeout()
{
GetNode<Timer>("MobTimer").Start();
Expand Down Expand Up @@ -219,6 +221,7 @@ Note that a new instance must be added to the scene using ``add_child()``.

.. code-tab:: csharp

// We also specified this function name in PascalCase in the editor's connection window.
private void OnMobTimerTimeout()
{
// Note: Normally it is best to use explicit types rather than the `var`
Expand Down
2 changes: 2 additions & 0 deletions getting_started/first_2d_game/06.heads_up_display.rst
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,14 @@ signal of ``MessageTimer``, and add the following code to the new functions:

.. code-tab:: csharp

// We also specified this function name in PascalCase in the editor's connection window.
private void OnStartButtonPressed()
{
GetNode<Button>("StartButton").Hide();
EmitSignal(SignalName.StartGame);
}

// We also specified this function name in PascalCase in the editor's connection window.
private void OnMessageTimerTimeout()
{
GetNode<Label>("Message").Hide();
Expand Down
11 changes: 11 additions & 0 deletions getting_started/first_3d_game/03.player_movement_code.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ Moving the player with code
It's time to code! We're going to use the input actions we created in the last
part to move the character.

.. note:: For this project, we will be following the Godot naming conventions.

- **GDScript**: Classes (nodes) use PascalCase, variables and
functions use snake_case, and constants use ALL_CAPS (See
:ref:`doc_gdscript_styleguide`).

- **C#**: Classes, export variables and methods use PascalCase,
private fields use _camelCase, local variables and parameters use
camelCase (See :ref:`doc_c_sharp_styleguide`). Be careful to type
the method names precisely when connecting signals.

Right-click the ``Player`` node and select *Attach Script* to add a new script to
it. In the popup, set the *Template* to *Empty* before pressing the *Create*
button. We set it to *Empty* because we want to write our own code for
Expand Down
4 changes: 2 additions & 2 deletions getting_started/first_3d_game/04.mob_scene.rst
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ method. This function destroys the instance it's called on.

.. code-tab:: csharp

// We also specified this function name in PascalCase in the editor's connection window
// We also specified this function name in PascalCase in the editor's connection window.
private void OnVisibilityNotifierScreenExited()
{
QueueFree();
Expand Down Expand Up @@ -321,7 +321,7 @@ Here is the complete ``Mob.gd`` script for reference.
Velocity = Velocity.Rotated(Vector3.Up, Rotation.Y);
}

// We also specified this function name in PascalCase in the editor's connection window
// We also specified this function name in PascalCase in the editor's connection window.
private void OnVisibilityNotifierScreenExited()
{
QueueFree();
Expand Down
2 changes: 1 addition & 1 deletion getting_started/first_3d_game/05.spawning_mobs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ Let's code the mob spawning logic. We're going to:

.. code-tab:: csharp

// We also specified this function name in PascalCase in the editor's connection window
// We also specified this function name in PascalCase in the editor's connection window.
private void OnMobTimerTimeout()
{
// Create a new instance of the Mob scene.
Expand Down
4 changes: 2 additions & 2 deletions getting_started/first_3d_game/07.killing_player.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ a ``die()`` function that helps us put a descriptive label on the code.
QueueFree();
}

// We also specified this function name in PascalCase in the editor's connection window
// We also specified this function name in PascalCase in the editor's connection window.
private void OnMobDetectorBodyEntered(Node3D body)
{
Die();
Expand Down Expand Up @@ -122,7 +122,7 @@ Get the timer, and stop it, in the ``_on_player_hit()`` function.

.. code-tab:: csharp

// We also specified this function name in PascalCase in the editor's connection window
// We also specified this function name in PascalCase in the editor's connection window.
private void OnPlayerHit()
{
GetNode<Timer>("MobTimer").Stop();
Expand Down
14 changes: 14 additions & 0 deletions getting_started/step_by_step/signals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ the bar to reflect the change. To do so, in Godot, you would use signals.
We will now use a signal to make our Godot icon from the previous lesson
(:ref:`doc_scripting_player_input`) move and stop by pressing a button.

.. note:: For this project, we will be following the Godot naming conventions.

- **GDScript**: Classes (nodes) use PascalCase, variables and
functions use snake_case, and constants use ALL_CAPS (See
:ref:`doc_gdscript_styleguide`).

- **C#**: Classes, export variables and methods use PascalCase,
private fields use _camelCase, local variables and parameters use
camelCase (See :ref:`doc_c_sharp_styleguide`). Be careful to type
the method names precisely when connecting signals.

.. Example
Scene setup
Expand Down Expand Up @@ -156,6 +167,7 @@ the ``not`` keyword to invert the value.

.. code-tab:: csharp C#

// We also specified this function name in PascalCase in the editor's connection window.
private void OnButtonPressed()
{
SetProcess(!IsProcessing());
Expand Down Expand Up @@ -221,6 +233,7 @@ Your complete ``sprite_2d.gd`` code should look like the following.
Position += velocity * (float)delta;
}

// We also specified this function name in PascalCase in the editor's connection window.
private void OnButtonPressed()
{
SetProcess(!IsProcessing());
Expand Down Expand Up @@ -393,6 +406,7 @@ Here is the complete ``sprite_2d.gd`` file for reference.
Position += velocity * (float)delta;
}

// We also specified this function name in PascalCase in the editor's connection window.
private void OnButtonPressed()
{
SetProcess(!IsProcessing());
Expand Down

0 comments on commit 13ce923

Please sign in to comment.