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

@@ -23,7 +23,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_sphere(pos, radius, color):
@@ -95,7 +95,7 @@ func start_timer(timeout):
_timer = Timer.new()
_timer.one_shot = true
add_child(_timer)
_timer.connect(&"timeout", Callable(self, "_on_timer_done"))
_timer.timeout.connect(_on_timer_done)
else:
cancel_timer()
@@ -108,7 +108,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

@@ -40,8 +40,8 @@ func _ready():
$Options.add_menu_item(OPTION_SHAPE_CONVEX_POLYGON, true, true)
$Options.add_menu_item(OPTION_SHAPE_CONCAVE_POLYGON, 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

@@ -42,8 +42,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

@@ -55,8 +55,8 @@ func _ready():
options.add_menu_item(OPTION_ROUGH, true, false)
options.add_menu_item(OPTION_PROCESS_PHYSICS, true, false)
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)
_shapes[SHAPE_CAPSULE] = "Capsule"
_shapes[SHAPE_BOX] = "Box"

View File

@@ -15,7 +15,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)
_material.flags_unshaded = true
_material.vertex_color_use_as_albedo = true

View File

@@ -36,7 +36,7 @@ func _ready():
options.add_menu_item(SHAPE_CONVEX)
options.add_menu_item(SHAPE_BOX)
options.option_selected.connect(self._on_option_selected)
options.option_selected.connect(_on_option_selected)
restart_scene()

View File

@@ -35,7 +35,7 @@ func _ready():
$Options.add_menu_item(OPTION_TYPE_CAPSULE)
$Options.add_menu_item(OPTION_TYPE_CYLINDER)
$Options.add_menu_item(OPTION_TYPE_CONVEX)
$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

@@ -8,7 +8,7 @@ var _rotation_pivot
func _ready():
call_deferred("_initialize_pivot")
_initialize_pivot.call_deferred()
func _unhandled_input(event):

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

@@ -55,6 +55,6 @@ func _on_item_pressed(item_index, popup_menu, path):
if 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

@@ -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)