Improve code style (#1021)

* Remove unnecessary use of `self`
* Connect to signals directly over `connect("name")`
* Use `call_deferred` on callables over `call_deferred("name"))`
* Emit signals directly over `emit_signal("name"...)`
This commit is contained in:
A Thousand Ships
2024-03-25 17:06:52 +01:00
committed by GitHub
parent 523c7d34c0
commit 82913393a8
70 changed files with 211 additions and 211 deletions

View File

@@ -32,7 +32,7 @@ func _physics_process(_delta):
if _wait_physics_ticks_counter > 0:
_wait_physics_ticks_counter -= 1
if _wait_physics_ticks_counter == 0:
emit_signal("wait_done")
wait_done.emit()
func add_line(pos_start, pos_end, color):
@@ -111,7 +111,7 @@ func start_timer(timeout):
_timer = Timer.new()
_timer.one_shot = true
add_child(_timer)
_timer.timeout.connect(self._on_timer_done)
_timer.timeout.connect(_on_timer_done)
else:
cancel_timer()
@@ -124,7 +124,7 @@ func start_timer(timeout):
func cancel_timer():
if _timer_started:
_timer.paused = true
_timer.emit_signal("timeout")
_timer.timeout.emit()
_timer.paused = false

View File

@@ -44,8 +44,8 @@ var _moving_body: PhysicsBody2D = null
func _ready():
options.option_selected.connect(self._on_option_selected)
options.option_changed.connect(self._on_option_changed)
options.option_selected.connect(_on_option_selected)
options.option_changed.connect(_on_option_changed)
_character_body_template = find_child("CharacterBody2D")
if _character_body_template:

View File

@@ -42,8 +42,8 @@ func _ready():
options.add_menu_item(OPTION_SHAPE_CONCAVE_POLYGON, true, true)
options.add_menu_item(OPTION_SHAPE_CONCAVE_SEGMENTS, true, true)
options.option_selected.connect(self._on_option_selected)
options.option_changed.connect(self._on_option_changed)
options.option_selected.connect(_on_option_selected)
options.option_changed.connect(_on_option_changed)
await start_timer(0.5).timeout
if is_timer_canceled():

View File

@@ -43,8 +43,8 @@ func _ready():
options.add_menu_item(OPTION_TEST_CASE_DESTROY_BODY, true, false)
options.add_menu_item(OPTION_TEST_CASE_CHANGE_POSITIONS, true, false)
options.connect(&"option_selected", Callable(self, "_on_option_selected"))
options.connect(&"option_changed", Callable(self, "_on_option_changed"))
options.option_selected.connect(_on_option_selected)
options.option_changed.connect(_on_option_changed)
_selected_joint = _joint_types.values()[0]
_update_joint = true

View File

@@ -81,15 +81,15 @@ func _ready():
options.add_menu_item(OPTION_TEST_CASE_MOVING_PLATFORM_RIGID)
options.add_menu_item(OPTION_TEST_CASE_MOVING_PLATFORM_CHARACTER)
options.option_selected.connect(self._on_option_selected)
options.option_selected.connect(_on_option_selected)
$Controls/PlatformSize/HSlider.value = _platform_size
$Controls/PlatformAngle/HSlider.value = _platform_angle
$Controls/BodyAngle/HSlider.value = _body_angle
remove_child(_target_area)
_target_area.body_entered.connect(self._on_target_entered)
$Timer.timeout.connect(self._on_timeout)
_target_area.body_entered.connect(_on_target_entered)
$Timer.timeout.connect(_on_timeout)
_rigid_body_template = $RigidBody2D
remove_child(_rigid_body_template)
@@ -236,13 +236,13 @@ func _start_test_case(option):
await _on_option_selected(option)
await self.all_tests_done
await all_tests_done
func _wait_for_test():
await _reset_test()
await self.test_done
await test_done
func _test_all_rigid_body():
@@ -331,7 +331,7 @@ func _test_moving_platform():
return
_platform_speed = 0.0
emit_signal("all_tests_done")
all_tests_done.emit()
func _test_all():
@@ -373,7 +373,7 @@ func _start_test():
test_label += String(_rigid_body_template.name)
_moving_body = _rigid_body_template.duplicate()
_moving_body.linear_velocity = _body_velocity
_moving_body.body_entered.connect(self._on_contact_detected)
_moving_body.body_entered.connect(_on_contact_detected)
add_child(_moving_body)
if _platform_speed != 0.0:
@@ -411,7 +411,7 @@ func _reset_test(cancel_test = true):
if cancel_test:
Log.print_log("*** Stop around the clock tests")
_test_all_angles = false
emit_signal("all_tests_done")
all_tests_done.emit()
else:
Log.print_log("*** Start around the clock tests")
_platform_body.rotation = deg_to_rad(_platform_angle)
@@ -487,8 +487,8 @@ func _on_timeout():
$Timer.stop()
if _test_canceled:
emit_signal("test_done")
emit_signal("all_tests_done")
test_done.emit()
all_tests_done.emit()
return
if not _contact_detected and not _target_entered:
@@ -497,18 +497,18 @@ func _on_timeout():
await start_timer(0.5).timeout
if _test_canceled:
emit_signal("test_done")
emit_signal("all_tests_done")
test_done.emit()
all_tests_done.emit()
return
var was_all_angles = _test_all_angles
_next_test()
emit_signal("test_done")
test_done.emit()
if was_all_angles and not _test_all_angles:
emit_signal("all_tests_done")
all_tests_done.emit()
func _set_result():

View File

@@ -12,7 +12,7 @@ func _ready():
options.add_menu_item(OPTION_TEST_CASE_HIT_FROM_INSIDE, true, false)
options.option_changed.connect(self._on_option_changed)
options.option_changed.connect(_on_option_changed)
await start_timer(0.5).timeout
if is_timer_canceled():

View File

@@ -39,7 +39,7 @@ func _ready():
options.add_menu_item(OPTION_TYPE_CAPSULE)
options.add_menu_item(OPTION_TYPE_CONVEX_POLYGON)
options.add_menu_item(OPTION_TYPE_CONCAVE_POLYGON)
options.option_selected.connect(self._on_option_selected)
options.option_selected.connect(_on_option_selected)
await _start_all_types()

View File

@@ -13,7 +13,7 @@ var _current_test_scene: Node = null
func _ready():
option_selected.connect(self._on_option_selected)
option_selected.connect(_on_option_selected)
func _process(_delta):

View File

@@ -7,7 +7,7 @@ var _entry_template
func _enter_tree():
Log.entry_logged.connect(self._on_log_entry)
Log.entry_logged.connect(_on_log_entry)
_entry_template = get_child(0) as Label
remove_child(_entry_template)

View File

@@ -62,10 +62,10 @@ func _on_item_pressed(item_index, popup_menu, path):
for other_index in range(popup_menu.get_item_count()):
if other_index != item_index:
popup_menu.set_item_checked(other_index, false)
emit_signal("option_selected", item_path)
option_selected.emit(item_path)
elif popup_menu.is_item_checkable(item_index):
var checked = not popup_menu.is_item_checked(item_index)
popup_menu.set_item_checked(item_index, checked)
emit_signal("option_changed", item_path, checked)
option_changed.emit(item_path, checked)
else:
emit_signal("option_selected", item_path)
option_selected.emit(item_path)

View File

@@ -6,7 +6,7 @@ extends ScrollContainer
func _ready():
var scrollbar = get_v_scroll_bar()
scrollbar.scrolling.connect(self._on_scrolling)
scrollbar.scrolling.connect(_on_scrolling)
func _process(_delta):

View File

@@ -11,10 +11,10 @@ signal entry_logged(message, type)
func print_log(message):
print(message)
emit_signal("entry_logged", message, LogType.LOG)
entry_logged.emit(message, LogType.LOG)
func print_error(message):
push_error(message)
printerr(message)
emit_signal("entry_logged", message, LogType.ERROR)
entry_logged.emit(message, LogType.ERROR)