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,36 +1,29 @@
extends Panel
const BPM = 116
const BARS = 4
var playing = false
const COMPENSATE_FRAMES = 2
const COMPENSATE_HZ = 60.0
enum SyncSource {
SYSTEM_CLOCK,
SOUND_CLOCK,
}
var sync_source = SyncSource.SYSTEM_CLOCK
const BPM = 116
const BARS = 4
const COMPENSATE_FRAMES = 2
const COMPENSATE_HZ = 60.0
var playing := false
var sync_source := SyncSource.SYSTEM_CLOCK
# Used by system clock.
var time_begin
var time_delay
var time_begin: float
var time_delay: float
func strsec(secs):
var s = str(secs)
if (secs < 10):
s = "0" + s
return s
func _process(_delta):
func _process(_delta: float) -> void:
if not playing or not $Player.playing:
return
var time = 0.0
var time := 0.0
if sync_source == SyncSource.SYSTEM_CLOCK:
# Obtain from ticks.
time = (Time.get_ticks_usec() - time_begin) / 1000000.0
@@ -39,14 +32,14 @@ func _process(_delta):
elif sync_source == SyncSource.SOUND_CLOCK:
time = $Player.get_playback_position() + AudioServer.get_time_since_last_mix() - AudioServer.get_output_latency() + (1 / COMPENSATE_HZ) * COMPENSATE_FRAMES
var beat = int(time * BPM / 60.0)
var seconds = int(time)
var seconds_total = int($Player.stream.get_length())
var beat := int(time * BPM / 60.0)
var seconds := int(time)
var seconds_total := int($Player.stream.get_length())
@warning_ignore("integer_division")
$Label.text = str("BEAT: ", beat % BARS + 1, "/", BARS, " TIME: ", seconds / 60, ":", strsec(seconds % 60), " / ", seconds_total / 60, ":", strsec(seconds_total % 60))
$Label.text = str("BEAT: ", beat % BARS + 1, "/", BARS, " TIME: ", seconds / 60, ":", str(seconds % 60).pad_zeros(2), " / ", seconds_total / 60, ":", str(seconds_total % 60).pad_zeros(2))
func _on_PlaySystem_pressed():
func _on_PlaySystem_pressed() -> void:
sync_source = SyncSource.SYSTEM_CLOCK
time_begin = Time.get_ticks_usec()
time_delay = AudioServer.get_time_to_next_mix() + AudioServer.get_output_latency()
@@ -54,7 +47,7 @@ func _on_PlaySystem_pressed():
$Player.play()
func _on_PlaySound_pressed():
func _on_PlaySound_pressed() -> void:
sync_source = SyncSource.SOUND_CLOCK
playing = true
$Player.play()

View File

@@ -19,32 +19,62 @@ size_flags_vertical = 4
script = ExtResource("7")
[node name="Label" type="Label" parent="."]
layout_mode = 0
offset_left = 106.895
offset_top = 427.158
offset_right = 914.895
offset_bottom = 488.158
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -404.0
offset_top = 55.0
offset_right = 404.0
offset_bottom = 121.0
grow_horizontal = 2
grow_vertical = 2
theme_override_colors/font_color = Color(0.654902, 1, 0.67451, 1)
theme_override_colors/font_shadow_color = Color(0, 0, 0, 1)
theme_override_constants/shadow_offset_x = 4
theme_override_constants/shadow_offset_y = 4
theme_override_fonts/font = ExtResource("2_wyi3x")
theme_override_font_sizes/font_size = 48
text = "Press one of the buttons."
horizontal_alignment = 1
vertical_alignment = 1
[node name="Player" type="AudioStreamPlayer" parent="."]
stream = ExtResource("3")
volume_db = -6.0
[node name="PlaySystem" type="TextureButton" parent="."]
layout_mode = 0
offset_left = 214.737
offset_top = 187.368
offset_right = 342.737
offset_bottom = 315.368
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -288.0
offset_top = -136.0
offset_right = -160.0
offset_bottom = -7.99997
grow_horizontal = 2
grow_vertical = 2
texture_normal = ExtResource("5")
texture_pressed = ExtResource("5")
texture_hover = ExtResource("1")
[node name="PlaySound" type="TextureButton" parent="."]
layout_mode = 0
offset_left = 622.105
offset_top = 183.158
offset_right = 750.105
offset_bottom = 311.158
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = 160.0
offset_top = -136.0
offset_right = 288.0
offset_bottom = -8.0
grow_horizontal = 2
grow_vertical = 2
texture_normal = ExtResource("2")
texture_pressed = ExtResource("2")
texture_hover = ExtResource("4")

View File

@@ -17,6 +17,10 @@ run/main_scene="res://bpm_sync.tscn"
config/features=PackedStringArray("4.2")
config/icon="res://icon.webp"
[debug]
gdscript/warnings/untyped_declaration=1
[display]
window/stretch/mode="canvas_items"