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,26 +1,19 @@
@tool
extends Node
# NOTE: in theory this would extend from resource, but until saving and loading resources
# works in godot, we'll stick with extending from node
# and using JSON files to save/load data
# NOTE: In theory, this would extend from Resource, but until saving and loading resources
# works in Godot, we'll stick with extending from Node and using JSON files to save/load data.
#
# See material_import.gd for more information
# See `material_import.gd` for more information.
var albedo_color
var metallic_strength
var roughness_strength
func init():
albedo_color = Color()
metallic_strength = 0
roughness_strength = 0
var albedo_color := Color.BLACK
var metallic_strength := 0.0
var roughness_strength := 0.0
# Convert our data into an dictonary so we can convert it
# into the JSON format
func make_json():
var json_dict = {}
# into the JSON format.
func make_json() -> String:
var json_dict := {}
json_dict["albedo_color"] = {}
json_dict["albedo_color"]["r"] = albedo_color.r
@@ -30,15 +23,13 @@ func make_json():
json_dict["metallic_strength"] = metallic_strength
json_dict["roughness_strength"] = roughness_strength
return JSON.new().stringify(json_dict)
return JSON.stringify(json_dict)
# Convert the passed in string to a json dictonary, and then
# Convert the passed in string to a JSON dictonary, and then
# fill in our data.
func from_json(json_dict_as_string):
var json = JSON.new()
json.parse(json_dict_as_string)
var json_dict = json.get_data()
func from_json(json_dict_as_string: String) -> void:
var json_dict: Dictionary = JSON.parse_string(json_dict_as_string)
albedo_color.r = json_dict["albedo_color"]["r"]
albedo_color.g = json_dict["albedo_color"]["g"]
@@ -49,11 +40,11 @@ func from_json(json_dict_as_string):
# Make a StandardMaterial3D using our variables.
func make_material():
var mat = StandardMaterial3D.new()
func make_material() -> StandardMaterial3D:
var material := StandardMaterial3D.new()
mat.albedo_color = albedo_color
mat.metallic = metallic_strength
mat.roughness = roughness_strength
material.albedo_color = albedo_color
material.metallic = metallic_strength
material.roughness = roughness_strength
return mat
return material