Skip to content

Commit

Permalink
Merge pull request #68 from miketvo/refactor/47-signals-syntax
Browse files Browse the repository at this point in the history
Refactor Object.connect() to Signal.connect() where applicable
  • Loading branch information
miketvo authored Oct 6, 2024
2 parents 4216176 + dc13bf6 commit 89dba57
Show file tree
Hide file tree
Showing 32 changed files with 109 additions and 109 deletions.
2 changes: 1 addition & 1 deletion p0ng/scripts/characters/paddle/ai_paddle/idle_state.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var _is_ready: bool
# ============================================================================ #
#region Godot builtins
func _ready() -> void:
_cooldown_timer.connect("timeout", _on_cooldown_timer_timeout)
_cooldown_timer.timeout.connect(_on_cooldown_timer_timeout)
#endregion
# ============================================================================ #

Expand Down
2 changes: 1 addition & 1 deletion p0ng/scripts/core/state_machine/state_matchine.gd
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func _ready() -> void:
var children: Array[Node] = get_children()
for child in children:
if child is State:
child.connect("transitioned", _on_child_state_transitioned)
child.transitioned.connect(_on_child_state_transitioned)
_states[child.name.to_lower()] = child
if _states.is_empty():
print_debug("State machine has no states")
Expand Down
2 changes: 1 addition & 1 deletion p0ng/scripts/main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func _process(_delta: float) -> void:
_current_scene = load(GameScene2D.GAME_SCENE[_current_scene_key]).instantiate()
add_child(_current_scene)
move_child(_current_scene, 0)
_current_scene.connect("scene_finished", _on_scene_finished)
_current_scene.scene_finished.connect(_on_scene_finished)
#endregion
# ============================================================================ #

Expand Down
12 changes: 6 additions & 6 deletions p0ng/scripts/scenes/game/game.gd
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var _game_point_state: int
#region Godot builtins
func _ready() -> void:
_game_mode = Global.current_game_mode
_game_ui.connect("acted", _on_game_ui_acted)
_game_ui.acted.connect(_on_game_ui_acted)
_spawn_paddes()
_configure_world()
_configure_game()
Expand Down Expand Up @@ -213,8 +213,8 @@ func _spawn_paddes() -> void:
func _spawn_ball() -> void:
ball = Ball.instantiate()
ball.position = _ball_spawn.position
ball.connect("body_entered", _on_ball_body_entered)
ball.connect("body_exited", _on_ball_body_exited)
ball.body_entered.connect(_on_ball_body_entered)
ball.body_exited.connect(_on_ball_body_exited)
_current_ball_speed = Global.BALL_SPEED_INITIAL
_round_started = false
add_child(ball)
Expand Down Expand Up @@ -256,9 +256,9 @@ func _despawn_ball() -> void:


func _configure_world() -> void:
$World/LeftBound.connect("body_entered", _on_left_bound_body_entered)
$World/RightBound.connect("body_entered", _on_right_bound_body_entered)
$World/VerticalSeparator.connect("body_entered", _on_vertical_separator_body_entered)
$World/LeftBound.body_entered.connect(_on_left_bound_body_entered)
$World/RightBound.body_entered.connect(_on_right_bound_body_entered)
$World/VerticalSeparator.body_entered.connect(_on_vertical_separator_body_entered)


func _configure_game() -> void:
Expand Down
4 changes: 2 additions & 2 deletions p0ng/scripts/scenes/game/game_ui.gd
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ func _ready() -> void:

for child in get_tree().get_nodes_in_group("ui_container_slider_buttons"):
assert(child is Button, "ui_container_slider_buttons group must contain only Buttons")
child.connect("pressed", _on_ui_container_slider_button_pressed)
child.pressed.connect(_on_ui_container_slider_button_pressed)
for child in get_tree().get_nodes_in_group("ui_scene_changer_buttons"):
assert(child is Button, "ui_scene_changer_buttons group must contain only Buttons")
child.connect("pressed", _on_ui_scene_changer_button_pressed)
child.pressed.connect(_on_ui_scene_changer_button_pressed)

_endgame_dialog.modulate = Color(1.0, 1.0, 1.0, 0.0)
_endgame_dialog.visible = false
Expand Down
14 changes: 7 additions & 7 deletions p0ng/scripts/scenes/game/side_select.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ extends GameScene2D
# ============================================================================ #
#region Godot builtins
func _ready() -> void:
_ui_back_button.connect("pressed", _on_back_button_pressed)
_ui_left_button.connect("mouse_entered", _on_focused_left_side)
_ui_left_button.connect("focus_entered", _on_focused_left_side)
_ui_left_button.connect("pressed", _on_selected_left_side)
_ui_right_button.connect("mouse_entered", _on_focused_right_side)
_ui_right_button.connect("focus_entered", _on_focused_right_side)
_ui_right_button.connect("pressed", _on_selected_right_side)
_ui_back_button.pressed.connect(_on_back_button_pressed)
_ui_left_button.mouse_entered.connect(_on_focused_left_side)
_ui_left_button.focus_entered.connect(_on_focused_left_side)
_ui_left_button.pressed.connect(_on_selected_left_side)
_ui_right_button.mouse_entered.connect(_on_focused_right_side)
_ui_right_button.focus_entered.connect(_on_focused_right_side)
_ui_right_button.pressed.connect(_on_selected_right_side)
_ui_left_button.grab_focus()
#endregion
# ============================================================================ #
Expand Down
2 changes: 1 addition & 1 deletion p0ng/scripts/scenes/game/side_select_ui.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ extends UI
func _ready() -> void:
for child in get_tree().get_nodes_in_group("ui_scene_changer_buttons"):
assert(child is Button, "ui_scene_changer_buttons group must contain only Buttons")
child.connect("pressed", _on_ui_scene_changer_button_pressed)
child.pressed.connect(_on_ui_scene_changer_button_pressed)
#endregion
# ============================================================================ #
8 changes: 4 additions & 4 deletions p0ng/scripts/scenes/main_menu/game_title.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ var _rng: RandomNumberGenerator = RandomNumberGenerator.new()
# ============================================================================ #
#region Godot builtins
func _ready() -> void:
$Walls/TopWall.connect("body_entered", _on_top_wall_body_entered)
$Walls/LeftWall.connect("body_entered", _on_left_wall_body_entered)
$Walls/BottomWall.connect("body_entered", _on_bottom_wall_body_entered)
$Walls/RightWall.connect("body_entered", _on_right_wall_body_entered)
$Walls/TopWall.body_entered.connect(_on_top_wall_body_entered)
$Walls/LeftWall.body_entered.connect(_on_left_wall_body_entered)
$Walls/BottomWall.body_entered.connect(_on_bottom_wall_body_entered)
$Walls/RightWall.body_entered.connect(_on_right_wall_body_entered)

var ball_speed = _rng.randf_range(60.0, 60.0)
var ball_velocity = Vector2.RIGHT * ball_speed
Expand Down
2 changes: 1 addition & 1 deletion p0ng/scripts/scenes/main_menu/main_menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ extends GameScene2D
# ============================================================================ #
#region Godot builtins
func _ready() -> void:
$UI/MainMenuUI.connect("acted", _on_main_menu_ui_acted)
$UI/MainMenuUI.acted.connect(_on_main_menu_ui_acted)
#endregion
# ============================================================================ #

Expand Down
14 changes: 7 additions & 7 deletions p0ng/scripts/scenes/main_menu/main_menu_ui.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ extends UI
func _ready() -> void:
%GameVersionLabel.text += ProjectSettings.get_setting("application/config/version")
%StartButton.grab_focus()
%StartButton.connect("pressed", _on_main_menu_start_button_pressed)
%StartButton.pressed.connect(_on_main_menu_start_button_pressed)
if Global.os_platform in [ "Mobile", "Web" ]:
UI.deactivate_control(%QuitButton)
else:
%QuitButton.connect("pressed", _on_main_menu_quit_button_pressed)
%SettingsButton.connect("pressed", _on_main_menu_settings_button_pressed)
%OnePlayerButton.connect("pressed", _on_start_menu_one_player_button_pressed)
%TwoPlayersButton.connect("pressed", _on_start_menu_two_players_button_pressed)
%QuitButton.pressed.connect(_on_main_menu_quit_button_pressed)
%SettingsButton.pressed.connect(_on_main_menu_settings_button_pressed)
%OnePlayerButton.pressed.connect(_on_start_menu_one_player_button_pressed)
%TwoPlayersButton.pressed.connect(_on_start_menu_two_players_button_pressed)
_start_menu.get_node("BackButton").connect("pressed", _on_start_menu_back_button_pressed)

for child in get_tree().get_nodes_in_group("ui_container_slider_buttons"):
assert(child is Button, "ui_container_slider_buttons group must contain only Buttons")
child.connect("pressed", _on_ui_container_slider_button_pressed)
child.pressed.connect(_on_ui_container_slider_button_pressed)
for child in get_tree().get_nodes_in_group("ui_scene_changer_buttons"):
assert(child is Button, "ui_scene_changer_buttons group must contain only Buttons")
child.connect("pressed", _on_ui_scene_changer_button_pressed)
child.pressed.connect(_on_ui_scene_changer_button_pressed)


func _process(_delta: float) -> void:
Expand Down
4 changes: 2 additions & 2 deletions p0ng/scripts/scenes/settings_menu/resolution_popup.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var resolution_option_items: Array = Array()
func _ready() -> void:
visible = false
if Global.os_platform == "Desktop":
option_button.connect("pressed", _on_option_button_pressed)
option_button.pressed.connect(_on_option_button_pressed)

var resolution_popup_button_group: ButtonGroup = ButtonGroup.new()
var resolution_popup_container: Container = $ScrollContainer/VBoxContainer
Expand All @@ -31,7 +31,7 @@ func _ready() -> void:
resolution_key,
resolution_popup_button_group
)
resolution_option_item.connect("selected", _on_resolution_option_item_selected)
resolution_option_item.selected.connect(_on_resolution_option_item_selected)
resolution_option_item.add_to_group("ui_accepted_buttons")
resolution_popup_container.add_child(resolution_option_item)

Expand Down
4 changes: 2 additions & 2 deletions p0ng/scripts/scenes/settings_menu/settings_menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ extends GameScene2D
#region Godot builtins
func _ready() -> void:
_ui_load_config()
_ui.connect("acted", _on_main_menu_ui_acted)
_ui.connect("acted_with_data", _on_main_menu_ui_acted_with_data)
_ui.acted.connect(_on_main_menu_ui_acted)
_ui.acted_with_data.connect(_on_main_menu_ui_acted_with_data)
#endregion
# ============================================================================ #

Expand Down
26 changes: 13 additions & 13 deletions p0ng/scripts/scenes/settings_menu/settings_menu_ui.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func _ready() -> void:
_main.get_node("SoundsButton").connect("pressed", _on_main_sounds_button_pressed)
_main.get_node("ResetButton").connect("pressed", _on_main_reset_button_pressed)
if Global.os_platform == "Desktop":
_resolution_popup.connect("resolution_selected", _on_resolution_popup_resolution_selected)
_resolution_popup.resolution_selected.connect(_on_resolution_popup_resolution_selected)
_graphics.get_node("Fullscreen/ToggleButton")\
.connect("toggled", _on_graphics_fullscreen_toggled)
_graphics.get_node("PostProcessing/ToggleButton")\
Expand Down Expand Up @@ -61,25 +61,25 @@ func _ready() -> void:

for child in get_tree().get_nodes_in_group("ui_container_slider_buttons"):
assert(child is Button, "ui_container_slider_buttons group must contain only Buttons")
child.connect("pressed", _on_ui_container_slider_button_pressed)
child.pressed.connect(_on_ui_container_slider_button_pressed)
for child in get_tree().get_nodes_in_group("ui_scene_changer_buttons"):
assert(child is Button, "ui_scene_changer_buttons group must contain only Buttons")
child.connect("pressed", _on_ui_scene_changer_button_pressed)
child.pressed.connect(_on_ui_scene_changer_button_pressed)
for child in get_tree().get_nodes_in_group("ui_selected_buttons"):
assert(child is Button, "ui_selected_buttons group must contain only Buttons")
child.connect("pressed", _on_ui_selected_button_pressed)
child.pressed.connect(_on_ui_selected_button_pressed)
for child in get_tree().get_nodes_in_group("ui_accepted_buttons"):
assert(
(child is Button) or (child is Slider),
"ui_accepted_buttons group must contain only Buttons or Slider"
)
if child is Slider:
child.connect("value_changed", _on_slider_updated)
child.value_changed.connect(_on_slider_updated)
else:
child.connect("pressed", _on_ui_accepted_button_pressed)
child.pressed.connect(_on_ui_accepted_button_pressed)
for child in get_tree().get_nodes_in_group("ui_disabled_buttons"):
assert(child is Button, "ui_disabled_buttons group must contain only Buttons")
child.connect("pressed", _on_ui_disabled_button_pressed)
child.pressed.connect(_on_ui_disabled_button_pressed)


