aboutsummaryrefslogtreecommitdiff
path: root/game/src/Game/Autoload/Argument
diff options
context:
space:
mode:
author Spartan322 <Megacake1234@gmail.com>2023-12-23 05:01:51 +0100
committer George L. Albany <Megacake1234@gmail.com>2023-12-24 04:52:36 +0100
commitb6413251a866c76538869b84ed1c9b9852f7c507 (patch)
tree1b99c935438692bb2ebadeac412b990c82089b65 /game/src/Game/Autoload/Argument
parent50b0b935b0bf0724f40b5140aca85d1830a8b1b3 (diff)
Apply type hints to menu scripts
Diffstat (limited to 'game/src/Game/Autoload/Argument')
-rw-r--r--game/src/Game/Autoload/Argument/ArgumentOption.gd12
-rw-r--r--game/src/Game/Autoload/Argument/ArgumentParser.gd22
2 files changed, 18 insertions, 16 deletions
diff --git a/game/src/Game/Autoload/Argument/ArgumentOption.gd b/game/src/Game/Autoload/Argument/ArgumentOption.gd
index f98b19c..a9b7000 100644
--- a/game/src/Game/Autoload/Argument/ArgumentOption.gd
+++ b/game/src/Game/Autoload/Argument/ArgumentOption.gd
@@ -17,10 +17,10 @@ extends Resource
TYPE_COLOR: default_value = Color()
_: default_value = null
notify_property_list_changed()
-var default_value
+var default_value : Variant
@export var description : String
-func _init(_name = "", _type = TYPE_NIL, _description = "", default = null):
+func _init(_name := "", _type := TYPE_NIL, _description := "", default : Variant = null) -> void:
name = _name
type = _type
if default != null and typeof(default) == type:
@@ -41,15 +41,17 @@ func get_type_string() -> StringName:
TYPE_COLOR: return "color"
return "<invalid type>"
-func _get(property):
+func _get(property : StringName) -> Variant:
if property == "default_value": return default_value
+ return null
-func _set(property, value):
+func _set(property : StringName, value : Variant) -> bool:
if property == "default_value":
default_value = value
return true
+ return false
-func _get_property_list():
+func _get_property_list() -> Array[Dictionary]:
var properties := []
properties.append({
diff --git a/game/src/Game/Autoload/Argument/ArgumentParser.gd b/game/src/Game/Autoload/Argument/ArgumentParser.gd
index b012215..b3e8632 100644
--- a/game/src/Game/Autoload/Argument/ArgumentParser.gd
+++ b/game/src/Game/Autoload/Argument/ArgumentParser.gd
@@ -46,7 +46,7 @@ const color_name_array : PackedStringArray =[
func has_argument_support(arg_name : StringName, include_aliases : bool = false) -> bool:
return option_array.any(
- func(opt):
+ func(opt : ArgumentOption) -> bool:
if include_aliases and arg_name in opt.aliases:
return true
return opt.name == arg_name
@@ -54,7 +54,7 @@ func has_argument_support(arg_name : StringName, include_aliases : bool = false)
func get_argument(arg_name : StringName, default_val : Variant = null) -> Variant:
if ProjectSettings.has_setting(argument_setting_path):
- var arg_setting = ProjectSettings.get_setting_with_override(argument_setting_path)
+ var arg_setting : Variant = ProjectSettings.get_setting_with_override(argument_setting_path)
if not arg_setting is Dictionary:
push_error("Argument setting is not a dictionary.")
return default_val
@@ -64,7 +64,7 @@ func get_argument(arg_name : StringName, default_val : Variant = null) -> Varian
func set_argument(arg_name : StringName, value : Variant) -> void:
if ProjectSettings.has_setting(argument_setting_path):
- var arg_setting = null
+ var arg_setting : Variant = null
arg_setting = ProjectSettings.get_setting_with_override(argument_setting_path)
if not arg_setting is Dictionary:
push_error("Argument setting is not a dictionary.")
@@ -124,7 +124,7 @@ func _parse_value(arg_name : StringName, value_string : String, type : Variant.T
TYPE_RECT2, \
TYPE_RECT2I:
push_warning("Value type '%s' may not be supported." % type)
- var data_array = value_string.lstrip("(").rstrip(")").split(",", false)
+ var data_array := value_string.lstrip("(").rstrip(")").split(",", false)
for index in range(data_array.size()):
data_array[index] = " " + data_array[index].strip_edges()
match type:
@@ -206,7 +206,7 @@ func _parse_argument_list(dictionary : Dictionary, arg_list : PackedStringArray)
var current_option : ArgumentOption = null
for arg in arg_list:
if current_option != null and not arg.begins_with("-"):
- var result = _parse_value(current_key, arg, current_option.type)
+ var result : Variant = _parse_value(current_key, arg, current_option.type)
if result != null:
dictionary[current_option.name] = result
current_option = null
@@ -229,8 +229,8 @@ func _parse_argument_list(dictionary : Dictionary, arg_list : PackedStringArray)
push_warning("Parsing shorthand alias containing '%s', perhaps you meant '--%s'? Skipping argument." % [c, arg])
break
var alias_found := false
- for o in option_array:
- if o.aliases.any(func(v): return c == v):
+ for o : ArgumentOption in option_array:
+ if o.aliases.any(func(v : StringName) -> bool: return c == v):
if o.type == TYPE_BOOL:
dictionary[o.name] = true
else:
@@ -258,7 +258,7 @@ func _parse_argument_list(dictionary : Dictionary, arg_list : PackedStringArray)
key = key.substr(1)
for o in option_array:
- if key == o.name or o.aliases.any(func(v): return key == v):
+ if key == o.name or o.aliases.any(func(v : StringName) -> bool: return key == v):
current_option = o
break
@@ -268,7 +268,7 @@ func _parse_argument_list(dictionary : Dictionary, arg_list : PackedStringArray)
current_key = key
if first_equal > -1:
- var arg_result = _parse_value(key, value, current_option.type)
+ var arg_result : Variant = _parse_value(key, value, current_option.type)
if arg_result != null:
dictionary[current_option.name] = arg_result
current_option = null
@@ -279,7 +279,7 @@ func _parse_argument_list(dictionary : Dictionary, arg_list : PackedStringArray)
return dictionary
-func _print_help():
+func _print_help() -> void:
var project_name : StringName = ProjectSettings.get_setting_with_override(&"application/config/name")
var project_version : String = _GIT_INFO_.tag
var project_hash : String = _GIT_INFO_.short_hash
@@ -310,7 +310,7 @@ Options:
option.description
])
-func _ready():
+func _ready() -> void:
if Engine.is_editor_hint(): return
_set_argument_setting()
GameDebug._singleton = GameDebug.new()