diff --git a/Translations/Translations.pot b/Translations/Translations.pot index b6dbe59e3..d8950d2d8 100644 --- a/Translations/Translations.pot +++ b/Translations/Translations.pot @@ -307,10 +307,17 @@ msgstr "" msgid "Exporting in progress..." msgstr "" +msgid "Can't load file '%s'." +msgstr "" + msgid "Can't load file '%s'.\n" "Error code: %s" msgstr "" +msgid "Can't load file '%s'.\n" +"This is not a valid palette file." +msgstr "" + msgid "Frame" msgstr "" diff --git a/src/Autoload/OpenSave.gd b/src/Autoload/OpenSave.gd index 22b4005d2..b3ac9f57e 100644 --- a/src/Autoload/OpenSave.gd +++ b/src/Autoload/OpenSave.gd @@ -23,8 +23,20 @@ func handle_loading_files(files: PoolStringArray) -> void: var file_ext: String = file.get_extension().to_lower() if file_ext == "pxo": # Pixelorama project file open_pxo_file(file) - elif file_ext == "tres" or file_ext == "gpl" or file_ext == "pal" or file_ext == "json": - Palettes.import_palette(file) + + elif file_ext == "tres": # Godot resource file + var resource = load(file) + if resource is Palette: + Palettes.import_palette(resource, file.get_file()) + else: + var file_name: String = file.get_file() + Global.error_dialog.set_text(tr("Can't load file '%s'.") % [file_name]) + Global.error_dialog.popup_centered() + Global.dialog_open(true) + + elif file_ext == "gpl" or file_ext == "pal" or file_ext == "json": + Palettes.import_palette_from_path(file) + else: # Image files var image := Image.new() var err := image.load(file) diff --git a/src/Autoload/Palettes.gd b/src/Autoload/Palettes.gd index 053e4d682..60ffc2ada 100644 --- a/src/Autoload/Palettes.gd +++ b/src/Autoload/Palettes.gd @@ -1,3 +1,4 @@ +# gdlint: ignore=max-public-methods extends Node # Presets for creating a new palette @@ -428,15 +429,13 @@ func _get_best_palette_file_location(looking_paths: Array, fname: String): # -> return null -func import_palette(path: String) -> void: +func import_palette_from_path(path: String) -> void: if does_palette_exist(path.get_basename().get_file()): # If there is a palette with same name ignore import for now return var palette: Palette = null match path.to_lower().get_extension(): - "tres": - palette = load(path) "gpl": var file = File.new() if file.file_exists(path): @@ -464,12 +463,25 @@ func import_palette(path: String) -> void: file.close() palette = _import_json_palette(text) + import_palette(palette, path.get_file()) + + +func import_palette(palette: Palette, file_name: String) -> void: + if does_palette_exist(file_name.get_basename()): + # If there is a palette with same name ignore import for now + return if palette: var palette_path := _save_palette(palette) palettes[palette_path] = palette select_palette(palette_path) Global.palette_panel.setup_palettes_selector() Global.palette_panel.select_palette(palette_path) + else: + Global.error_dialog.set_text( + tr("Can't load file '%s'.\nThis is not a valid palette file.") % [file_name] + ) + Global.error_dialog.popup_centered() + Global.dialog_open(true) func _import_gpl(path: String, text: String) -> Palette: diff --git a/src/UI/Dialogs/PreviewDialog.gd b/src/UI/Dialogs/PreviewDialog.gd index 99efe37c6..1aec00ce9 100644 --- a/src/UI/Dialogs/PreviewDialog.gd +++ b/src/UI/Dialogs/PreviewDialog.gd @@ -114,7 +114,7 @@ func _on_PreviewDialog_confirmed() -> void: OpenSave.open_image_as_new_layer(image, path.get_basename().get_file(), frame_index) elif current_import_option == ImageImportOptions.PALETTE: - Palettes.import_palette(path) + Palettes.import_palette_from_path(path) elif current_import_option == ImageImportOptions.BRUSH: add_brush()