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

File diff suppressed because one or more lines are too long

View File

@@ -1,8 +1,8 @@
extends Node3D
# Random spawn of Rigidbody cubes.
func _on_SpawnTimer_timeout():
var new_rb = preload("res://cube_rigidbody.tscn").instantiate()
func _on_SpawnTimer_timeout() -> void:
var new_rb: RigidBody3D = preload("res://cube_rigidbody.tscn").instantiate()
new_rb.position.y = 15
new_rb.position.x = randf_range(-5, 5)
new_rb.position.z = randf_range(-5, 5)

View File

@@ -107,7 +107,7 @@ data = {
environment = SubResource("Environment_jpjfl")
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(-0.766044, 0.45452, -0.454519, 0, 0.707107, 0.707107, 0.642788, 0.541675, -0.541675, 0, 5, 1)
transform = Transform3D(-0.436154, 0.776648, -0.45452, 0.353553, 0.612372, 0.707107, 0.827508, 0.14771, -0.541675, 0, 5, 1)
light_energy = 1.3
shadow_enabled = true
shadow_bias = 0.032

View File

@@ -1,10 +1,10 @@
extends RigidBody3D
@onready var shape_cast = $ShapeCast3D
@onready var camera = $Target/Camera3D
@onready var start_position = position
@onready var shape_cast: ShapeCast3D = $ShapeCast3D
@onready var camera: Camera3D = $Target/Camera3D
@onready var start_position := position
func _physics_process(_delta):
func _physics_process(_delta: float) -> void:
if Input.is_action_just_pressed(&"exit"):
get_tree().quit()
if Input.is_action_just_pressed(&"reset_position") or global_position.y < - 6:
@@ -12,13 +12,13 @@ func _physics_process(_delta):
position = start_position
linear_velocity = Vector3.ZERO
var dir = Vector3()
var dir := Vector3()
dir.x = Input.get_axis(&"move_left", &"move_right")
dir.z = Input.get_axis(&"move_forward", &"move_back")
# Get the camera's transform basis, but remove the X rotation such
# that the Y axis is up and Z is horizontal.
var cam_basis = camera.global_transform.basis
var cam_basis := camera.global_transform.basis
cam_basis = cam_basis.rotated(cam_basis.x, -cam_basis.get_euler().x)
dir = cam_basis * dir
@@ -38,11 +38,10 @@ func _physics_process(_delta):
# Test if there is a body below the player.
func on_ground():
if shape_cast.is_colliding():
return true
func on_ground() -> bool:
return shape_cast.is_colliding()
func _on_tcube_body_entered(body):
func _on_tcube_body_entered(body: Node) -> void:
if body == self:
get_node(^"WinText").show()
$WinText.visible = true

View File

@@ -1,41 +1,41 @@
extends Camera3D
var collision_exception = []
@export var min_distance = 0.5
@export var max_distance = 3.0
@export var angle_v_adjust = 0.0
var max_height = 2.0
var min_height = 0
var collision_exception := []
var max_height := 2.0
var min_height := 0
@export var min_distance := 0.5
@export var max_distance := 3.0
@export var angle_v_adjust := 0.0
@onready var target_node: Node3D = get_parent()
func _ready():
func _ready() -> void:
collision_exception.append(target_node.get_parent().get_rid())
# Detaches the camera transform from the parent spatial node
set_as_top_level(true)
# Detach the camera transform from the parent spatial node.
top_level = true
func _physics_process(_delta):
var target_pos: Vector3 = target_node.global_transform.origin
var camera_pos: Vector3 = global_transform.origin
func _physics_process(_delta: float) -> void:
var target_pos := target_node.global_transform.origin
var camera_pos := global_transform.origin
var delta_pos: Vector3 = camera_pos - target_pos
var delta_pos := camera_pos - target_pos
# Regular delta follow
# Regular delta follow.
# Check ranges
# Check ranges.
if delta_pos.length() < min_distance:
delta_pos = delta_pos.normalized() * min_distance
elif delta_pos.length() > max_distance:
delta_pos = delta_pos.normalized() * max_distance
# Check upper and lower height
# Check upper and lower height.
delta_pos.y = clamp(delta_pos.y, min_height, max_height)
camera_pos = target_pos + delta_pos
look_at_from_position(camera_pos, target_pos, Vector3.UP)
# Turn a little up or down
var t = transform
# Turn a little up or down.
var t := transform
t.basis = Basis(t.basis[0], deg_to_rad(angle_v_adjust)) * t.basis
transform = t

View File

@@ -18,6 +18,10 @@ run/main_scene="res://level.tscn"
config/features=PackedStringArray("4.2")
config/icon="res://icon.webp"
[debug]
gdscript/warnings/untyped_declaration=1
[display]
window/stretch/mode="canvas_items"