1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 17:19:50 +00:00

Each Project has its own export path now

This could be buggy so it needs more testing.
This commit is contained in:
OverloadedOrama 2020-08-28 18:05:49 +03:00
parent 687819413d
commit 0a0bf62bcd
4 changed files with 48 additions and 66 deletions

View file

@ -38,20 +38,7 @@ var file_name := "untitled"
var file_format : int = FileFormat.PNG
enum FileFormat { PNG = 0, GIF = 1}
# Store all settings after export, enables a quick re-export with same settings
var was_exported : bool = false
var exported_tab : int
var exported_frame_number : int
var exported_frame_current_tag : int
var exported_orientation : int
var exported_lines_count : int
var exported_animation_type : int
var exported_direction : int
var exported_resize : int
var exported_interpolation : int
var exported_directory_path : String
var exported_file_name : String
var exported_file_format : int
# Export coroutine signal
var stop_export = false
@ -64,11 +51,22 @@ var export_progress := 0.0
onready var gif_export_thread := Thread.new()
func _exit_tree():
func _exit_tree() -> void:
if gif_export_thread.is_active():
gif_export_thread.wait_to_finish()
func external_export() -> void:
match current_tab:
ExportTab.FRAME:
process_frame()
ExportTab.SPRITESHEET:
process_spritesheet()
ExportTab.ANIMATION:
process_animation()
export_processed_images(true, Global.export_dialog)
func process_frame() -> void:
var frame = Global.current_project.frames[frame_number - 1]
var image := Image.new()
@ -187,16 +185,17 @@ func export_processed_images(ignore_overwrites: bool, export_dialog: AcceptDialo
gif_export_thread.start(self, "export_gif", {"export_dialog": export_dialog, "export_paths": export_paths})
else:
for i in range(processed_images.size()):
processed_images[i].unlock()
if OS.get_name() == "HTML5":
Html5FileExchange.save_image(processed_images[i], export_paths[i].get_file())
else:
var err = processed_images[i].save_png(export_paths[i])
if err != OK:
OS.alert("Can't save file")
OS.alert("Can't save file. Error code: %s" % err)
processed_images[i].lock()
# Store settings for quick export and when the dialog is opened again
was_exported = true
store_export_settings()
Global.file_menu.get_popup().set_item_text(5, tr("Export") + " %s" % (file_name + file_format_string(file_format)))
# Only show when not exporting gif - gif export finishes in thread
@ -328,35 +327,3 @@ func blend_layers(image : Image, frame : Frame, origin : Vector2 = Vector2(0, 0)
func frames_divided_by_spritesheet_lines() -> int:
return int(ceil(number_of_frames / float(lines_count)))
func store_export_settings() -> void:
exported_tab = current_tab
exported_frame_number = frame_number
exported_frame_current_tag = frame_current_tag
exported_orientation = orientation
exported_lines_count = lines_count
exported_animation_type = animation_type
exported_direction = direction
exported_resize = resize
exported_interpolation = interpolation
exported_directory_path = directory_path
exported_file_name = file_name
exported_file_format = file_format
# Fill the dialog with previous export settings
func restore_previous_export_settings() -> void:
current_tab = exported_tab
frame_number = exported_frame_number if exported_frame_number <= Global.current_project.frames.size() else Global.current_project.frames.size()
frame_current_tag = exported_frame_current_tag if exported_frame_current_tag <= Global.current_project.animation_tags.size() else 0
orientation = exported_orientation
lines_count = exported_lines_count
animation_type = exported_animation_type
direction = exported_direction
resize = exported_resize
interpolation = exported_interpolation
directory_path = exported_directory_path
file_name = exported_file_name
file_format = exported_file_format

View file

@ -28,6 +28,11 @@ var selected_rect := Rect2(0, 0, 0, 0) setget _set_selected_rect
var cameras_zoom := [Vector2(0.15, 0.15), Vector2(0.15, 0.15), Vector2(0.15, 0.15)] # Array of Vector2
var cameras_offset := [Vector2.ZERO, Vector2.ZERO, Vector2.ZERO] # Array of Vector2
# Export directory path and export file name
var directory_path := ""
var file_name := "untitled"
var file_format : int = Export.FileFormat.PNG
func _init(_frames := [], _name := tr("untitled"), _size := Vector2(64, 64)) -> void:
frames = _frames
@ -60,6 +65,11 @@ func _init(_frames := [], _name := tr("untitled"), _size := Vector2(64, 64)) ->
y_symmetry_axis.add_point(Vector2(x_symmetry_point, 19999))
Global.canvas.add_child(y_symmetry_axis)
if OS.get_name() == "HTML5":
directory_path = "user://"
else:
directory_path = OS.get_system_dir(OS.SYSTEM_DIR_DESKTOP)
func select_all_pixels() -> void:
clear_selection()
@ -179,6 +189,15 @@ func change_project() -> void:
else:
Global.file_menu.get_popup().set_item_text(3, tr("Save"))
Export.directory_path = directory_path
Export.file_name = file_name
Export.file_format = file_format
if directory_path.empty():
Global.file_menu.get_popup().set_item_text(5, tr("Export"))
else:
Global.file_menu.get_popup().set_item_text(5, tr("Export") + " %s" % (file_name + Export.file_format_string(file_format)))
func serialize() -> Dictionary:
var layer_data := []
@ -246,6 +265,9 @@ func serialize() -> Dictionary:
"symmetry_points" : [x_symmetry_point, y_symmetry_point],
"frames" : frame_data,
"brushes" : brush_data,
"export_directory_path" : directory_path,
"export_file_name" : file_name,
"export_file_format" : file_format,
}
return project_data
@ -301,6 +323,12 @@ func deserialize(dict : Dictionary) -> void:
x_symmetry_axis.points[1].y = floor(y_symmetry_point / 2 + 1)
y_symmetry_axis.points[0].x = floor(x_symmetry_point / 2 + 1)
y_symmetry_axis.points[1].x = floor(x_symmetry_point / 2 + 1)
if dict.has("export_directory_path"):
directory_path = dict.export_directory_path
if dict.has("export_file_name"):
file_name = dict.export_file_name
if dict.has("export_file_format"):
file_format = dict.export_file_format
func name_changed(value : String) -> void:

View file

@ -99,19 +99,6 @@ func show_tab() -> void:
tabs.current_tab = Export.current_tab
func external_export() -> void:
Export.restore_previous_export_settings()
match Export.current_tab:
Export.ExportTab.FRAME:
Export.process_frame()
Export.ExportTab.SPRITESHEET:
Export.process_spritesheet()
Export.ExportTab.ANIMATION:
Export.process_animation()
if Export.export_processed_images(true, self):
hide()
func set_preview() -> void:
remove_previews()
if Export.processed_images.size() == 1 and Export.current_tab != Export.ExportTab.ANIMATION:
@ -234,10 +221,6 @@ func set_export_progress_bar(value: float) -> void:
func _on_ExportDialog_about_to_show() -> void:
# If export already occured - fill the dialog with previous export settings
if Export.was_exported:
Export.restore_previous_export_settings()
# If we're on HTML5, don't let the user change the directory path
if OS.get_name() == "HTML5":
path_container.visible = false
@ -333,19 +316,23 @@ 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(id : int) -> void:
Global.current_project.file_format = id
Export.file_format = id

View file

@ -198,7 +198,7 @@ func export_file() -> void:
Global.export_dialog.popup_centered()
Global.dialog_open(true)
else:
Global.export_dialog.external_export()
Export.external_export()
func edit_menu_id_pressed(id : int) -> void: