Use static typing in all demos (#1063)

This leads to code that is easier to understand and runs
faster thanks to GDScript's typed instructions.

The untyped declaration warning is now enabled on all projects
where type hints were added. All projects currently run without
any untyped declration warnings.

Dodge the Creeps and Squash the Creeps demos intentionally don't
use type hints to match the documentation, where type hints haven't
been adopted yet (given its beginner focus).
This commit is contained in:
Hugo Locurcio
2024-06-01 12:12:18 +02:00
committed by GitHub
parent 8e9c180278
commit bac1e69164
498 changed files with 5218 additions and 4776 deletions

View File

@@ -1,6 +1,5 @@
extends TestCharacter
const OPTION_TEST_CASE_ALL = "Test Cases/TEST ALL (0)"
const OPTION_TEST_CASE_JUMP_ONE_WAY_RIGID = "Test Cases/Jump through one-way tiles (Rigid Body)"
const OPTION_TEST_CASE_JUMP_ONE_WAY_CHARACTER = "Test Cases/Jump through one-way tiles (Character Body)"
@@ -8,16 +7,15 @@ const OPTION_TEST_CASE_JUMP_ONE_WAY_CORNER_RIGID = "Test Cases/Jump through one-
const OPTION_TEST_CASE_JUMP_ONE_WAY_CORNER_CHARACTER = "Test Cases/Jump through one-way corner (Character Body)"
const OPTION_TEST_CASE_FALL_ONE_WAY_CHARACTER = "Test Cases/Fall and pushed on one-way tiles (Character Body)"
var _test_jump_one_way = false
var _test_jump_one_way_corner = false
var _test_fall_one_way = false
var _test_jump_one_way := false
var _test_jump_one_way_corner := false
var _test_fall_one_way := false
var _extra_body: PhysicsBody2D = null
var _failed_reason = ""
var _failed_reason := ""
func _ready():
func _ready() -> void:
super._ready()
options.add_menu_item(OPTION_TEST_CASE_ALL)
@@ -28,16 +26,15 @@ func _ready():
options.add_menu_item(OPTION_TEST_CASE_FALL_ONE_WAY_CHARACTER)
func _input(event):
func _input(event: InputEvent) -> void:
super._input(event)
var key_event = event as InputEventKey
if key_event and not key_event.pressed:
if key_event.keycode == KEY_0:
if event is InputEventKey and not event.pressed:
if event.keycode == KEY_0:
await _on_option_selected(OPTION_TEST_CASE_ALL)
func _on_option_selected(option):
func _on_option_selected(option: String) -> void:
match option:
OPTION_TEST_CASE_ALL:
await _test_all()
@@ -60,34 +57,34 @@ func _on_option_selected(option):
super._on_option_selected(option)
func _start_test_case(option):
func _start_test_case(option: String) -> void:
Log.print_log("* Starting " + option)
match option:
OPTION_TEST_CASE_JUMP_ONE_WAY_RIGID:
_body_type = E_BodyType.RIGID_BODY
_body_type = BodyType.RIGID_BODY
_test_jump_one_way_corner = false
await _start_jump_one_way()
OPTION_TEST_CASE_JUMP_ONE_WAY_CHARACTER:
_body_type = E_BodyType.CHARACTER_BODY
_body_type = BodyType.CHARACTER_BODY
_test_jump_one_way_corner = false
await _start_jump_one_way()
OPTION_TEST_CASE_JUMP_ONE_WAY_CORNER_RIGID:
_body_type = E_BodyType.RIGID_BODY
_body_type = BodyType.RIGID_BODY
_test_jump_one_way_corner = true
await _start_jump_one_way()
OPTION_TEST_CASE_JUMP_ONE_WAY_CORNER_CHARACTER:
_body_type = E_BodyType.CHARACTER_BODY
_body_type = BodyType.CHARACTER_BODY
_test_jump_one_way_corner = true
await _start_jump_one_way()
OPTION_TEST_CASE_FALL_ONE_WAY_CHARACTER:
_body_type = E_BodyType.CHARACTER_BODY
_body_type = BodyType.CHARACTER_BODY
await _start_fall_one_way()
_:
Log.print_error("Invalid test case.")
func _test_all():
func _test_all() -> void:
Log.print_log("* TESTING ALL...")
# RigidBody tests.
@@ -115,8 +112,8 @@ func _test_all():
Log.print_log("* Done.")
func _set_result(test_passed):
var result = ""
func _set_result(test_passed: bool) -> void:
var result := ""
if test_passed:
result = "PASSED"
else:
@@ -130,7 +127,7 @@ func _set_result(test_passed):
Log.print_log("Test %s" % result)
func _start_test():
func _start_test() -> void:
if _extra_body:
_body_parent.remove_child(_extra_body)
_extra_body.queue_free()
@@ -167,7 +164,7 @@ func _start_test():
$FallTargetArea2D/CollisionShape2D.disabled = false
func _start_jump_one_way():
func _start_jump_one_way() -> void:
_test_jump_one_way = true
_start_test()
@@ -178,7 +175,7 @@ func _start_jump_one_way():
_finalize_jump_one_way()
func _start_fall_one_way():
func _start_fall_one_way() -> void:
_test_fall_one_way = true
_start_test()
@@ -189,8 +186,8 @@ func _start_fall_one_way():
_finalize_fall_one_way()
func _finalize_jump_one_way():
var passed = true
func _finalize_jump_one_way() -> void:
var passed := true
if not $JumpTargetArea2D.overlaps_body(_moving_body):
passed = false
_failed_reason = ": the body wasn't able to jump all the way through."
@@ -201,8 +198,8 @@ func _finalize_jump_one_way():
$JumpTargetArea2D/CollisionShape2D.disabled = true
func _finalize_fall_one_way():
var passed = true
func _finalize_fall_one_way() -> void:
var passed := true
if $FallTargetArea2D.overlaps_body(_moving_body):
passed = false
_failed_reason = ": the body was pushed through the one-way collision."