diff --git a/save_load/autoloads/save_game_manager.gd b/save_load/autoloads/save_game_manager.gd index 2558117..ac5758f 100644 --- a/save_load/autoloads/save_game_manager.gd +++ b/save_load/autoloads/save_game_manager.gd @@ -72,7 +72,7 @@ func list_saves(include_quick_saves: bool = true, include_auto_saves: bool = tru _save_resource.filesize = _loaded_file.get_length() if FileAccess.file_exists(save_game_data_path + _save_icon): - _save_resource.save_icon = _save_icon + _save_resource.save_icon = save_game_data_path + _save_icon save_files.append(_save_resource) @@ -95,10 +95,20 @@ func quick_load_game() -> void: game_loaded.emit() + ## Sort the save files list by date created, descending func _custom_save_file_sort(a: SaveFileDetailsResource, b: SaveFileDetailsResource) -> bool: return a.date_created > b.date_created +## Generates an icon by taking a screenshot[br] +## The icon utilizes the same filename as the save file, replacing `.tres` with `.png` +func _generate_save_icon(save_game_file_path: String) -> void: + # TODO: Hide the UI before taking the screenshot + var _icon_filepath: String = save_game_file_path.replace(".tres", ".png") + + var _icon: Image = get_viewport().get_texture().get_image() + _icon.save_png(_icon_filepath) + ## Find the SaveLevelDataComponent within the level which stores the save paths and filenames func _load_save_level_data_component() -> bool: _save_level_data_component = get_tree().get_first_node_in_group("save_level_data_component") @@ -138,6 +148,8 @@ func _save_game_as_resource(resource_filename: String) -> void: if result != OK: printerr("Failed to save game (" , result, "): ", save_game_file_path) + _generate_save_icon(save_game_file_path) + ## Save the properties defined on the SaveDataComponents attached to various nodes (such as Block) func _save_node_data() -> void: var nodes: Array = get_tree().get_nodes_in_group("save_data_component") diff --git a/save_load/ui/save_file.gd b/save_load/ui/save_file.gd index 1c82756..6954b52 100644 --- a/save_load/ui/save_file.gd +++ b/save_load/ui/save_file.gd @@ -39,7 +39,16 @@ func set_save_date() -> void: save_date_label.text = save_file_details.date_created func set_save_icon() -> void: - save_icon.texture = load(save_file_details.save_icon) + if !FileAccess.file_exists(save_file_details.save_icon): + return + + var _icon_image: Image = Image.new() + _icon_image.load(save_file_details.save_icon) + + var _icon_texture: ImageTexture = ImageTexture.new() + _icon_texture.set_image(_icon_image) + + save_icon.texture = _icon_texture func set_save_name() -> void: save_name_label.text = save_file_details.save_name