mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-30 23:19:49 +00:00
Remove duplicate project-specific variables from Export
Removed `directory_path`, `file_name`, `file_format` and `was_exported` from Export.gd. These variables already exist on Project.gd, no need to have them twice.
This commit is contained in:
parent
c50239ff18
commit
7e15fc9d15
|
@ -24,13 +24,6 @@ var resize := 100
|
|||
var interpolation := 0 # Image.Interpolation
|
||||
var new_dir_for_each_frame_tag := false # we don't need to store this after export
|
||||
|
||||
# Export directory path and export file name
|
||||
var directory_path := ""
|
||||
var file_name := "untitled"
|
||||
var file_format: int = FileFormat.PNG
|
||||
|
||||
var was_exported := false
|
||||
|
||||
# Export coroutine signal
|
||||
var stop_export := false
|
||||
|
||||
|
@ -151,17 +144,17 @@ func export_processed_images(
|
|||
) -> bool:
|
||||
# Stop export if directory path or file name are not valid
|
||||
var dir := Directory.new()
|
||||
if not dir.dir_exists(directory_path) or not file_name.is_valid_filename():
|
||||
if not dir.dir_exists(directory_path) and file_name.is_valid_filename():
|
||||
if not dir.dir_exists(project.directory_path) or not project.file_name.is_valid_filename():
|
||||
if not dir.dir_exists(project.directory_path) and project.file_name.is_valid_filename():
|
||||
export_dialog.open_path_validation_alert_popup(0)
|
||||
elif not file_name.is_valid_filename() and dir.dir_exists(directory_path):
|
||||
elif not project.file_name.is_valid_filename() and dir.dir_exists(project.directory_path):
|
||||
export_dialog.open_path_validation_alert_popup(1)
|
||||
else:
|
||||
export_dialog.open_path_validation_alert_popup()
|
||||
return false
|
||||
|
||||
var multiple_files := false
|
||||
if current_tab == ExportTab.IMAGE and not is_single_file_format():
|
||||
if current_tab == ExportTab.IMAGE and not is_single_file_format(project):
|
||||
multiple_files = true if processed_images.size() > 1 else false
|
||||
# Check export paths
|
||||
var export_paths := []
|
||||
|
@ -174,7 +167,7 @@ func export_processed_images(
|
|||
if multiple_files and new_dir_for_each_frame_tag:
|
||||
var frame_tag_directory := Directory.new()
|
||||
if not frame_tag_directory.dir_exists(export_path.get_base_dir()):
|
||||
frame_tag_directory.open(directory_path)
|
||||
frame_tag_directory.open(project.directory_path)
|
||||
frame_tag_directory.make_dir(export_path.get_base_dir().get_file())
|
||||
|
||||
if not ignore_overwrites: # Check if the files already exist
|
||||
|
@ -185,7 +178,7 @@ func export_processed_images(
|
|||
paths_of_existing_files += export_path
|
||||
export_paths.append(export_path)
|
||||
# Only get one export path if single file animated image is exported
|
||||
if is_single_file_format():
|
||||
if is_single_file_format(project):
|
||||
break
|
||||
|
||||
if not paths_of_existing_files.empty(): # If files already exist
|
||||
|
@ -198,9 +191,9 @@ func export_processed_images(
|
|||
|
||||
scale_processed_images()
|
||||
|
||||
if is_single_file_format():
|
||||
if is_single_file_format(project):
|
||||
var exporter: BaseAnimationExporter
|
||||
if file_format == FileFormat.APNG:
|
||||
if project.file_format == FileFormat.APNG:
|
||||
exporter = APNGAnimationExporter.new()
|
||||
else:
|
||||
exporter = GIFAnimationExporter.new()
|
||||
|
@ -232,19 +225,19 @@ func export_processed_images(
|
|||
Global.dialog_open(true)
|
||||
|
||||
# Store settings for quick export and when the dialog is opened again
|
||||
was_exported = true
|
||||
var file_name_with_ext := project.file_name + file_format_string(project.file_format)
|
||||
project.was_exported = true
|
||||
if project.export_overwrite:
|
||||
Global.top_menu_container.file_menu.set_item_text(
|
||||
6, tr("Overwrite") + " %s" % (file_name + Export.file_format_string(file_format))
|
||||
Global.FileMenu.EXPORT, tr("Overwrite") + " %s" % file_name_with_ext
|
||||
)
|
||||
else:
|
||||
Global.top_menu_container.file_menu.set_item_text(
|
||||
6, tr("Export") + " %s" % (file_name + file_format_string(file_format))
|
||||
Global.FileMenu.EXPORT, tr("Export") + " %s" % file_name_with_ext
|
||||
)
|
||||
|
||||
# Only show when not exporting gif - gif export finishes in thread
|
||||
if not is_single_file_format():
|
||||
if not is_single_file_format(project):
|
||||
Global.notification_label("File(s) exported")
|
||||
return true
|
||||
|
||||
|
@ -318,14 +311,14 @@ func file_format_description(format_enum: int) -> String:
|
|||
return ""
|
||||
|
||||
|
||||
func is_single_file_format(format_enum: int = file_format) -> bool:
|
||||
func is_single_file_format(project := Global.current_project) -> bool:
|
||||
# True when exporting to .gif and .apng (and potentially video formats in the future)
|
||||
# False when exporting to .png, and other non-animated formats in the future
|
||||
return format_enum == FileFormat.GIF or format_enum == FileFormat.APNG
|
||||
return project.file_format == FileFormat.GIF or project.file_format == FileFormat.APNG
|
||||
|
||||
|
||||
func create_export_path(multifile: bool, project: Project, frame: int = 0) -> String:
|
||||
var path := file_name
|
||||
var path := project.file_name
|
||||
# Only append frame number when there are multiple files exported
|
||||
if multifile:
|
||||
var frame_tag_and_start_id := get_proccessed_image_animation_tag_and_start_id(
|
||||
|
@ -343,8 +336,8 @@ func create_export_path(multifile: bool, project: Project, frame: int = 0) -> St
|
|||
# Add frame tag if frame has one
|
||||
# (frame - start_id + 1) Makes frames id to start from 1 in each frame tag directory
|
||||
path += "_" + frame_tag_dir + "_" + String(frame - start_id + 1)
|
||||
return directory_path.plus_file(frame_tag_dir).plus_file(
|
||||
path + file_format_string(file_format)
|
||||
return project.directory_path.plus_file(frame_tag_dir).plus_file(
|
||||
path + file_format_string(project.file_format)
|
||||
)
|
||||
else:
|
||||
# Add frame tag if frame has one
|
||||
|
@ -353,7 +346,7 @@ func create_export_path(multifile: bool, project: Project, frame: int = 0) -> St
|
|||
else:
|
||||
path += "_" + String(frame)
|
||||
|
||||
return directory_path.plus_file(path + file_format_string(file_format))
|
||||
return project.directory_path.plus_file(path + file_format_string(project.file_format))
|
||||
|
||||
|
||||
func get_proccessed_image_animation_tag_and_start_id(
|
||||
|
|
|
@ -148,13 +148,13 @@ func open_pxo_file(path: String, untitled_backup: bool = false, replace_empty: b
|
|||
# Set last opened project path and save
|
||||
Global.config_cache.set_value("preferences", "last_project_path", path)
|
||||
Global.config_cache.save("user://cache.ini")
|
||||
Export.file_name = path.get_file().trim_suffix(".pxo")
|
||||
Export.directory_path = path.get_base_dir()
|
||||
new_project.directory_path = Export.directory_path
|
||||
new_project.file_name = Export.file_name
|
||||
Export.was_exported = false
|
||||
Global.top_menu_container.file_menu.set_item_text(4, tr("Save") + " %s" % path.get_file())
|
||||
Global.top_menu_container.file_menu.set_item_text(6, tr("Export"))
|
||||
new_project.directory_path = path.get_base_dir()
|
||||
new_project.file_name = path.get_file().trim_suffix(".pxo")
|
||||
new_project.was_exported = false
|
||||
Global.top_menu_container.file_menu.set_item_text(
|
||||
Global.FileMenu.SAVE, tr("Save") + " %s" % path.get_file()
|
||||
)
|
||||
Global.top_menu_container.file_menu.set_item_text(Global.FileMenu.EXPORT, tr("Export"))
|
||||
|
||||
save_project_to_recent_list(path)
|
||||
|
||||
|
@ -396,9 +396,11 @@ func save_pxo_file(
|
|||
Global.config_cache.set_value("preferences", "last_project_path", path)
|
||||
Global.config_cache.save("user://cache.ini")
|
||||
if !project.was_exported:
|
||||
Export.file_name = path.get_file().trim_suffix(".pxo")
|
||||
Export.directory_path = path.get_base_dir()
|
||||
Global.top_menu_container.file_menu.set_item_text(4, tr("Save") + " %s" % path.get_file())
|
||||
project.file_name = path.get_file().trim_suffix(".pxo")
|
||||
project.directory_path = path.get_base_dir()
|
||||
Global.top_menu_container.file_menu.set_item_text(
|
||||
Global.FileMenu.SAVE, tr("Save") + " %s" % path.get_file()
|
||||
)
|
||||
|
||||
save_project_to_recent_list(path)
|
||||
|
||||
|
@ -635,9 +637,6 @@ func set_new_imported_tab(project: Project, path: String) -> void:
|
|||
project.was_exported = true
|
||||
if path.get_extension().to_lower() == "png":
|
||||
project.export_overwrite = true
|
||||
Export.directory_path = directory_path
|
||||
Export.file_name = file_name
|
||||
Export.was_exported = true
|
||||
|
||||
Global.tabs.current_tab = Global.tabs.get_tab_count() - 1
|
||||
Global.canvas.camera_zoom()
|
||||
|
|
|
@ -194,26 +194,23 @@ func change_project() -> void:
|
|||
Global.open_sprites_dialog.current_path = save_path
|
||||
Global.save_sprites_dialog.current_path = save_path
|
||||
Global.top_menu_container.file_menu.set_item_text(
|
||||
4, tr("Save") + " %s" % save_path.get_file()
|
||||
Global.FileMenu.SAVE, tr("Save") + " %s" % save_path.get_file()
|
||||
)
|
||||
else:
|
||||
Global.top_menu_container.file_menu.set_item_text(4, tr("Save"))
|
||||
|
||||
Export.directory_path = directory_path
|
||||
Export.file_name = file_name
|
||||
Export.file_format = file_format
|
||||
Export.was_exported = was_exported
|
||||
Global.top_menu_container.file_menu.set_item_text(Global.FileMenu.SAVE, tr("Save"))
|
||||
|
||||
if !was_exported:
|
||||
Global.top_menu_container.file_menu.set_item_text(6, tr("Export"))
|
||||
Global.top_menu_container.file_menu.set_item_text(Global.FileMenu.EXPORT, tr("Export"))
|
||||
else:
|
||||
if export_overwrite:
|
||||
Global.top_menu_container.file_menu.set_item_text(
|
||||
6, tr("Overwrite") + " %s" % (file_name + Export.file_format_string(file_format))
|
||||
Global.FileMenu.EXPORT,
|
||||
tr("Overwrite") + " %s" % (file_name + Export.file_format_string(file_format))
|
||||
)
|
||||
else:
|
||||
Global.top_menu_container.file_menu.set_item_text(
|
||||
6, tr("Export") + " %s" % (file_name + Export.file_format_string(file_format))
|
||||
Global.FileMenu.EXPORT,
|
||||
tr("Export") + " %s" % (file_name + Export.file_format_string(file_format))
|
||||
)
|
||||
|
||||
for j in Tiles.MODE.values():
|
||||
|
|
10
src/Main.gd
10
src/Main.gd
|
@ -364,13 +364,13 @@ func _quit() -> void:
|
|||
|
||||
func _on_BackupConfirmation_confirmed(project_paths: Array, backup_paths: Array) -> void:
|
||||
OpenSave.reload_backup_file(project_paths, backup_paths)
|
||||
Export.file_name = OpenSave.current_save_paths[0].get_file().trim_suffix(".pxo")
|
||||
Export.directory_path = OpenSave.current_save_paths[0].get_base_dir()
|
||||
Export.was_exported = false
|
||||
Global.current_project.file_name = OpenSave.current_save_paths[0].get_file().trim_suffix(".pxo")
|
||||
Global.current_project.directory_path = OpenSave.current_save_paths[0].get_base_dir()
|
||||
Global.current_project.was_exported = false
|
||||
Global.top_menu_container.file_menu.set_item_text(
|
||||
4, tr("Save") + " %s" % OpenSave.current_save_paths[0].get_file()
|
||||
Global.FileMenu.SAVE, tr("Save") + " %s" % OpenSave.current_save_paths[0].get_file()
|
||||
)
|
||||
Global.top_menu_container.file_menu.set_item_text(6, tr("Export"))
|
||||
Global.top_menu_container.file_menu.set_item_text(Global.FileMenu.EXPORT, tr("Export"))
|
||||
|
||||
|
||||
func _on_BackupConfirmation_custom_action(
|
||||
|
|
|
@ -165,16 +165,17 @@ func set_file_format_selector() -> void:
|
|||
# Updates the suitable list of file formats. First is preferred.
|
||||
# Note that if the current format is in the list, it stays for consistency.
|
||||
func _set_file_format_selector_suitable_file_formats(formats: Array) -> void:
|
||||
var project: Project = Global.current_project
|
||||
file_format_options.clear()
|
||||
var needs_update := true
|
||||
for i in formats:
|
||||
if Export.file_format == i:
|
||||
if project.file_format == i:
|
||||
needs_update = false
|
||||
var label := Export.file_format_string(i) + "; " + Export.file_format_description(i)
|
||||
file_format_options.add_item(label, i)
|
||||
if needs_update:
|
||||
Export.file_format = formats[0]
|
||||
file_format_options.selected = file_format_options.get_item_index(Export.file_format)
|
||||
project.file_format = formats[0]
|
||||
file_format_options.selected = file_format_options.get_item_index(project.file_format)
|
||||
|
||||
|
||||
func create_frame_tag_list() -> void:
|
||||
|
@ -242,23 +243,24 @@ func set_export_progress_bar(value: float) -> void:
|
|||
|
||||
func _on_ExportDialog_about_to_show() -> void:
|
||||
Global.canvas.selection.transform_content_confirm()
|
||||
var project: Project = Global.current_project
|
||||
# If we're on HTML5, don't let the user change the directory path
|
||||
if OS.get_name() == "HTML5":
|
||||
get_tree().call_group("NotHTML5", "hide")
|
||||
Export.directory_path = "user://"
|
||||
project.directory_path = "user://"
|
||||
|
||||
if Export.directory_path.empty():
|
||||
Export.directory_path = Global.config_cache.get_value(
|
||||
if project.directory_path.empty():
|
||||
project.directory_path = Global.config_cache.get_value(
|
||||
"data", "current_dir", OS.get_system_dir(OS.SYSTEM_DIR_DESKTOP)
|
||||
)
|
||||
|
||||
# If export already occurred - sets GUI to show previous settings
|
||||
options_resize.value = Export.resize
|
||||
options_interpolation.selected = Export.interpolation
|
||||
path_line_edit.text = Export.directory_path
|
||||
path_dialog_popup.current_dir = Export.directory_path
|
||||
file_line_edit.text = Export.file_name
|
||||
file_format_options.selected = Export.file_format
|
||||
path_line_edit.text = project.directory_path
|
||||
path_dialog_popup.current_dir = project.directory_path
|
||||
file_line_edit.text = project.file_name
|
||||
file_format_options.selected = project.file_format
|
||||
show_tab()
|
||||
|
||||
# Set the size of the preview checker
|
||||
|
@ -317,24 +319,20 @@ func _on_PathButton_pressed() -> void:
|
|||
|
||||
func _on_PathLineEdit_text_changed(new_text: String) -> void:
|
||||
Global.current_project.directory_path = new_text
|
||||
Export.directory_path = new_text
|
||||
|
||||
|
||||
func _on_FileLineEdit_text_changed(new_text: String) -> void:
|
||||
Global.current_project.file_name = new_text
|
||||
Export.file_name = new_text
|
||||
|
||||
|
||||
func _on_FileDialog_dir_selected(dir: String) -> void:
|
||||
path_line_edit.text = dir
|
||||
Global.current_project.directory_path = dir
|
||||
Export.directory_path = dir
|
||||
|
||||
|
||||
func _on_FileFormat_item_selected(idx: int) -> void:
|
||||
var id := file_format_options.get_item_id(idx)
|
||||
Global.current_project.file_format = id
|
||||
Export.file_format = id
|
||||
if not Export.is_single_file_format():
|
||||
multiple_animations_directories.disabled = false
|
||||
frame_timer.stop()
|
||||
|
|
|
@ -392,7 +392,7 @@ func _save_project_file_as() -> void:
|
|||
|
||||
|
||||
func _export_file() -> void:
|
||||
if Export.was_exported == false:
|
||||
if Global.current_project.was_exported == false:
|
||||
_popup_dialog(Global.export_dialog)
|
||||
else:
|
||||
Export.external_export()
|
||||
|
|
Loading…
Reference in a new issue