func _process(_delta: float) -> void:
Expand Down Expand Up @@ -275,16 +275,16 @@ func _update_graphics_save_button() -> void:
graphics_save_button.disconnect("pressed", _on_ui_disabled_button_pressed)
graphics_save_button.remove_from_group("ui_disabled_buttons")
graphics_save_button.add_to_group("ui_accepted_buttons")
graphics_save_button.connect("pressed", _on_ui_accepted_button_pressed)
graphics_save_button.connect("pressed", _on_graphics_menu_save_button_pressed)
graphics_save_button.pressed.connect(_on_ui_accepted_button_pressed)
graphics_save_button.pressed.connect(_on_graphics_menu_save_button_pressed)
[ false, _, false ]:
graphics_message_label.text = ""
graphics_save_button.flat = true
if graphics_save_button.is_in_group("ui_accepted_buttons"):
graphics_save_button.disconnect("pressed", _on_ui_accepted_button_pressed)
graphics_save_button.remove_from_group("ui_accepted_buttons")
graphics_save_button.add_to_group("ui_disabled_buttons")
graphics_save_button.connect("pressed", _on_ui_disabled_button_pressed)
graphics_save_button.pressed.connect(_on_ui_disabled_button_pressed)
graphics_save_button.disconnect("pressed", _on_graphics_menu_save_button_pressed)


Expand All @@ -304,16 +304,16 @@ func _update_sounds_save_button() -> void:
sounds_save_button.disconnect("pressed", _on_ui_disabled_button_pressed)
sounds_save_button.remove_from_group("ui_disabled_buttons")
sounds_save_button.add_to_group("ui_accepted_buttons")
sounds_save_button.connect("pressed", _on_ui_accepted_button_pressed)
sounds_save_button.connect("pressed", _on_sounds_menu_save_button_pressed)
sounds_save_button.pressed.connect(_on_ui_accepted_button_pressed)
sounds_save_button.pressed.connect(_on_sounds_menu_save_button_pressed)
[ false, _, false ]:
sounds_message_label.text = ""
sounds_save_button.flat = true
if sounds_save_button.is_in_group("ui_accepted_buttons"):
sounds_save_button.disconnect("pressed", _on_ui_accepted_button_pressed)
sounds_save_button.remove_from_group("ui_accepted_buttons")
sounds_save_button.add_to_group("ui_disabled_buttons")
sounds_save_button.connect("pressed", _on_ui_disabled_button_pressed)
sounds_save_button.pressed.connect(_on_ui_disabled_button_pressed)
sounds_save_button.disconnect("pressed", _on_sounds_menu_save_button_pressed)
#endregion
# ============================================================================ #
2 changes: 1 addition & 1 deletion p0ng/scripts/scenes/software_cursor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func _ready() -> void:
Input.mouse_mode = Input.MOUSE_MODE_HIDDEN
process_mode = Node.PROCESS_MODE_ALWAYS
idle_timer.autostart = true
idle_timer.connect("timeout", _on_idle_timer_timeout)
idle_timer.timeout.connect(_on_idle_timer_timeout)


func _process(_delta: float) -> void:
Expand Down
2 changes: 1 addition & 1 deletion ssssss/scripts/core/state_machine/state_matchine.gd
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func _ready() -> void:
var children: Array[Node] = get_children()
for child in children:
if child is State:
child.connect("transitioned", _on_child_state_transitioned)
child.transitioned.connect(_on_child_state_transitioned)
_states[child.name.to_lower()] = child
if _states.is_empty():
print_debug("State machine has no states")
Expand Down
2 changes: 1 addition & 1 deletion ssssss/scripts/main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func _process(_delta: float) -> void:
_current_scene = load(GameScene2D.GAME_SCENE[_current_scene_key]).instantiate()
add_child(_current_scene)
move_child(_current_scene, 0)
_current_scene.connect("scene_finished", _on_scene_finished)
_current_scene.scene_finished.connect(_on_scene_finished)
#endregion
# ============================================================================ #

