mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
Added UndoRedo support for importing images as frames and layers
This commit is contained in:
parent
40a01f1da3
commit
76b7014d84
|
@ -357,6 +357,7 @@ func open_image_as_spritesheet(path : String, image : Image, horizontal : int, v
|
|||
func open_image_as_new_frame(image : Image, layer_index := 0) -> void:
|
||||
var project = Global.current_project
|
||||
image.crop(project.size.x, project.size.y)
|
||||
var new_frames : Array = project.frames.duplicate()
|
||||
|
||||
var frame := Frame.new()
|
||||
for i in project.layers.size():
|
||||
|
@ -370,15 +371,27 @@ func open_image_as_new_frame(image : Image, layer_index := 0) -> void:
|
|||
empty_image.lock()
|
||||
frame.cels.append(Cel.new(empty_image, 1))
|
||||
|
||||
project.frames.append(frame)
|
||||
project.frames = project.frames # Just to call frames_changed()
|
||||
project.current_frame = project.frames.size() - 1
|
||||
project.current_layer = layer_index
|
||||
new_frames.append(frame)
|
||||
|
||||
Global.current_project.undos += 1
|
||||
Global.current_project.undo_redo.create_action("Add Frame")
|
||||
Global.current_project.undo_redo.add_do_method(Global, "redo")
|
||||
Global.current_project.undo_redo.add_undo_method(Global, "undo")
|
||||
|
||||
Global.current_project.undo_redo.add_do_property(project, "frames", new_frames)
|
||||
Global.current_project.undo_redo.add_do_property(project, "current_frame", new_frames.size() - 1)
|
||||
Global.current_project.undo_redo.add_do_property(project, "current_layer", layer_index)
|
||||
|
||||
Global.current_project.undo_redo.add_undo_property(project, "frames", project.frames)
|
||||
Global.current_project.undo_redo.add_undo_property(project, "current_frame", project.current_frame)
|
||||
Global.current_project.undo_redo.add_undo_property(project, "current_layer", project.current_layer)
|
||||
Global.current_project.undo_redo.commit_action()
|
||||
|
||||
|
||||
func open_image_as_new_layer(image : Image, file_name : String, frame_index := 0) -> void:
|
||||
var project = Global.current_project
|
||||
image.crop(project.size.x, project.size.y)
|
||||
var new_layers : Array = Global.current_project.layers.duplicate()
|
||||
|
||||
var layer := Layer.new(file_name)
|
||||
for i in project.frames.size():
|
||||
|
@ -392,10 +405,21 @@ func open_image_as_new_layer(image : Image, file_name : String, frame_index := 0
|
|||
empty_image.lock()
|
||||
project.frames[i].cels.append(Cel.new(empty_image, 1))
|
||||
|
||||
project.layers.append(layer)
|
||||
project.layers = project.layers # Just to call layers_changed()
|
||||
project.current_layer = project.layers.size() - 1
|
||||
project.current_frame = frame_index
|
||||
new_layers.append(layer)
|
||||
|
||||
Global.current_project.undos += 1
|
||||
Global.current_project.undo_redo.create_action("Add Layer")
|
||||
Global.current_project.undo_redo.add_do_property(project, "current_layer", new_layers.size() - 1)
|
||||
Global.current_project.undo_redo.add_do_property(project, "layers", new_layers)
|
||||
Global.current_project.undo_redo.add_do_property(project, "current_frame", frame_index)
|
||||
|
||||
Global.current_project.undo_redo.add_undo_property(project, "current_layer", project.current_layer)
|
||||
Global.current_project.undo_redo.add_undo_property(project, "layers", project.layers)
|
||||
Global.current_project.undo_redo.add_undo_property(project, "current_frame", project.current_frame)
|
||||
|
||||
Global.current_project.undo_redo.add_undo_method(Global, "undo")
|
||||
Global.current_project.undo_redo.add_do_method(Global, "redo")
|
||||
Global.current_project.undo_redo.commit_action()
|
||||
|
||||
|
||||
func set_new_tab(project : Project, path : String) -> void:
|
||||
|
|
|
@ -9,5 +9,5 @@ func _draw() -> void:
|
|||
# Draw current frame layers
|
||||
for i in range(current_cels.size()):
|
||||
var modulate_color := Color(1, 1, 1, current_cels[i].opacity)
|
||||
if current_project.layers[i].visible: # if it's visible
|
||||
if i < current_project.layers.size() and current_project.layers[i].visible: # if it's visible
|
||||
draw_texture(current_cels[i].image_texture, Vector2.ZERO, modulate_color)
|
||||
|
|
Loading…
Reference in a new issue