mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-06 14:10:55 +03:00
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:
@@ -1,35 +1,32 @@
|
||||
extends Camera3D
|
||||
|
||||
|
||||
const ROTATION_COEFF = 0.02
|
||||
|
||||
var _rotation_enabled = false
|
||||
var _rotation_pivot
|
||||
var _rotation_enabled := false
|
||||
var _rotation_pivot: Node3D
|
||||
|
||||
|
||||
func _ready():
|
||||
func _ready() -> void:
|
||||
_initialize_pivot.call_deferred()
|
||||
|
||||
|
||||
func _unhandled_input(event):
|
||||
var mouse_button_event = event as InputEventMouseButton
|
||||
if mouse_button_event:
|
||||
if mouse_button_event.button_index == MOUSE_BUTTON_RIGHT:
|
||||
_rotation_enabled = mouse_button_event.pressed
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseButton:
|
||||
if event.button_index == MOUSE_BUTTON_RIGHT:
|
||||
_rotation_enabled = event.pressed
|
||||
|
||||
return
|
||||
|
||||
if not _rotation_enabled:
|
||||
return
|
||||
|
||||
var mouse_motion_event = event as InputEventMouseMotion
|
||||
if mouse_motion_event:
|
||||
var rotation_delta = mouse_motion_event.relative.x
|
||||
if event is InputEventMouseMotion:
|
||||
var rotation_delta: float = event.relative.x
|
||||
_rotation_pivot.rotate(Vector3.UP, -rotation_delta * ROTATION_COEFF)
|
||||
|
||||
|
||||
func _initialize_pivot():
|
||||
func _initialize_pivot() -> void:
|
||||
_rotation_pivot = Node3D.new()
|
||||
var camera_parent = get_parent()
|
||||
var camera_parent := get_parent()
|
||||
camera_parent.add_child(_rotation_pivot)
|
||||
camera_parent.remove_child(self)
|
||||
_rotation_pivot.add_child(self)
|
||||
|
||||
Reference in New Issue
Block a user