Browse Source

Moving icon texture into SaveGameManager

pull/16/head
Ryan Reed 1 month ago
parent
commit
8ea3b727f3
6 changed files with 23 additions and 20 deletions
  1. +17
    -3
      save_load/autoloads/save_game_manager.gd
  2. +1
    -0
      save_load/components/save_level_data_component.gd
  3. +3
    -1
      save_load/components/save_level_data_component.tscn
  4. +1
    -1
      save_load/resources/save_file_details_resource.gd
  5. +1
    -14
      save_load/ui/save_file.gd
  6. +0
    -1
      save_load/ui/save_file.tscn

+ 17
- 3
save_load/autoloads/save_game_manager.gd View File

@ -70,8 +70,7 @@ func list_saves(include_quick_saves: bool = true, include_auto_saves: bool = tru
var _loaded_file: FileAccess = FileAccess.open(_save_path, FileAccess.READ)
_save_resource.filesize = _loaded_file.get_length()
if FileAccess.file_exists(save_game_data_path + _save_icon):
_save_resource.save_icon = save_game_data_path + _save_icon
_save_resource.save_icon_texture = _generate_save_icon_texture(save_game_data_path + _save_icon)
save_files.append(_save_resource)
@ -94,11 +93,26 @@ 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
## Generate the texture for use in the save file listing
func _generate_save_icon_texture(save_icon: String) -> Texture2D:
var _icon_texture: Texture2D = ImageTexture.new()
if save_icon != null and !FileAccess.file_exists(save_icon):
_icon_texture = _save_level_data_component.default_save_icon_resource
elif save_icon == null:
_icon_texture = _save_level_data_component.default_save_icon_resource
else:
var _icon_image: Image = Image.new()
_icon_image.load(save_icon)
@warning_ignore("unsafe_method_access")
_icon_texture.set_image(_icon_image)
return _icon_texture
## 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:


+ 1
- 0
save_load/components/save_level_data_component.gd View File

@ -4,6 +4,7 @@ class_name SaveLevelDataComponent
extends Node
@export var default_save_icon_resource: CompressedTexture2D
@export var settings: SaveGameSettings ## The SaveGameSettings resource
@export var ui_node: CanvasLayer ## The UI to Show/Hide when taking screenshot (e.g. save icon generation)


+ 3
- 1
save_load/components/save_level_data_component.tscn View File

@ -1,8 +1,10 @@
[gd_scene load_steps=3 format=3 uid="uid://c3pqilb6yh5kc"]
[gd_scene load_steps=4 format=3 uid="uid://c3pqilb6yh5kc"]
[ext_resource type="Script" uid="uid://c7x2qvyu62230" path="res://save_load/components/save_level_data_component.gd" id="1_exguq"]
[ext_resource type="Texture2D" uid="uid://60ib8urc8xjo" path="res://save_load/resources/default_save_icon.tres" id="2_hd7aa"]
[ext_resource type="Resource" uid="uid://o32fooj1lxg7" path="res://save_load/resources/save_game_settings_resource.tres" id="2_rkr1f"]
[node name="SaveLevelDataComponent" type="Node"]
script = ExtResource("1_exguq")
default_save_icon_resource = ExtResource("2_hd7aa")
settings = ExtResource("2_rkr1f")

+ 1
- 1
save_load/resources/save_file_details_resource.gd View File

@ -8,4 +8,4 @@ extends Node
@export var filename: String = ""
@export var date_created: String = ""
@export var filesize: int = 0
@export var save_icon: String
@export var save_icon_texture: Texture2D

+ 1
- 14
save_load/ui/save_file.gd View File

@ -4,7 +4,6 @@ extends Panel
@export var save_panel_highlight: StyleBoxFlat
@export var save_panel_normal: StyleBoxFlat
@export var default_save_icon_resource: CompressedTexture2D
@export_group("Node Exports")
@export var save_name_label: Label
@ -40,19 +39,7 @@ func set_save_date() -> void:
save_date_label.text = save_file_details.date_created
func set_save_icon() -> void:
var _icon_texture: Texture2D = ImageTexture.new()
if save_file_details.save_icon != "" and !FileAccess.file_exists(save_file_details.save_icon):
return
elif save_file_details.save_icon == "":
_icon_texture = default_save_icon_resource
else:
var _icon_image: Image = Image.new()
_icon_image.load(save_file_details.save_icon)
@warning_ignore("unsafe_method_access")
_icon_texture.set_image(_icon_image)
save_icon.texture = _icon_texture
save_icon.texture = save_file_details.save_icon_texture
func set_save_name() -> void:
save_name_label.text = save_file_details.save_name


+ 0
- 1
save_load/ui/save_file.tscn View File

@ -19,7 +19,6 @@ theme_override_styles/panel = ExtResource("1_cqw77")
script = ExtResource("2_5g2eu")
save_panel_highlight = ExtResource("3_om23c")
save_panel_normal = ExtResource("1_cqw77")
default_save_icon_resource = ExtResource("4_jgxci")
save_name_label = NodePath("HBoxContainer/NameDate/SaveName")
save_date_label = NodePath("HBoxContainer/NameDate/SaveDate")
save_icon = NodePath("HBoxContainer/SaveFileIcon")


Loading…
Cancel
Save