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,6 +1,5 @@
extends Node2D
const VU_COUNT = 16
const FREQ_MAX = 11050.0
@@ -10,14 +9,14 @@ const HEIGHT_SCALE = 8.0
const MIN_DB = 60
const ANIMATION_SPEED = 0.1
var spectrum
var min_values = []
var max_values = []
var spectrum: AudioEffectSpectrumAnalyzerInstance
var min_values: Array[float] = []
var max_values: Array[float] = []
func _draw():
var w = WIDTH / VU_COUNT
for i in range(VU_COUNT):
func _draw() -> void:
@warning_ignore("integer_division")
var w := WIDTH / VU_COUNT
for i in VU_COUNT:
var min_height = min_values[i]
var max_height = max_values[i]
var height = lerp(min_height, max_height, ANIMATION_SPEED)
@@ -48,32 +47,32 @@ func _draw():
)
func _process(_delta):
var data = []
var prev_hz = 0
func _process(_delta: float) -> void:
var data: Array[float] = []
var prev_hz := 0.0
for i in range(1, VU_COUNT + 1):
var hz = i * FREQ_MAX / VU_COUNT
var magnitude = spectrum.get_magnitude_for_frequency_range(prev_hz, hz).length()
var energy = clampf((MIN_DB + linear_to_db(magnitude)) / MIN_DB, 0, 1)
var height = energy * HEIGHT * HEIGHT_SCALE
var hz := i * FREQ_MAX / VU_COUNT
var magnitude := spectrum.get_magnitude_for_frequency_range(prev_hz, hz).length()
var energy := clampf((MIN_DB + linear_to_db(magnitude)) / MIN_DB, 0, 1)
var height := energy * HEIGHT * HEIGHT_SCALE
data.append(height)
prev_hz = hz
for i in range(VU_COUNT):
for i in VU_COUNT:
if data[i] > max_values[i]:
max_values[i] = data[i]
else:
max_values[i] = lerp(max_values[i], data[i], ANIMATION_SPEED)
max_values[i] = lerpf(max_values[i], data[i], ANIMATION_SPEED)
if data[i] <= 0.0:
min_values[i] = lerp(min_values[i], 0.0, ANIMATION_SPEED)
min_values[i] = lerpf(min_values[i], 0.0, ANIMATION_SPEED)
# Sound plays back continuously, so the graph needs to be updated every frame.
queue_redraw()
func _ready():
func _ready() -> void:
spectrum = AudioServer.get_bus_effect_instance(0, 0)
min_values.resize(VU_COUNT)
max_values.resize(VU_COUNT)