From a1e373308277ed45b96db9463f722563501bd8b8 Mon Sep 17 00:00:00 2001 From: qrrk <19731636+qrrk@users.noreply.github.com> Date: Sun, 19 Sep 2021 00:15:59 +0300 Subject: [PATCH] Fix crash when switching to Fonts --- scripts/Catapult.gd | 2 +- scripts/FontManager.gd | 20 ++++++++++++++++++-- scripts/FontsUI.gd | 11 +++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/scripts/Catapult.gd b/scripts/Catapult.gd index cefd0bd4..134dee2a 100644 --- a/scripts/Catapult.gd +++ b/scripts/Catapult.gd @@ -418,5 +418,5 @@ func _refresh_currently_installed() -> void: _btn_play.disabled = true _btn_game_dir.visible = false - for i in [1, 2]: + for i in [1, 2, 3]: _tabs.set_tab_disabled(i, not _is_selected_game_installed()) diff --git a/scripts/FontManager.gd b/scripts/FontManager.gd index 6acf2568..e2c52772 100644 --- a/scripts/FontManager.gd +++ b/scripts/FontManager.gd @@ -66,6 +66,14 @@ func load_available_fonts() -> void: available_fonts = json_result.result +func font_config_file_exists() -> bool: + + var config_file: String = _workdir.plus_file(_settings.read("game")).\ + plus_file("current").plus_file("config").plus_file("fonts.json") + + return Directory.new().file_exists(config_file) + + func load_font_config() -> void: var result: Dictionary = {} @@ -87,11 +95,19 @@ func load_font_config() -> void: emit_signal("status_message", "Could not open font config file %s (error code: %s)." % [config_file, err], Enums.MSG_ERROR) else: - emit_signal("status_message", "Font config file %s is not found!", Enums.MSG_ERROR) + emit_signal("status_message", "Font config file %s is not found!" % config_file, Enums.MSG_ERROR) font_config = result +func options_file_exists() -> bool: + + var options_file: String = _workdir.plus_file(_settings.read("game")).\ + plus_file("current").plus_file("config").plus_file("options.json") + + return Directory.new().file_exists(options_file) + + func load_game_options() -> void: var options_file: String = _workdir.plus_file(_settings.read("game")).\ @@ -112,7 +128,7 @@ func load_game_options() -> void: emit_signal("status_message", "Could not open game options file %s (error code: %s)." % [options_file, err], Enums.MSG_ERROR) else: - emit_signal("status_message", "Game options file %s is not found!", Enums.MSG_ERROR) + emit_signal("status_message", "Game options file %s is not found!" % options_file, Enums.MSG_ERROR) func _write_font_config() -> void: diff --git a/scripts/FontsUI.gd b/scripts/FontsUI.gd index 72c88b0d..a77976d9 100644 --- a/scripts/FontsUI.gd +++ b/scripts/FontsUI.gd @@ -55,6 +55,7 @@ const _PREVIEW_TEXT_NUM := "1234567890 !@#$ %^&* ()[]{}" onready var _rng := RandomNumberGenerator.new() onready var _geom := $"/root/WindowGeometry" +onready var _tabs := $".." onready var _settings := $"/root/SettingsManager" onready var _fonts := $"/root/Catapult/Fonts" onready var _list := $FontSelection/RightPane/FontsList @@ -127,6 +128,16 @@ func _on_Tabs_tab_changed(tab: int) -> void: if tab != 3: return + if not _fonts.font_config_file_exists(): + emit_signal("status_message", "Can't manage fonts at this time: font config file does not exist. Make sure you've started the game at least once to create it.", Enums.MSG_WARN) + _tabs.current_tab = 0 + return + + if not _fonts.options_file_exists(): + emit_signal("status_message", "Can't manage fonts at this time: options file does not exist. Make sure you've started the game at least once to create it.", Enums.MSG_WARN) + _tabs.current_tab = 0 + return + _fonts.load_available_fonts() _fonts.load_font_config()