Expand Down
4 changes: 2 additions & 2 deletions ssssss/scripts/scenes/game/game_ui.gd
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ func _ready() -> void:

for child in get_tree().get_nodes_in_group("ui_container_slider_buttons"):
assert(child is Button, "ui_container_slider_buttons group must contain only Buttons")
child.connect("pressed", _on_ui_container_slider_button_pressed)
child.pressed.connect(_on_ui_container_slider_button_pressed)
for child in get_tree().get_nodes_in_group("ui_scene_changer_buttons"):
assert(child is Button, "ui_scene_changer_buttons group must contain only Buttons")
child.connect("pressed", _on_ui_scene_changer_button_pressed)
child.pressed.connect(_on_ui_scene_changer_button_pressed)

_endgame_dialog.modulate = Color(1.0, 1.0, 1.0, 0.0)
_endgame_dialog.visible = false
Expand Down
4 changes: 2 additions & 2 deletions ssssss/scripts/scenes/level_select/level_select_ui.gd
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func _on_load_succeeded() -> void:
level_select_button.toggle_mode = true
level_select_button.custom_minimum_size = Vector2(180, 0)
level_select_button.add_to_group("ui_selected_buttons")
level_select_button.connect("pressed", _on_level_select_button_pressed)
level_select_button.connect("pressed", _on_ui_selected_button_pressed)
level_select_button.pressed.connect(_on_level_select_button_pressed)
level_select_button.pressed.connect(_on_ui_selected_button_pressed)

%LevelListContainer.add_child(level_select_button)
_level_select_buttons.append(level_select_button)
Expand Down
2 changes: 1 addition & 1 deletion ssssss/scripts/scenes/main_menu/main_menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ extends GameScene2D
#region Godot builtins
func _ready() -> void:
%GameTitle/Sprite2D/AnimationPlayer.play("default")
$UI/MainMenuUI.connect("acted", _on_main_menu_ui_acted)
$UI/MainMenuUI.acted.connect(_on_main_menu_ui_acted)
#endregion
# ============================================================================ #

Expand Down
14 changes: 7 additions & 7 deletions ssssss/scripts/scenes/main_menu/main_menu_ui.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ extends UI
func _ready() -> void:
%GameVersionLabel.text += ProjectSettings.get_setting("application/config/version")
%StartButton.grab_focus()
%StartButton.connect("pressed", _on_main_menu_start_button_pressed)
%StartButton.pressed.connect(_on_main_menu_start_button_pressed)
if Global.os_platform in [ "Mobile", "Web" ]:
UI.deactivate_control(%QuitButton)
else:
%QuitButton.connect("pressed", _on_main_menu_quit_button_pressed)
%SettingsButton.connect("pressed", _on_main_menu_settings_button_pressed)
%ClassicModeButton.connect("pressed", _on_start_menu_classic_mode_button_pressed)
%ChaosModeButton.connect("pressed", _on_start_menu_chaos_mode_button_pressed)
%QuitButton.pressed.connect(_on_main_menu_quit_button_pressed)
%SettingsButton.pressed.connect(_on_main_menu_settings_button_pressed)
%ClassicModeButton.pressed.connect(_on_start_menu_classic_mode_button_pressed)
%ChaosModeButton.pressed.connect(_on_start_menu_chaos_mode_button_pressed)
_start_menu.get_node("BackButton").connect("pressed", _on_start_menu_back_button_pressed)

for child in get_tree().get_nodes_in_group("ui_container_slider_buttons"):
assert(child is Button, "ui_container_slider_buttons group must contain only Buttons")
child.connect("pressed", _on_ui_container_slider_button_pressed)
child.pressed.connect(_on_ui_container_slider_button_pressed)
for child in get_tree().get_nodes_in_group("ui_scene_changer_buttons"):
assert(child is Button, "ui_scene_changer_buttons group must contain only Buttons")
child.connect("pressed", _on_ui_scene_changer_button_pressed)
child.pressed.connect(_on_ui_scene_changer_button_pressed)


func _process(_delta: float) -> void:
Expand Down
Loading

0 comments on commit 89dba57

Please sign in to comment.