|
@ -13,6 +13,9 @@ signal create_auto_save_file |
|
|
signal create_save_file(save_name: String) |
|
|
signal create_save_file(save_name: String) |
|
|
signal delete_save_file(filename: String) |
|
|
signal delete_save_file(filename: String) |
|
|
signal load_save_file(filename: String) |
|
|
signal load_save_file(filename: String) |
|
|
|
|
|
signal save_error(error_message: String) |
|
|
|
|
|
signal load_error(error_message: String) |
|
|
|
|
|
signal delete_error(error_message: String) |
|
|
signal quick_save |
|
|
signal quick_save |
|
|
signal quick_load |
|
|
signal quick_load |
|
|
signal open_save_list_ui |
|
|
signal open_save_list_ui |
|
@ -83,20 +86,17 @@ func list_saves(include_quick_saves: bool = true, include_auto_saves: bool = tru |
|
|
|
|
|
|
|
|
func load_game_save(resource_filename: String) -> void: |
|
|
func load_game_save(resource_filename: String) -> void: |
|
|
_load_game_resource(resource_filename) |
|
|
_load_game_resource(resource_filename) |
|
|
game_loaded.emit() |
|
|
|
|
|
|
|
|
|
|
|
func quick_save_game() -> void: |
|
|
func quick_save_game() -> void: |
|
|
if not _load_save_level_data_component(): return |
|
|
if not _load_save_level_data_component(): return |
|
|
|
|
|
|
|
|
_game_data_resource.save_name = "Quick Save" |
|
|
_game_data_resource.save_name = "Quick Save" |
|
|
_save_game_as_resource(_save_level_data_component.settings.quicksave_file_name) |
|
|
_save_game_as_resource(_save_level_data_component.settings.quicksave_file_name) |
|
|
game_saved.emit() |
|
|
|
|
|
|
|
|
|
|
|
func quick_load_game() -> void: |
|
|
func quick_load_game() -> void: |
|
|
if not _load_save_level_data_component(): return |
|
|
if not _load_save_level_data_component(): return |
|
|
|
|
|
|
|
|
_load_game_resource(_save_level_data_component.settings.quicksave_file_name) |
|
|
_load_game_resource(_save_level_data_component.settings.quicksave_file_name) |
|
|
game_loaded.emit() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Sort the save files list by date created, descending |
|
|
## Sort the save files list by date created, descending |
|
@ -133,12 +133,12 @@ func _load_game_resource(resource_filename: String) -> void: |
|
|
|
|
|
|
|
|
var save_game_file_path: String = _save_level_data_component.settings.save_game_data_path + resource_filename |
|
|
var save_game_file_path: String = _save_level_data_component.settings.save_game_data_path + resource_filename |
|
|
if !FileAccess.file_exists(save_game_file_path): |
|
|
if !FileAccess.file_exists(save_game_file_path): |
|
|
printerr("Failed to load save. File does not exist: ", save_game_file_path) |
|
|
|
|
|
|
|
|
load_error.emit("Failed to load save. File does not exist: %s" % save_game_file_path) |
|
|
return |
|
|
return |
|
|
|
|
|
|
|
|
_game_data_resource = ResourceLoader.load(save_game_file_path) |
|
|
_game_data_resource = ResourceLoader.load(save_game_file_path) |
|
|
if _game_data_resource == null: |
|
|
if _game_data_resource == null: |
|
|
printerr("Failed to load save. Unknown format? ", save_game_file_path) |
|
|
|
|
|
|
|
|
load_error.emit("Failed to load save. Unknown format? %s" % save_game_file_path) |
|
|
return |
|
|
return |
|
|
|
|
|
|
|
|
EntityManager.reset_world.emit() |
|
|
EntityManager.reset_world.emit() |
|
@ -148,6 +148,8 @@ func _load_game_resource(resource_filename: String) -> void: |
|
|
if resource is Node3DDataResource: |
|
|
if resource is Node3DDataResource: |
|
|
(resource as Node3DDataResource)._load_data(root_node) |
|
|
(resource as Node3DDataResource)._load_data(root_node) |
|
|
|
|
|
|
|
|
|
|
|
game_loaded.emit() |
|
|
|
|
|
|
|
|
func _save_game_as_resource(resource_filename: String) -> void: |
|
|
func _save_game_as_resource(resource_filename: String) -> void: |
|
|
if not _load_save_level_data_component(): return |
|
|
if not _load_save_level_data_component(): return |
|
|
|
|
|
|
|
@ -159,9 +161,11 @@ func _save_game_as_resource(resource_filename: String) -> void: |
|
|
|
|
|
|
|
|
var result: int = ResourceSaver.save(_game_data_resource, save_game_file_path) |
|
|
var result: int = ResourceSaver.save(_game_data_resource, save_game_file_path) |
|
|
if result != OK: |
|
|
if result != OK: |
|
|
printerr("Failed to save game (" , result, "): ", save_game_file_path) |
|
|
|
|
|
|
|
|
save_error.emit("Failed to save game (" , result, "): " + save_game_file_path) |
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
_take_save_screenshot(save_game_file_path) |
|
|
_take_save_screenshot(save_game_file_path) |
|
|
|
|
|
game_saved.emit() |
|
|
|
|
|
|
|
|
## Save the properties defined on the SaveDataComponents attached to various nodes (such as Block) |
|
|
## Save the properties defined on the SaveDataComponents attached to various nodes (such as Block) |
|
|
func _save_node_data() -> void: |
|
|
func _save_node_data() -> void: |
|
@ -204,7 +208,7 @@ func _on_save_game_as_resource(save_name: String) -> void: |
|
|
## Delete both the save file and the related screenshot |
|
|
## Delete both the save file and the related screenshot |
|
|
func _on_delete_save_file(filename: String) -> void: |
|
|
func _on_delete_save_file(filename: String) -> void: |
|
|
if filename.length() < 1: |
|
|
if filename.length() < 1: |
|
|
printerr("_on_delete_save_file(): 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_level_data_component.settings.save_game_data_path + filename |
|
|