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

@@ -2,7 +2,7 @@
# the key maps in a simple way through a dictionary.
extends Node
const keymaps_path = "user://keymaps.dat"
const keymaps_path := "user://keymaps.dat"
var keymaps: Dictionary
@@ -10,27 +10,30 @@ func _ready() -> void:
# First we create the keymap dictionary on startup with all
# the keymap actions we have.
for action in InputMap.get_actions():
if InputMap.action_get_events(action).size() != 0:
if not InputMap.action_get_events(action).is_empty():
keymaps[action] = InputMap.action_get_events(action)[0]
load_keymap()
func load_keymap() -> void:
if not FileAccess.file_exists(keymaps_path):
save_keymap() # There is no save file yet, so let's create one.
# There is no save file yet, so let's create one.
save_keymap()
return
var file = FileAccess.open(keymaps_path, FileAccess.READ)
var temp_keymap = file.get_var(true) as Dictionary
var file := FileAccess.open(keymaps_path, FileAccess.READ)
var temp_keymap: Dictionary = file.get_var(true)
file.close()
# We don't just replace the keymaps dictionary, because if you
# updated your game and removed/added keymaps, the data of this
# save file may have invalid actions. So we check one by one to
# make sure that the keymap dictionary really has all current actions.
for action in keymaps.keys():
for action: StringName in keymaps.keys():
if temp_keymap.has(action):
keymaps[action] = temp_keymap[action]
# Whilst setting the keymap dictionary, we also set the
# correct InputMap event
# correct InputMap event.
InputMap.action_erase_events(action)
InputMap.action_add_event(action, keymaps[action])