mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-02-20 12:33:14 +00:00
Remove handle_undo() and handle_redo() from Canvas.gd
Getting rid of some old, unneeded code.
This commit is contained in:
parent
0259f7523b
commit
f7ef4a4283
2 changed files with 11 additions and 83 deletions
|
@ -3,8 +3,7 @@ extends Node2D
|
|||
|
||||
var fill_color := Color(0, 0, 0, 0)
|
||||
var current_pixel := Vector2.ZERO
|
||||
var can_undo := true
|
||||
var sprite_changed_this_frame := false # for optimization purposes
|
||||
var sprite_changed_this_frame := false # For optimization purposes
|
||||
var move_preview_location := Vector2.ZERO
|
||||
|
||||
onready var currently_visible_frame: Viewport = $CurrentlyVisibleFrame
|
||||
|
@ -17,7 +16,6 @@ onready var indicators = $Indicators
|
|||
onready var previews = $Previews
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
$OnionPast.type = $OnionPast.PAST
|
||||
$OnionPast.blue_red_color = Color.blue
|
||||
|
@ -136,84 +134,6 @@ func new_empty_frame(
|
|||
return frame
|
||||
|
||||
|
||||
func handle_undo(
|
||||
action: String, project: Project = Global.current_project, layer_index := -2, frame_index := -2
|
||||
) -> void:
|
||||
if !can_undo:
|
||||
return
|
||||
|
||||
if layer_index <= -2:
|
||||
layer_index = project.current_layer
|
||||
if frame_index <= -2:
|
||||
frame_index = project.current_frame
|
||||
|
||||
var cels := []
|
||||
var frames := []
|
||||
var layers := []
|
||||
if frame_index == -1:
|
||||
frames = project.frames
|
||||
else:
|
||||
frames.append(project.frames[frame_index])
|
||||
|
||||
if layer_index == -1:
|
||||
layers = project.layers
|
||||
else:
|
||||
layers.append(project.layers[layer_index])
|
||||
|
||||
for f in frames:
|
||||
for l in layers:
|
||||
var index = project.layers.find(l)
|
||||
cels.append(f.cels[index])
|
||||
|
||||
project.undos += 1
|
||||
project.undo_redo.create_action(action)
|
||||
for cel in cels:
|
||||
# If we don't unlock the image, it doesn't work properly
|
||||
cel.image.unlock()
|
||||
var data = cel.image.data
|
||||
cel.image.lock()
|
||||
project.undo_redo.add_undo_property(cel.image, "data", data)
|
||||
project.undo_redo.add_undo_method(Global, "undo", frame_index, layer_index, project)
|
||||
|
||||
can_undo = false
|
||||
|
||||
|
||||
func handle_redo(
|
||||
_action: String, project: Project = Global.current_project, layer_index := -2, frame_index := -2
|
||||
) -> void:
|
||||
can_undo = true
|
||||
if project.undos < project.undo_redo.get_version():
|
||||
return
|
||||
|
||||
if layer_index <= -2:
|
||||
layer_index = project.current_layer
|
||||
if frame_index <= -2:
|
||||
frame_index = project.current_frame
|
||||
|
||||
var cels := []
|
||||
var frames := []
|
||||
var layers := []
|
||||
if frame_index == -1:
|
||||
frames = project.frames
|
||||
else:
|
||||
frames.append(project.frames[frame_index])
|
||||
|
||||
if layer_index == -1:
|
||||
layers = project.layers
|
||||
else:
|
||||
layers.append(project.layers[layer_index])
|
||||
|
||||
for f in frames:
|
||||
for l in layers:
|
||||
var index = project.layers.find(l)
|
||||
cels.append(f.cels[index])
|
||||
|
||||
for cel in cels:
|
||||
project.undo_redo.add_do_property(cel.image, "data", cel.image.data)
|
||||
project.undo_redo.add_do_method(Global, "redo", frame_index, layer_index, project)
|
||||
project.undo_redo.commit_action()
|
||||
|
||||
|
||||
func update_texture(layer_i: int, frame_i := -1, project: Project = Global.current_project) -> void:
|
||||
if frame_i == -1:
|
||||
frame_i = project.current_frame
|
||||
|
|
|
@ -172,9 +172,17 @@ func _on_PopupMenu_id_pressed(id: int) -> void:
|
|||
func delete_cel_contents() -> void:
|
||||
if image.is_invisible():
|
||||
return
|
||||
Global.canvas.handle_undo("Draw", Global.current_project, layer, frame)
|
||||
var project = Global.current_project
|
||||
image.unlock()
|
||||
var data := image.data
|
||||
project.undos += 1
|
||||
project.undo_redo.create_action("Draw")
|
||||
project.undo_redo.add_undo_property(image, "data", data)
|
||||
project.undo_redo.add_undo_method(Global, "undo", frame, layer, project)
|
||||
image.fill(0)
|
||||
Global.canvas.handle_redo("Draw", Global.current_project, layer, frame)
|
||||
project.undo_redo.add_do_property(image, "data", image.data)
|
||||
project.undo_redo.add_do_method(Global, "redo", frame, layer, project)
|
||||
project.undo_redo.commit_action()
|
||||
|
||||
|
||||
func get_drag_data(_position) -> Array:
|
||||
|
|
Loading…
Add table
Reference in a new issue