Skip to content

Commit

Permalink
[*] Add more static typing
Browse files Browse the repository at this point in the history
  • Loading branch information
IceflowRE committed Sep 10, 2024
1 parent 505dee0 commit 6ee21e0
Show file tree
Hide file tree
Showing 16 changed files with 22 additions and 26 deletions.
2 changes: 1 addition & 1 deletion addons/git_sha_project_setting/utils.gd
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static func get_git_sha() -> GitResult:

var rx: RegEx = RegEx.new()
rx.compile('^ref:\\s(.*)$')
var git_head = rx.search(text)
var git_head: RegExMatch = rx.search(text)
if git_head == null:
return GitResult.new("", "could not parse git head file")
file = FileAccess.open("res://.git/" + git_head.get_string(1), FileAccess.READ)
Expand Down
2 changes: 1 addition & 1 deletion addons/glogging/glogging.gd
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Logger:
return "CRITICAL"

func _log(level: int, module: String, message: Variant, values: Array[Variant] = []) -> void:
var unix_time = Time.get_unix_time_from_system()
var unix_time: float = Time.get_unix_time_from_system()
var time: Dictionary = Time.get_datetime_dict_from_unix_time(unix_time)
time.merge(Time.get_time_dict_from_unix_time(unix_time))
time["millisecond"] = int(str(unix_time).pad_decimals(3).split(".", true, 1)[1])
Expand Down
2 changes: 1 addition & 1 deletion addons/hide_private_properties/inspector_plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func _parse_property(object: Object, type: Variant.Type, name: String, hint_type
func _has_property(object: Object, propertyName: String) -> bool:
# Note: Checking if the property exists using the 'in' keyword also triggers
# the warning in 'core/config/project_settings.cpp:_get' (v4.2.1)
for property in object.get_property_list():
for property: Dictionary in object.get_property_list():
if property.name == propertyName:
return true
return false
4 changes: 2 additions & 2 deletions addons/licenses/component.gd
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class License:
return self

func duplicate():
var dup = new()
var dup: License = new()
dup.name = self.name
dup.identifier = self.identifier
dup.text = self.text
Expand Down Expand Up @@ -90,7 +90,7 @@ var web: String
var paths: PackedStringArray = []
var licenses: Array[License] = []

func _get_property_list() -> Array:
func _get_property_list() -> Array[Dictionary]:
return [
{
"name": "paths",
Expand Down
2 changes: 1 addition & 1 deletion addons/licenses/export_plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func _export_begin(features: PackedStringArray, is_debug: bool, path: String, fl
if not FileAccess.file_exists(Licenses.get_license_data_filepath()):
return
self._add_file(Licenses.get_license_data_filepath())
var res = Licenses.load(Licenses.get_license_data_filepath())
var res: Licenses.LoadResult = Licenses.load(Licenses.get_license_data_filepath())
if res.err_msg != "":
push_error("Failed to export license files: " + res.err_msg)
return
Expand Down
2 changes: 1 addition & 1 deletion addons/licenses/internal/component_detail_tree.gd
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func _on_item_edited(item: TreeItem = null) -> void:
item = self.get_edited()
var handler = item.get_meta("handler")
handler.edited()
var parent = item.get_parent()
var parent: TreeItem = item.get_parent()
if parent != null:
parent.get_meta("handler").child_edited(item)

Expand Down
2 changes: 1 addition & 1 deletion addons/licenses/internal/components_tree.gd
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func _get_drag_data(at_position: Vector2) -> Variant:

func _drop_data(at_position: Vector2, data: Variant) -> void:
var to_item: TreeItem = self.get_item_at_position(at_position)
var category = to_item.get_meta("category")
var category: String = to_item.get_meta("category")
var cur_component: Component = self._get_selected_component()
if cur_component.category == category:
return
Expand Down
6 changes: 3 additions & 3 deletions addons/licenses/internal/utils.gd
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
## will return the property list of object
## if an entry is duplicated the last one is replacing the previous one
static func get_updated_property_list(object: Object) -> Array:
var properties: Array = object.get_property_list()
var patched_properties: Array = object._get_property_list()
static func get_updated_property_list(object: Object) -> Array[Dictionary]:
var properties: Array[Dictionary] = object.get_property_list()
var patched_properties: Array[Dictionary] = object._get_property_list()
properties = properties.slice(0, properties.size() - patched_properties.size())
for p_prop_idx: int in range(patched_properties.size()):
for prop_idx: int in range(properties.size()):
Expand Down
2 changes: 1 addition & 1 deletion addons/licenses/licenses.gd
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static func save(components: Array[Component], file_path: String) -> int:
var file: FileAccess = FileAccess.open(file_path, FileAccess.WRITE)
if file == null:
return FileAccess.get_open_error()
var raw: Array = []
var raw: Array[Dictionary] = []
for component: Component in components:
raw.append(component.serialize())
file.store_line(JSON.stringify({"components": raw}))
Expand Down
9 changes: 4 additions & 5 deletions addons/qr_code/qr_code.gd
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ const _ALPHANUMERIC_CHARACTERS: Dictionary = {

## https://www.thonky.com/qr-code-tutorial/error-correction-table
## [total data codewords, EC codewords per block, number of blocks in group 1, number of data codewords in group 1 blocks, number of blocks in group 2, number of data codewords in group 2 blocks]
const _ERROR_CORRECTION: Array = [
const _ERROR_CORRECTION: Array[Dictionary] = [
# 1
{
ErrorCorrection.LOW: [19, 7, 1, 19, 0, 0],
Expand Down Expand Up @@ -635,7 +635,7 @@ const _ERROR_CORRECTION: Array = [
]

## sorted by version
const _ALIGNMENT_PATTERN_POSITIONS: Array = [
const _ALIGNMENT_PATTERN_POSITIONS: Array[Array] = [
[],
[6, 18],
[6, 22],
Expand Down Expand Up @@ -679,7 +679,7 @@ const _ALIGNMENT_PATTERN_POSITIONS: Array = [
]

## remainder bits after structured data bits
const _REMAINDER_BITS: Array = [ 0, 7, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4,4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0 ]
const _REMAINDER_BITS: Array[int] = [ 0, 7, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4,4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0 ]

static var _number_rx: RegEx = RegEx.create_from_string("[^\\d]*")
static var _alphanumeric_rx: RegEx = RegEx.create_from_string("[^0-9A-Z $%*+\\-.\\/:]*")
Expand Down Expand Up @@ -773,7 +773,6 @@ func set_mask_pattern(new_mask_pattern: int) -> void:
func get_input_data() -> Variant:
return _input_data


## get module count of one axis
func get_module_count() -> int:
return _calc_module_count(self.version)
Expand Down Expand Up @@ -960,7 +959,7 @@ func encode() -> PackedByteArray:
self.version = self.calc_min_version()

var data_stream: BitStream = self._encode_data()
var err_correction: Array = self._error_correction(data_stream)
var err_correction: Array[PackedByteArray] = self._error_correction(data_stream)
var structured_data: BitStream = self._structure_data(data_stream, err_correction)
var qr_data: PackedByteArray = self._place_modules(structured_data)
qr_data = self._mask_qr(qr_data)
Expand Down
2 changes: 1 addition & 1 deletion addons/qr_code/qr_code_rect.gd
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var auto_mask_pattern: bool = true:
set = set_auto_mask_pattern,
get = get_auto_mask_pattern
## Used mask pattern.
var mask_pattern = 0:
var mask_pattern: int = 0:
set = set_mask_pattern,
get = get_mask_pattern
var light_module_color: Color = Color.WHITE:
Expand Down
4 changes: 2 additions & 2 deletions addons/qr_code/shift_jis.gd
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ static func get_string_from_jis_8(arr: PackedByteArray) -> String:
## [Unicode3.2] UCS codepoint defined by Unicode 3.2
## Fullwidth UCS fullwidth form (U+Fxxx)
## Windows Windows (CP932) mapping
const _UNICODE_TO_SHIFT_JIS_TABLE: Dictionary = {
const _UNICODE_TO_SHIFT_JIS_TABLE: Dictionary[int, int] = {
0x0000: 0x00, # <control>
0x0001: 0x01, # <control>
0x0002: 0x02, # <control>
Expand Down Expand Up @@ -11622,7 +11622,7 @@ const _UNICODE_TO_SHIFT_JIS_TABLE: Dictionary = {
0x2A6B2: 0xFCF4, # <cjk> [2000] [Unicode3.1]
}

const _SHIFT_JIS_TO_UNICODE_TABLE: Dictionary = {
const _SHIFT_JIS_TO_UNICODE_TABLE: Dictionary[int, int] = {
0x00: 0x0000, # <control>
0x01: 0x0001, # <control>
0x02: 0x0002, # <control>
Expand Down
2 changes: 1 addition & 1 deletion addons/texture_button_colored/texture_button_colored.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var icon_disabled_color: Color

var _is_hovered: bool = false

var _theme_overrides = CustomThemeOverrides.new([
var _theme_overrides: CustomThemeOverrides = CustomThemeOverrides.new([
["icon_normal_color", Theme.DATA_TYPE_COLOR],
["icon_pressed_color", Theme.DATA_TYPE_COLOR],
["icon_hover_color", Theme.DATA_TYPE_COLOR],
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_theme_overrides/main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var my_font_size: int
var my_icon: Texture2D
var my_style_box: StyleBox

var _theme_overrides = CustomThemeOverrides.new([
var _theme_overrides: CustomThemeOverrides = CustomThemeOverrides.new([
["my_font_color", Theme.DATA_TYPE_COLOR],
["my_border_size", Theme.DATA_TYPE_CONSTANT],
["my_font", Theme.DATA_TYPE_FONT],
Expand Down
2 changes: 0 additions & 2 deletions examples/licenses/display_licenses.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ const LicenseContainer := preload("res://examples/licenses/license_container.gd"
## Container to display the license details.
@export var _license_container: LicenseContainer

@export var _example_selector: TabContainer

var licenses: Array[Component] = []

func _ready() -> void:
Expand Down
3 changes: 1 addition & 2 deletions examples/licenses/main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[ext_resource type="Script" path="res://examples/licenses/display_licenses.gd" id="1_bba6e"]
[ext_resource type="Script" path="res://examples/licenses/license_container.gd" id="2_0yh67"]

[node name="main" type="PanelContainer" node_paths=PackedStringArray("_tree", "_item_list", "_license_container", "_example_selector")]
[node name="main" type="PanelContainer" node_paths=PackedStringArray("_tree", "_item_list", "_license_container")]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
Expand All @@ -13,7 +13,6 @@ script = ExtResource("1_bba6e")
_tree = NodePath("MarginContainer/HBoxContainer/TabContainer/Tree")
_item_list = NodePath("MarginContainer/HBoxContainer/TabContainer/ItemList")
_license_container = NodePath("MarginContainer/HBoxContainer/PanelContainer/MarginContainer")
_example_selector = NodePath("MarginContainer/HBoxContainer/TabContainer")

[node name="MarginContainer" type="MarginContainer" parent="."]
layout_mode = 2
Expand Down

0 comments on commit 6ee21e0

Please sign in to comment.