Skip to content

Commit

Permalink
Fix crash when switching to Fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
qrrk committed Sep 18, 2021
1 parent 4072782 commit a1e3733
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion scripts/Catapult.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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())
20 changes: 18 additions & 2 deletions scripts/FontManager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand All @@ -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")).\
Expand All @@ -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:
Expand Down
11 changes: 11 additions & 0 deletions scripts/FontsUI.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit a1e3733

Please sign in to comment.