From caf6ba1e0d5255c3827aceae2de33cff5109c397 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 29 Nov 2020 15:08:22 +0100 Subject: [PATCH] OpenSave in no longer a singleton either. --- project.godot | 1 - src/Autoload/Global.gd | 7 ++++++- src/Classes/Project.gd | 10 +++++----- src/Main.gd | 28 ++++++++++++++-------------- src/Preferences/PreferencesDialog.gd | 2 +- src/UI/Dialogs/PreviewDialog.gd | 8 ++++---- src/UI/Tabs.gd | 18 +++++++++--------- src/UI/TopMenuContainer.gd | 2 +- 8 files changed, 40 insertions(+), 36 deletions(-) diff --git a/project.godot b/project.godot index f802ae7..15552af 100644 --- a/project.godot +++ b/project.godot @@ -122,7 +122,6 @@ driver="Dummy" [autoload] DrawGD="*res://src/Autoload/Global.gd" -OpenSave="*res://src/Autoload/OpenSave.gd" [debug] diff --git a/src/Autoload/Global.gd b/src/Autoload/Global.gd index 2a085bb..6201468 100644 --- a/src/Autoload/Global.gd +++ b/src/Autoload/Global.gd @@ -169,6 +169,8 @@ onready var current_version : String = ProjectSettings.get_setting("application/ var tools_script = preload("res://src/Autoload/Tools.gd") var tools = null +var opensave_script = preload("res://src/Autoload/OpenSave.gd") +var opensave = null func _ready() -> void: randomize() @@ -179,6 +181,9 @@ func _ready() -> void: tools = tools_script.new() add_child(tools) + + opensave = opensave_script.new() + add_child(opensave) # The fact that root_dir is set earlier than this is important # XDGDataDirs depends on it nyaa @@ -507,5 +512,5 @@ func _exit_tree() -> void: var i := 0 for project in projects: project.undo_redo.free() - OpenSave.remove_backup(i) + DrawGD.opensave.remove_backup(i) i += 1 diff --git a/src/Classes/Project.gd b/src/Classes/Project.gd index 93e34b8..ca6976e 100644 --- a/src/Classes/Project.gd +++ b/src/Classes/Project.gd @@ -44,8 +44,8 @@ func _init(_frames := [], _name := tr("untitled"), _size := Vector2(64, 64)) -> undo_redo = UndoRedo.new() DrawGD.tabs.add_tab(name) - OpenSave.current_save_paths.append("") - OpenSave.backup_save_paths.append("") + DrawGD.opensave.current_save_paths.append("") + DrawGD.opensave.backup_save_paths.append("") x_symmetry_point = size.x / 2 y_symmetry_point = size.y / 2 @@ -185,7 +185,7 @@ func change_project() -> void: if has_changed: DrawGD.window_title = DrawGD.window_title + "(*)" - var save_path = OpenSave.current_save_paths[DrawGD.current_project_index] + var save_path = DrawGD.opensave.current_save_paths[DrawGD.current_project_index] if save_path != "": DrawGD.open_sprites_dialog.current_path = save_path DrawGD.save_sprites_dialog.current_path = save_path @@ -262,7 +262,7 @@ func serialize() -> Dictionary: "name" : name, "size_x" : size.x, "size_y" : size.y, - "save_path" : OpenSave.current_save_paths[DrawGD.projects.find(self)], + "save_path" : DrawGD.opensave.current_save_paths[DrawGD.projects.find(self)], "layers" : layer_data, "tags" : tag_data, "guides" : guide_data, @@ -285,7 +285,7 @@ func deserialize(dict : Dictionary) -> void: size.y = dict.size_y select_all_pixels() if dict.has("save_path"): - OpenSave.current_save_paths[DrawGD.projects.find(self)] = dict.save_path + DrawGD.opensave.current_save_paths[DrawGD.projects.find(self)] = dict.save_path if dict.has("frames"): for frame in dict.frames: var cels := [] diff --git a/src/Main.gd b/src/Main.gd index f672e7c..03217ee 100644 --- a/src/Main.gd +++ b/src/Main.gd @@ -42,7 +42,7 @@ func _ready() -> void: # If the user wants to run Pixelorama with arguments in terminal mode # or open files with Pixelorama directly, then handle that if OS.get_cmdline_args(): - OpenSave.handle_loading_files(OS.get_cmdline_args()) + DrawGD.opensave.handle_loading_files(OS.get_cmdline_args()) get_tree().connect("files_dropped", self, "_on_files_dropped") @@ -99,7 +99,7 @@ func handle_backup() -> void: for p_path in project_paths: backup_paths.append(DrawGD.config_cache.get_value("backups", p_path)) # Temporatily stop autosave until user confirms backup - OpenSave.autosave_timer.stop() + DrawGD.opensave.autosave_timer.stop() backup_confirmation.dialog_text = tr(backup_confirmation.dialog_text) % project_paths backup_confirmation.connect("confirmed", self, "_on_BackupConfirmation_confirmed", [project_paths, backup_paths]) backup_confirmation.get_cancel().connect("pressed", self, "_on_BackupConfirmation_delete", [project_paths, backup_paths]) @@ -120,7 +120,7 @@ func _notification(what : int) -> void: func _on_files_dropped(_files : PoolStringArray, _screen : int) -> void: - OpenSave.handle_loading_files(_files) + DrawGD.opensave.handle_loading_files(_files) func load_last_project() -> void: @@ -132,7 +132,7 @@ func load_last_project() -> void: var file_path = DrawGD.config_cache.get_value("preferences", "last_project_path") var file_check := File.new() if file_check.file_exists(file_path): # If yes then load the file - OpenSave.open_pxo_file(file_path) + DrawGD.opensave.open_pxo_file(file_path) else: # If file doesn't exist on disk then warn user about this DrawGD.error_dialog.set_text("Cannot find last project file.") @@ -141,12 +141,12 @@ func load_last_project() -> void: func _on_OpenSprite_file_selected(path : String) -> void: - OpenSave.handle_loading_files([path]) + DrawGD.opensave.handle_loading_files([path]) func _on_SaveSprite_file_selected(path : String) -> void: var zstd = DrawGD.save_sprites_dialog.get_vbox().get_node("ZSTDCompression").pressed - OpenSave.save_pxo_file(path, false, zstd) + DrawGD.opensave.save_pxo_file(path, false, zstd) if is_quitting_on_save: _on_QuitDialog_confirmed() @@ -156,7 +156,7 @@ func _on_SaveSpriteHTML5_confirmed() -> void: var file_name = DrawGD.save_sprites_html5_dialog.get_node("FileNameContainer/FileNameLineEdit").text file_name += ".pxo" var path = "user://".plus_file(file_name) - OpenSave.save_pxo_file(path, false, false) + DrawGD.opensave.save_pxo_file(path, false, false) func _on_OpenSprite_popup_hide() -> void: @@ -194,19 +194,19 @@ func _on_QuitDialog_confirmed() -> void: func _on_BackupConfirmation_confirmed(project_paths : Array, backup_paths : Array) -> void: - OpenSave.reload_backup_file(project_paths, backup_paths) - OpenSave.autosave_timer.start() - Export.file_name = OpenSave.current_save_paths[0].get_file().trim_suffix(".pxo") - Export.directory_path = OpenSave.current_save_paths[0].get_base_dir() + DrawGD.opensave.reload_backup_file(project_paths, backup_paths) + DrawGD.opensave.autosave_timer.start() + Export.file_name = DrawGD.opensave.current_save_paths[0].get_file().trim_suffix(".pxo") + Export.directory_path = DrawGD.opensave.current_save_paths[0].get_base_dir() Export.was_exported = false - DrawGD.file_menu.get_popup().set_item_text(3, tr("Save") + " %s" % OpenSave.current_save_paths[0].get_file()) + DrawGD.file_menu.get_popup().set_item_text(3, tr("Save") + " %s" % DrawGD.opensave.current_save_paths[0].get_file()) DrawGD.file_menu.get_popup().set_item_text(5, tr("Export")) func _on_BackupConfirmation_delete(project_paths : Array, backup_paths : Array) -> void: for i in range(project_paths.size()): - OpenSave.remove_backup_by_path(project_paths[i], backup_paths[i]) - OpenSave.autosave_timer.start() + DrawGD.opensave.remove_backup_by_path(project_paths[i], backup_paths[i]) + DrawGD.opensave.autosave_timer.start() # Reopen last project if DrawGD.open_last_project: load_last_project() diff --git a/src/Preferences/PreferencesDialog.gd b/src/Preferences/PreferencesDialog.gd index 5575c34..2df6640 100644 --- a/src/Preferences/PreferencesDialog.gd +++ b/src/Preferences/PreferencesDialog.gd @@ -113,7 +113,7 @@ func _on_Preference_item_selected(id : int, prop : String, default_value, restor func preference_update(prop : String) -> void: if prop in ["autosave_interval", "enable_autosave"]: - OpenSave.update_autosave() + DrawGD.opensave.update_autosave() autosave_interval.editable = DrawGD.enable_autosave if autosave_interval.editable: autosave_interval.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND diff --git a/src/UI/Dialogs/PreviewDialog.gd b/src/UI/Dialogs/PreviewDialog.gd index 686c925..97d7f66 100644 --- a/src/UI/Dialogs/PreviewDialog.gd +++ b/src/UI/Dialogs/PreviewDialog.gd @@ -42,18 +42,18 @@ func _on_PreviewDialog_popup_hide() -> void: func _on_PreviewDialog_confirmed() -> void: if current_import_option == ImageImportOptions.NEW_TAB: - OpenSave.open_image_as_new_tab(path, image) + DrawGD.opensave.open_image_as_new_tab(path, image) elif current_import_option == ImageImportOptions.SPRITESHEET: - OpenSave.open_image_as_spritesheet(path, image, spritesheet_horizontal, spritesheet_vertical) + DrawGD.opensave.open_image_as_spritesheet(path, image, spritesheet_horizontal, spritesheet_vertical) elif current_import_option == ImageImportOptions.NEW_FRAME: var layer_index : int = new_frame_options.get_node("AtLayerSpinbox").value - OpenSave.open_image_as_new_frame(image, layer_index) + DrawGD.opensave.open_image_as_new_frame(image, layer_index) elif current_import_option == ImageImportOptions.NEW_LAYER: var frame_index : int = new_layer_options.get_node("AtFrameSpinbox").value - 1 - OpenSave.open_image_as_new_layer(image, path.get_basename().get_file(), frame_index) + DrawGD.opensave.open_image_as_new_layer(image, path.get_basename().get_file(), frame_index) elif current_import_option == ImageImportOptions.PALETTE: DrawGD.palette_container.import_image_palette(path, image) diff --git a/src/UI/Tabs.gd b/src/UI/Tabs.gd index 29fe607..436ce30 100644 --- a/src/UI/Tabs.gd +++ b/src/UI/Tabs.gd @@ -24,20 +24,20 @@ func _on_Tabs_reposition_active_tab_request(idx_to : int) -> void: DrawGD.projects.insert(idx_to, temp) # Change save paths - var temp_save_path = OpenSave.current_save_paths[DrawGD.current_project_index] - OpenSave.current_save_paths[DrawGD.current_project_index] = OpenSave.current_save_paths[idx_to] - OpenSave.current_save_paths[idx_to] = temp_save_path - var temp_backup_path = OpenSave.backup_save_paths[DrawGD.current_project_index] - OpenSave.backup_save_paths[DrawGD.current_project_index] = OpenSave.backup_save_paths[idx_to] - OpenSave.backup_save_paths[idx_to] = temp_backup_path + var temp_save_path = DrawGD.opensave.current_save_paths[DrawGD.current_project_index] + DrawGD.opensave.current_save_paths[DrawGD.current_project_index] = DrawGD.opensave.current_save_paths[idx_to] + DrawGD.opensave.current_save_paths[idx_to] = temp_save_path + var temp_backup_path = DrawGD.opensave.backup_save_paths[DrawGD.current_project_index] + DrawGD.opensave.backup_save_paths[DrawGD.current_project_index] = DrawGD.opensave.backup_save_paths[idx_to] + DrawGD.opensave.backup_save_paths[idx_to] = temp_backup_path func delete_tab(tab : int) -> void: remove_tab(tab) DrawGD.projects[tab].undo_redo.free() - OpenSave.remove_backup(tab) - OpenSave.current_save_paths.remove(tab) - OpenSave.backup_save_paths.remove(tab) + DrawGD.opensave.remove_backup(tab) + DrawGD.opensave.current_save_paths.remove(tab) + DrawGD.opensave.backup_save_paths.remove(tab) DrawGD.projects.remove(tab) if tab > 0: DrawGD.current_project_index -= 1 diff --git a/src/UI/TopMenuContainer.gd b/src/UI/TopMenuContainer.gd index 8160b4d..82af56f 100644 --- a/src/UI/TopMenuContainer.gd +++ b/src/UI/TopMenuContainer.gd @@ -155,7 +155,7 @@ func on_open_last_project_file_menu_option_pressed() -> void: func save_project_file() -> void: DrawGD.control.is_quitting_on_save = false - var path = OpenSave.current_save_paths[DrawGD.current_project_index] + var path = DrawGD.opensave.current_save_paths[DrawGD.current_project_index] if path == "": if OS.get_name() == "HTML5": DrawGD.save_sprites_html5_dialog.popup_centered()