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,53 +1,49 @@
extends RigidBody3D
const MOUSE_DELTA_COEFFICIENT = 0.01
const CAMERA_DISTANCE_COEFFICIENT = 0.2
var _picked = false
var _last_mouse_pos = Vector2.ZERO
var _mouse_pos = Vector2.ZERO
var _picked := false
var _last_mouse_pos := Vector2.ZERO
var _mouse_pos := Vector2.ZERO
func _ready():
func _ready() -> void:
input_ray_pickable = true
func _input(event):
var mouse_event = event as InputEventMouseButton
if mouse_event and not mouse_event.pressed:
if mouse_event.button_index == MOUSE_BUTTON_LEFT:
func _input(event: InputEvent) -> void:
if event is InputEventMouseButton:
if not event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
_picked = false
var mouse_motion = event as InputEventMouseMotion
if mouse_motion:
_mouse_pos = mouse_motion.position
if event is InputEventMouseMotion:
_mouse_pos = event.position
func _input_event(_viewport, event, _click_pos, _click_normal, _shape_idx):
var mouse_event = event as InputEventMouseButton
if mouse_event and mouse_event.pressed:
if mouse_event.button_index == MOUSE_BUTTON_LEFT:
func _input_event(_camera: Camera3D, event: InputEvent, _position: Vector3, _normal: Vector3, _shape_idx: int) -> void:
if event is InputEventMouseButton:
if event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
_picked = true
_mouse_pos = mouse_event.position
_mouse_pos = event.position
_last_mouse_pos = _mouse_pos
func _physics_process(delta):
func _physics_process(delta: float) -> void:
if _picked:
var mouse_delta = _mouse_pos - _last_mouse_pos
var mouse_delta := _mouse_pos - _last_mouse_pos
var world_delta := Vector3.ZERO
world_delta.x = mouse_delta.x * MOUSE_DELTA_COEFFICIENT
world_delta.y = -mouse_delta.y * MOUSE_DELTA_COEFFICIENT
var camera = get_viewport().get_camera_3d()
var camera := get_viewport().get_camera_3d()
if camera:
var camera_basis = camera.global_transform.basis
var camera_basis := camera.global_transform.basis
world_delta = camera_basis * world_delta
var camera_dist = camera.global_transform.origin.distance_to(global_transform.origin)
var fov_coefficient = camera.fov / 70.0
var camera_dist := camera.global_transform.origin.distance_to(global_transform.origin)
const DEFAULT_CAMERA_FOV = 75.0
var fov_coefficient := camera.fov / DEFAULT_CAMERA_FOV
world_delta *= CAMERA_DISTANCE_COEFFICIENT * camera_dist * fov_coefficient
if freeze: