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,18 +1,18 @@
[gd_scene load_steps=4 format=2]
[gd_scene load_steps=4 format=3 uid="uid://cgx884jv27maj"]
[ext_resource path="res://bowling_ball.png" type="Texture2D" id=1]
[ext_resource type="Texture2D" uid="uid://cyqshsjd3qwo0" path="res://bowling_ball.png" id="1"]
[sub_resource type="PhysicsMaterial" id=1]
[sub_resource type="PhysicsMaterial" id="1"]
bounce = 0.4
[sub_resource type="CircleShape2D" id=2]
[sub_resource type="CircleShape2D" id="2"]
radius = 30.0
[node name="Ball" type="RigidDynamicBody2D"]
physics_material_override = SubResource( 1 )
[node name="Ball" type="RigidBody2D"]
physics_material_override = SubResource("1")
[node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource( 1 )
texture = ExtResource("1")
[node name="Collision" type="CollisionShape2D" parent="."]
shape = SubResource( 2 )
shape = SubResource("2")

View File

@@ -2,15 +2,16 @@ extends Node2D
@export var ball_scene: PackedScene = preload("res://ball.tscn")
func _unhandled_input(event):
func _unhandled_input(event: InputEvent) -> void:
if event.is_echo():
return
if event is InputEventMouseButton and event.is_pressed():
if event.button_index == MOUSE_BUTTON_LEFT:
spawn(get_global_mouse_position())
func spawn(spawn_global_position):
var instance = ball_scene.instantiate()
func spawn(spawn_global_position: Vector2) -> void:
var instance: Node2D = ball_scene.instantiate()
instance.global_position = spawn_global_position
add_child(instance)

View File

@@ -18,6 +18,10 @@ run/main_scene="res://scene_instancing.tscn"
config/features=PackedStringArray("4.2")
config/icon="res://icon.webp"
[debug]
gdscript/warnings/untyped_declaration=1
[display]
window/stretch/mode="canvas_items"
@@ -25,6 +29,7 @@ window/stretch/aspect="expand"
[physics]
common/physics_ticks_per_second=120
2d/default_gravity=300
[rendering]

View File

@@ -1,7 +1,7 @@
[gd_scene load_steps=13 format=3 uid="uid://rcsr8t4nw526"]
[ext_resource type="Script" path="res://ball_factory.gd" id="1"]
[ext_resource type="PackedScene" path="res://ball.tscn" id="2"]
[ext_resource type="PackedScene" uid="uid://cgx884jv27maj" path="res://ball.tscn" id="2"]
[sub_resource type="PhysicsMaterial" id="1"]
bounce = 0.4
@@ -35,7 +35,9 @@ bounce = 0.4
[node name="SceneInstancing" type="Node2D"]
[node name="InfoLabel" type="Label" parent="."]
[node name="CanvasLayer" type="CanvasLayer" parent="."]
[node name="InfoLabel" type="Label" parent="CanvasLayer"]
offset_left = 16.0
offset_top = 16.0
offset_right = 370.0