|
@ -26,8 +26,8 @@ signal toggle_save_icon_generation(toggled: bool) ## Enable/Disable the generati |
|
|
|
|
|
|
|
|
var _enable_save_icon_generation: bool = true |
|
|
var _enable_save_icon_generation: bool = true |
|
|
var _loaded_save_resource: SaveGameDataResource = SaveGameDataResource.new() |
|
|
var _loaded_save_resource: SaveGameDataResource = SaveGameDataResource.new() |
|
|
|
|
|
var _save_game_settings: SaveGameSettings ## Contains the save paths, filename prepends, and other save settings |
|
|
var _save_icon_size: Vector2i = Vector2i(896, 504) ## If Vector2.ZERO, uses the user's resolution |
|
|
var _save_icon_size: Vector2i = Vector2i(896, 504) ## If Vector2.ZERO, uses the user's resolution |
|
|
var _save_level_data_component: SaveLevelDataComponent ## Contains the save paths and filenames |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _ready() -> void: |
|
|
func _ready() -> void: |
|
@ -48,20 +48,20 @@ func _unhandled_input(event: InputEvent) -> void: |
|
|
|
|
|
|
|
|
func list_saves(include_quick_saves: bool = true, include_auto_saves: bool = true) -> Array[SaveFileDetailsResource]: |
|
|
func list_saves(include_quick_saves: bool = true, include_auto_saves: bool = true) -> Array[SaveFileDetailsResource]: |
|
|
var save_files: Array[SaveFileDetailsResource] = [] |
|
|
var save_files: Array[SaveFileDetailsResource] = [] |
|
|
if not _load_save_level_data_component(): |
|
|
|
|
|
|
|
|
if not _load_save_settings(): |
|
|
return save_files |
|
|
return save_files |
|
|
|
|
|
|
|
|
var save_game_data_path: String = _save_level_data_component.settings.save_game_data_path |
|
|
|
|
|
|
|
|
var save_game_data_path: String = _save_game_settings.save_game_data_path |
|
|
if !DirAccess.dir_exists_absolute(save_game_data_path): |
|
|
if !DirAccess.dir_exists_absolute(save_game_data_path): |
|
|
return save_files |
|
|
return save_files |
|
|
|
|
|
|
|
|
for filename: String in ResourceLoader.list_directory(save_game_data_path): |
|
|
for filename: String in ResourceLoader.list_directory(save_game_data_path): |
|
|
# TODO: Rework so the settings determine the file_name using prepends |
|
|
# TODO: Rework so the settings determine the file_name using prepends |
|
|
if filename.begins_with(_save_level_data_component.settings.quicksave_file_name_prepend) and not include_quick_saves: |
|
|
|
|
|
|
|
|
if filename.begins_with(_save_game_settings.quicksave_file_name_prepend) and not include_quick_saves: |
|
|
continue |
|
|
continue |
|
|
elif filename.begins_with(_save_level_data_component.settings.autosave_file_name_prepend) and not include_auto_saves: |
|
|
|
|
|
|
|
|
elif filename.begins_with(_save_game_settings.autosave_file_name_prepend) and not include_auto_saves: |
|
|
continue |
|
|
continue |
|
|
elif !filename.begins_with(_save_level_data_component.settings.save_file_name_prepend) and !filename.begins_with(_save_level_data_component.settings.quicksave_file_name_prepend) and !filename.begins_with(_save_level_data_component.settings.autosave_file_name_prepend): |
|
|
|
|
|
|
|
|
elif !filename.begins_with(_save_game_settings.save_file_name_prepend) and !filename.begins_with(_save_game_settings.quicksave_file_name_prepend) and !filename.begins_with(_save_game_settings.autosave_file_name_prepend): |
|
|
continue |
|
|
continue |
|
|
|
|
|
|
|
|
var _save_path: String = save_game_data_path + filename |
|
|
var _save_path: String = save_game_data_path + filename |
|
@ -114,9 +114,9 @@ func _generate_save_game_resource() -> SaveGameDataResource: |
|
|
func _generate_save_icon_texture(save_icon: String) -> Texture2D: |
|
|
func _generate_save_icon_texture(save_icon: String) -> Texture2D: |
|
|
var _icon_texture: Texture2D = ImageTexture.new() |
|
|
var _icon_texture: Texture2D = ImageTexture.new() |
|
|
if save_icon != null and !FileAccess.file_exists(save_icon): |
|
|
if save_icon != null and !FileAccess.file_exists(save_icon): |
|
|
_icon_texture = _save_level_data_component.settings.default_save_icon_resource |
|
|
|
|
|
|
|
|
_icon_texture = _save_game_settings.default_save_icon_resource |
|
|
elif save_icon == null: |
|
|
elif save_icon == null: |
|
|
_icon_texture = _save_level_data_component.settings.default_save_icon_resource |
|
|
|
|
|
|
|
|
_icon_texture = _save_game_settings.default_save_icon_resource |
|
|
else: |
|
|
else: |
|
|
var _icon_image: Image = Image.new() |
|
|
var _icon_image: Image = Image.new() |
|
|
_icon_image.load(save_icon) |
|
|
_icon_image.load(save_icon) |
|
@ -126,19 +126,10 @@ func _generate_save_icon_texture(save_icon: String) -> Texture2D: |
|
|
|
|
|
|
|
|
return _icon_texture |
|
|
return _icon_texture |
|
|
|
|
|
|
|
|
## Find the SaveLevelDataComponent within the level which stores the save settings |
|
|
|
|
|
func _load_save_level_data_component() -> bool: |
|
|
|
|
|
_save_level_data_component = get_tree().get_first_node_in_group("save_level_data_component") |
|
|
|
|
|
if _save_level_data_component == null: |
|
|
|
|
|
push_error("Could not find SaveLevelDataComponent node in level") |
|
|
|
|
|
return false |
|
|
|
|
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
|
|
|
|
func _load_game_resource(resource_filename: String) -> void: |
|
|
func _load_game_resource(resource_filename: String) -> void: |
|
|
if not _load_save_level_data_component(): return |
|
|
|
|
|
|
|
|
if not _load_save_settings(): return |
|
|
|
|
|
|
|
|
var save_game_file_path: String = _save_level_data_component.settings.save_game_data_path + resource_filename |
|
|
|
|
|
|
|
|
var save_game_file_path: String = _save_game_settings.save_game_data_path + resource_filename |
|
|
if !FileAccess.file_exists(save_game_file_path): |
|
|
if !FileAccess.file_exists(save_game_file_path): |
|
|
load_error.emit("Failed to load save. File does not exist: %s" % save_game_file_path) |
|
|
load_error.emit("Failed to load save. File does not exist: %s" % save_game_file_path) |
|
|
return |
|
|
return |
|
@ -150,13 +141,24 @@ func _load_game_resource(resource_filename: String) -> void: |
|
|
|
|
|
|
|
|
load_complete.emit() |
|
|
load_complete.emit() |
|
|
|
|
|
|
|
|
|
|
|
## Find the SaveLevelDataComponent within the tree which stores the save settings |
|
|
|
|
|
func _load_save_settings() -> bool: |
|
|
|
|
|
var _save_level_data_component: SaveLevelDataComponent = get_tree().get_first_node_in_group("save_level_data_component") |
|
|
|
|
|
if _save_level_data_component == null: |
|
|
|
|
|
push_error("Could not find SaveLevelDataComponent node in level") |
|
|
|
|
|
return false |
|
|
|
|
|
|
|
|
|
|
|
_save_game_settings = _save_level_data_component.settings |
|
|
|
|
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
|
func _save_game_as_resource(save_name, resource_filename: String) -> void: |
|
|
func _save_game_as_resource(save_name, resource_filename: String) -> void: |
|
|
if not _load_save_level_data_component(): return |
|
|
|
|
|
|
|
|
if not _load_save_settings(): return |
|
|
|
|
|
|
|
|
if !DirAccess.dir_exists_absolute(_save_level_data_component.settings.save_game_data_path): |
|
|
|
|
|
DirAccess.make_dir_absolute(_save_level_data_component.settings.save_game_data_path) |
|
|
|
|
|
|
|
|
if !DirAccess.dir_exists_absolute(_save_game_settings.save_game_data_path): |
|
|
|
|
|
DirAccess.make_dir_absolute(_save_game_settings.save_game_data_path) |
|
|
|
|
|
|
|
|
var save_game_file_path: String = _save_level_data_component.settings.save_game_data_path + resource_filename |
|
|
|
|
|
|
|
|
var save_game_file_path: String = _save_game_settings.save_game_data_path + resource_filename |
|
|
|
|
|
|
|
|
var _save_resource: SaveGameDataResource = _generate_save_game_resource() |
|
|
var _save_resource: SaveGameDataResource = _generate_save_game_resource() |
|
|
_save_resource.save_name = save_name |
|
|
_save_resource.save_name = save_name |
|
@ -200,7 +202,7 @@ func _on_delete_save(filename: String) -> void: |
|
|
delete_error.emit("Empty filename provided") |
|
|
delete_error.emit("Empty filename provided") |
|
|
return |
|
|
return |
|
|
|
|
|
|
|
|
var save_file_path: String = _save_level_data_component.settings.save_game_data_path + filename |
|
|
|
|
|
|
|
|
var save_file_path: String = _save_game_settings.save_game_data_path + filename |
|
|
DirAccess.remove_absolute(save_file_path) |
|
|
DirAccess.remove_absolute(save_file_path) |
|
|
DirAccess.remove_absolute(save_file_path.replace(".tres", ".png")) # Delete icon |
|
|
DirAccess.remove_absolute(save_file_path.replace(".tres", ".png")) # Delete icon |
|
|
|
|
|
|
|
@ -208,20 +210,20 @@ func _on_load_game_save(resource_filename: String) -> void: |
|
|
_load_game_resource(resource_filename) |
|
|
_load_game_resource(resource_filename) |
|
|
|
|
|
|
|
|
func _on_quick_load() -> void: |
|
|
func _on_quick_load() -> void: |
|
|
if not _load_save_level_data_component(): return |
|
|
|
|
|
_load_game_resource(_save_level_data_component.settings.quicksave_file_name_prepend + "game_data.tres") |
|
|
|
|
|
|
|
|
if not _load_save_settings(): return |
|
|
|
|
|
_load_game_resource(_save_game_settings.quicksave_file_name_prepend + "game_data.tres") |
|
|
|
|
|
|
|
|
func _on_quick_save() -> void: |
|
|
func _on_quick_save() -> void: |
|
|
if not _load_save_level_data_component(): return |
|
|
|
|
|
|
|
|
if not _load_save_settings(): return |
|
|
|
|
|
|
|
|
_save_game_as_resource("Quick Save", _save_level_data_component.settings.quicksave_file_name_prepend + "game_data.tres") |
|
|
|
|
|
|
|
|
_save_game_as_resource("Quick Save", _save_game_settings.quicksave_file_name_prepend + "game_data.tres") |
|
|
|
|
|
|
|
|
## Save the game, with a filename of `<save_prepend><current_date>.tres |
|
|
## Save the game, with a filename of `<save_prepend><current_date>.tres |
|
|
func _on_save_game_as_resource(save_name: String) -> void: |
|
|
func _on_save_game_as_resource(save_name: String) -> void: |
|
|
if not _load_save_level_data_component(): return |
|
|
|
|
|
|
|
|
if not _load_save_settings(): return |
|
|
|
|
|
|
|
|
var current_date: String = Time.get_datetime_string_from_system().replace(":", "") |
|
|
var current_date: String = Time.get_datetime_string_from_system().replace(":", "") |
|
|
var _filename: String = _save_level_data_component.settings.save_file_name_prepend + current_date + ".tres" |
|
|
|
|
|
|
|
|
var _filename: String = _save_game_settings.save_file_name_prepend + current_date + ".tres" |
|
|
|
|
|
|
|
|
_loaded_save_resource.save_name = save_name |
|
|
_loaded_save_resource.save_name = save_name |
|
|
_save_game_as_resource(save_name, _filename) |
|
|
_save_game_as_resource(save_name, _filename) |
|
|