Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply type hints to menu scripts #178

Merged
merged 1 commit into from
Dec 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Apply type hints to menu scripts
Spartan322 committed Dec 24, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit b6413251a866c76538869b84ed1c9b9852f7c507
12 changes: 7 additions & 5 deletions game/src/Game/Autoload/Argument/ArgumentOption.gd
Original file line number Diff line number Diff line change
@@ -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({
22 changes: 11 additions & 11 deletions game/src/Game/Autoload/Argument/ArgumentParser.gd
Original file line number Diff line number Diff line change
@@ -46,15 +46,15 @@ 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
)

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()
2 changes: 1 addition & 1 deletion game/src/Game/Autoload/Events.gd
Original file line number Diff line number Diff line change
@@ -5,5 +5,5 @@ extends Node

var Options: OptionsEventsObject

func _init():
func _init() -> void:
Options = OptionsEventsObject.new()
2 changes: 1 addition & 1 deletion game/src/Game/Autoload/Events/Options.gd
Original file line number Diff line number Diff line change
@@ -31,6 +31,6 @@ var _settings_file := ConfigFile.new()
# * SS-9
# * UIFUN-7, UIFUN-12
# * FS-562
func _init():
func _init() -> void:
if FileAccess.file_exists(_settings_file_path):
_settings_file.load(_settings_file_path)
2 changes: 1 addition & 1 deletion game/src/Game/Autoload/GameLoader.gd
Original file line number Diff line number Diff line change
@@ -2,5 +2,5 @@ extends Node

var ShaderManager : ShaderManagerClass

func _init():
func _init() -> void:
ShaderManager = ShaderManagerClass.new()
6 changes: 3 additions & 3 deletions game/src/Game/Autoload/GuiScale.gd
Original file line number Diff line number Diff line change
@@ -18,9 +18,9 @@ var _guiscales: Dictionary
#Similar to Resolution.gd, but we don't bother checking for strings from files
#and we have floats instead of vector2 integers

func _ready():
func _ready() -> void:
assert(minimum_guiscale > 0, "Minimum gui scale must be positive")
for guiscale_value in _starting_guiscales:
for guiscale_value : float in _starting_guiscales:
add_guiscale(guiscale_value, _starting_guiscales[guiscale_value])
assert(not _guiscales.is_empty(), "No valid starting gui scales!")

@@ -43,7 +43,7 @@ func add_guiscale(guiscale_value: float, guiscale_name: StringName=&"") -> bool:
#returns floats
func get_guiscale_value_list() -> Array:
var list := _guiscales.keys()
list.sort_custom(func(a, b): return a > b)
list.sort_custom(func(a : float, b : float) -> bool: return a > b)
return list

func get_guiscale_display_name(guiscale_value : float) -> StringName:
4 changes: 2 additions & 2 deletions game/src/Game/Autoload/Resolution.gd
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ var _resolutions : Array[Vector2i]
const _regex_pattern : String = "(\\d+)\\s*[xX,]\\s*(\\d+)"
var _regex : RegEx

func _ready():
func _ready() -> void:
assert(minimum_resolution.x > 0 and minimum_resolution.y > 0, "Minimum resolution must be positive!")
for resolution_value in _starting_resolutions:
add_resolution(resolution_value)
@@ -53,7 +53,7 @@ func get_resolution_value_list() -> Array[Vector2i]:
var list : Array[Vector2i] = []
# Return a sorted copy instead of a reference to the private array
list.append_array(_resolutions)
list.sort_custom(func(a, b): return a > b)
list.sort_custom(func(a : Vector2i, b : Vector2i) -> bool: return a > b)
return list

func get_resolution_value_from_string(resolution_string : String) -> Vector2i:
2 changes: 1 addition & 1 deletion game/src/Game/Autoload/SaveManager.gd
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ var current_session_tag : StringName
var _save_dictionary : Dictionary = {}
var _dirty_save : SaveResource

func _ready():
func _ready() -> void:
var saves_dir_path : String = ProjectSettings.get_setting_with_override(save_directory_setting)
assert(saves_dir_path != null, "'%s' setting could not be found." % save_directory_setting)

6 changes: 3 additions & 3 deletions game/src/Game/Autoload/SoundManager.gd
Original file line number Diff line number Diff line change
@@ -11,9 +11,9 @@ var _bus_to_stream_player : Dictionary = {}

# REQUIREMENTS:
# * SND-10
func _ready():
var dir = DirAccess.open(_audio_directory_path)
for fname in dir.get_files():
func _ready() -> void:
var dir := DirAccess.open(_audio_directory_path)
for fname : String in dir.get_files():
match fname.get_extension():
"ogg", "wav", "mp3":
_loaded_sound[fname.get_basename()] = load(_audio_directory_path.path_join(fname)) # SND-10
6 changes: 3 additions & 3 deletions game/src/Game/Autoload/WindowOverride.gd
Original file line number Diff line number Diff line change
@@ -2,11 +2,11 @@ extends Node

const VideoOptions = preload("res://src/Game/Menu/OptionMenu/VideoTab.tscn")

func _init():
func _init() -> void:
var window_id := DisplayServer.get_window_list()[0]
DisplayServer.window_set_size(Vector2(1280.0, 720.0), window_id)

func _ready():
func _ready() -> void:
if ArgumentParser.get_argument(&"help"): return
_on_SceneTree_idle()
# Hack to ensure Video Options load
@@ -15,7 +15,7 @@ func _ready():
add_child(video)
video.queue_free()

func _on_SceneTree_idle():
func _on_SceneTree_idle() -> void:
var window := get_window()
window.set_mode(Window.MODE_FULLSCREEN)
await get_tree().process_frame
14 changes: 7 additions & 7 deletions game/src/Game/GameMenu.gd
Original file line number Diff line number Diff line change
@@ -7,36 +7,36 @@ extends Control

# REQUIREMENTS
# * SS-10
func _ready():
func _ready() -> void:
Events.Options.load_settings_from_file()

func _on_main_menu_new_game_button_pressed():
func _on_main_menu_new_game_button_pressed() -> void:
_lobby_menu.show()
_main_menu.hide()

# REQUIREMENTS
# * SS-6
# * UIFUN-5
func _on_main_menu_options_button_pressed():
func _on_main_menu_options_button_pressed() -> void:
_options_menu.show()
_main_menu.hide()


func _on_options_menu_back_button_pressed():
func _on_options_menu_back_button_pressed() -> void:
_main_menu.show()
_options_menu.hide()


func _on_lobby_menu_back_button_pressed():
func _on_lobby_menu_back_button_pressed() -> void:
_main_menu.show()
_lobby_menu.hide()


func _on_credits_back_button_pressed():
func _on_credits_back_button_pressed() -> void:
_credits_menu.hide()
_main_menu.show()


func _on_main_menu_credits_button_pressed():
func _on_main_menu_credits_button_pressed() -> void:
_credits_menu.show()
_main_menu.hide()
4 changes: 2 additions & 2 deletions game/src/Game/GameStart.gd
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ func _save_setting(file : ConfigFile) -> void:
if file == null: return
file.set_value(section_name, setting_name, _settings_base_path)

func _load_compatibility_mode():
func _load_compatibility_mode() -> void:
# Set this to your Vic2 install dir or a mod's dir to enable compatibility mode
# (this won't work for mods which rely on vanilla map assets, copy missing assets
# into the mod's dir for a temporary fix)
@@ -107,5 +107,5 @@ func _initialize_game() -> void:
# change scene in a thread-safe way
get_tree().change_scene_to_packed.call_deferred(GameMenuScene)

func _on_splash_container_splash_end():
func _on_splash_container_splash_end() -> void:
loading_screen.show()
4 changes: 2 additions & 2 deletions game/src/Game/GlobalClass/Localisation.gd
Original file line number Diff line number Diff line change
@@ -23,12 +23,12 @@ static func load_localisation(dir_path : String) -> void:
# REQUIREMENTS
# * SS-57
# * FS-17
static func initialize():
static func initialize() -> void:
var localisation_dir_path : String = ProjectSettings.get_setting("internationalization/locale/localisation_path", "")
if localisation_dir_path.is_empty():
push_error("internationalization/locale/localisation_path setting is empty!")
else:
Localisation.load_localisation(localisation_dir_path)

static func tr_number(num) -> String:
static func tr_number(num : Variant) -> String:
return TextServerManager.get_primary_interface().format_number(str(num))
6 changes: 3 additions & 3 deletions game/src/Game/LoadingScreen.gd
Original file line number Diff line number Diff line change
@@ -22,14 +22,14 @@ func start_loading_screen(thread_safe_function : Callable) -> void:

thread.start(thread_safe_function)

func try_update_loading_screen(percent_complete: float, quote_should_change = false):
func try_update_loading_screen(percent_complete: float, quote_should_change := false) -> void:
# forces the function to behave as if deferred
await get_tree().process_frame
progress_bar.value = percent_complete
if quote_should_change:
quote_label.text = quotes[randi() % quotes.size()]

func _ready():
func _ready() -> void:
if Engine.is_editor_hint(): return
thread = Thread.new()
# FS-3, UI-30, UIFUN-35
@@ -39,6 +39,6 @@ func _ready():
quotes = [""]
animation_player.play("loadingscreen_gear")

func _exit_tree():
func _exit_tree() -> void:
if thread != null and thread.is_started():
thread.wait_to_finish()
10 changes: 5 additions & 5 deletions game/src/Game/LocaleButton.gd
Original file line number Diff line number Diff line change
@@ -5,15 +5,15 @@ const setting_name : String = "locale"

var _default_locale_index : int

func _ready():
func _ready() -> void:
var locales_country_rename : Dictionary = ProjectSettings.get_setting("internationalization/locale/country_short_name", {})

var locales_list = TranslationServer.get_loaded_locales()
var locales_list := TranslationServer.get_loaded_locales()
var default_locale := Localisation.get_default_locale()
if default_locale not in locales_list:
locales_list.push_back(default_locale)

for locale in locales_list:
for locale : String in locales_list:
# locale_name consists of a compulsory language name and optional script
# and country names, in the format: "<language>[ (script)][, country]"
var locale_name := TranslationServer.get_locale_name(locale)
@@ -33,7 +33,7 @@ func _ready():
Events.Options.load_settings.connect(load_setting)
Events.Options.save_settings.connect(save_setting)

func _notification(what : int):
func _notification(what : int) -> void:
match what:
NOTIFICATION_TRANSLATION_CHANGED:
_select_locale_by_string(TranslationServer.get_locale())
@@ -43,7 +43,7 @@ func _valid_index(index : int) -> bool:

func load_setting(file : ConfigFile) -> void:
if file == null: return
var load_value = file.get_value(section_name, setting_name, Localisation.get_default_locale())
var load_value : Variant = file.get_value(section_name, setting_name, Localisation.get_default_locale())
match typeof(load_value):
TYPE_STRING, TYPE_STRING_NAME:
if _select_locale_by_string(load_value as String):
Loading