mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-06 16:00:08 +01: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:
Binary file not shown.
@@ -20,6 +20,10 @@ run/main_scene="res://material_tester.tscn"
|
||||
config/features=PackedStringArray("4.2")
|
||||
config/icon="res://icon.webp"
|
||||
|
||||
[debug]
|
||||
|
||||
gdscript/warnings/untyped_declaration=1
|
||||
|
||||
[display]
|
||||
|
||||
window/stretch/mode="canvas_items"
|
||||
|
||||
@@ -6,13 +6,13 @@ const ZOOM_SPEED = 0.1
|
||||
const ZOOM_MAX = 2.5
|
||||
const MAIN_BUTTONS = MOUSE_BUTTON_MASK_LEFT | MOUSE_BUTTON_MASK_MIDDLE | MOUSE_BUTTON_MASK_RIGHT
|
||||
|
||||
var tester_index = 0
|
||||
var rot_x = -0.5 # This must be kept in sync with RotationX.
|
||||
var rot_y = -0.5 # This must be kept in sync with CameraHolder.
|
||||
var zoom = 5
|
||||
var base_height = ProjectSettings.get_setting("display/window/size/viewport_height")
|
||||
var tester_index := 0
|
||||
var rot_x := -0.5 # This must be kept in sync with RotationX.
|
||||
var rot_y := -0.5 # This must be kept in sync with CameraHolder.
|
||||
var zoom := 5.0
|
||||
var base_height := int(ProjectSettings.get_setting("display/window/size/viewport_height"))
|
||||
|
||||
var backgrounds = [
|
||||
var backgrounds: Array[Dictionary] = [
|
||||
{ path = "res://backgrounds/schelde.hdr", name = "Riverside" },
|
||||
{ path = "res://backgrounds/lobby.hdr", name = "Lobby" },
|
||||
{ path = "res://backgrounds/park.hdr", name = "Park" },
|
||||
@@ -23,21 +23,21 @@ var backgrounds = [
|
||||
@onready var testers: Node3D = $Testers
|
||||
@onready var material_name: Label = $UI/MaterialName
|
||||
|
||||
@onready var camera_holder: Node3D = $CameraHolder # Has a position and rotates on Y.
|
||||
@onready var camera_holder: Node3D = $CameraHolder # Has a position and rotates on Y.
|
||||
@onready var rotation_x: Node3D = $CameraHolder/RotationX
|
||||
@onready var camera: Camera3D = $CameraHolder/RotationX/Camera
|
||||
|
||||
func _ready():
|
||||
func _ready() -> void:
|
||||
for background in backgrounds:
|
||||
get_node(^"UI/Background").add_item(background.name)
|
||||
|
||||
update_gui()
|
||||
|
||||
|
||||
func _unhandled_input(event):
|
||||
if event.is_action_pressed("ui_left"):
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed(&"ui_left"):
|
||||
_on_previous_pressed()
|
||||
if event.is_action_pressed("ui_right"):
|
||||
if event.is_action_pressed(&"ui_right"):
|
||||
_on_next_pressed()
|
||||
|
||||
if event is InputEventMouseButton:
|
||||
@@ -50,7 +50,7 @@ func _unhandled_input(event):
|
||||
|
||||
if event is InputEventMouseMotion and event.button_mask & MAIN_BUTTONS:
|
||||
# Compensate motion speed to be resolution-independent (based on the window height).
|
||||
var relative_motion = event.relative * DisplayServer.window_get_size().y / base_height
|
||||
var relative_motion: Vector2 = event.relative * DisplayServer.window_get_size().y / base_height
|
||||
rot_y -= relative_motion.x * ROT_SPEED
|
||||
rot_x -= relative_motion.y * ROT_SPEED
|
||||
rot_x = clamp(rot_x, -1.4, 0.45)
|
||||
@@ -58,40 +58,40 @@ func _unhandled_input(event):
|
||||
rotation_x.transform.basis = Basis.from_euler(Vector3(rot_x, 0, 0))
|
||||
|
||||
|
||||
func _process(delta):
|
||||
var current_tester = testers.get_child(tester_index)
|
||||
func _process(delta: float) -> void:
|
||||
var current_tester: Node3D = testers.get_child(tester_index)
|
||||
# This code assumes CameraHolder's Y and Z coordinates are already correct.
|
||||
var target_position = current_tester.transform.origin.x
|
||||
var current_position = camera_holder.transform.origin.x
|
||||
var target_position := current_tester.transform.origin.x
|
||||
var current_position := camera_holder.transform.origin.x
|
||||
camera_holder.transform.origin.x = lerp(current_position, target_position, INTERP_SPEED * delta)
|
||||
|
||||
|
||||
func _on_previous_pressed():
|
||||
func _on_previous_pressed() -> void:
|
||||
if tester_index > 0:
|
||||
tester_index -= 1
|
||||
|
||||
update_gui()
|
||||
|
||||
|
||||
func _on_next_pressed():
|
||||
func _on_next_pressed() -> void:
|
||||
if tester_index < testers.get_child_count() - 1:
|
||||
tester_index += 1
|
||||
|
||||
update_gui()
|
||||
|
||||
|
||||
func update_gui():
|
||||
var current_tester = testers.get_child(tester_index)
|
||||
func update_gui() -> void:
|
||||
var current_tester := testers.get_child(tester_index)
|
||||
material_name.text = current_tester.get_name()
|
||||
$UI/Previous.disabled = tester_index == 0
|
||||
$UI/Next.disabled = tester_index == testers.get_child_count() - 1
|
||||
|
||||
|
||||
func _on_bg_item_selected(index):
|
||||
func _on_bg_item_selected(index: int) -> void:
|
||||
var sky_material: PanoramaSkyMaterial = $WorldEnvironment.environment.sky.sky_material
|
||||
|
||||
sky_material.panorama = load(backgrounds[index].path)
|
||||
|
||||
|
||||
func _on_quit_pressed():
|
||||
func _on_quit_pressed() -> void:
|
||||
get_tree().quit()
|
||||
|
||||
Reference in New Issue
Block a user