mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-31 07:29:49 +00:00
Fix crash when importing .tres files that are not palettes
This commit is contained in:
parent
008683a33a
commit
e0d2393eb2
|
@ -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 ""
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue