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

Fixed issue with linked cels where, if you had linked cels in one layer and then linked more cels of the same frame in another layer, their previews did not update automatically

Cel's image_texture was being reset due to the creation of new Cel instances in CelButton.gd (line 113)
This commit is contained in:
Manolis Papadeas 2021-07-22 02:25:00 +03:00
parent 9bec8f1b09
commit 57bb7929df
2 changed files with 16 additions and 16 deletions

View file

@ -4,18 +4,15 @@ class_name Cel extends Reference
# The "image" variable is where the image data of each cel are.
var image : Image setget image_changed
var image : Image
var image_texture : ImageTexture
var opacity : float
func _init(_image := Image.new(), _opacity := 1.0) -> void:
image_texture = ImageTexture.new()
self.image = _image
func _init(_image := Image.new(), _opacity := 1.0, _image_texture : ImageTexture = null) -> void:
if _image_texture:
image_texture = _image_texture
else:
image_texture = ImageTexture.new()
image = _image
opacity = _opacity
func image_changed(value : Image) -> void:
image = value
if !image.is_empty():
image_texture.create_from_image(image, 0)

View file

@ -100,24 +100,27 @@ func _on_PopupMenu_id_pressed(ID : int) -> void:
delete_cel_contents()
MenuOptions.LINK:
var cel_index : int = Global.current_project.layers[layer].linked_cels.find(Global.current_project.frames[frame])
var f = Global.current_project.frames[frame]
var f : Frame = Global.current_project.frames[frame]
var cel_index : int = Global.current_project.layers[layer].linked_cels.find(f)
var new_layers : Array = Global.current_project.layers.duplicate()
# Loop through the array to create new classes for each element, so that they
# won't be the same as the original array's classes. Needed for undo/redo to work properly.
for i in new_layers.size():
var new_linked_cels = new_layers[i].linked_cels.duplicate()
var new_linked_cels : Array = new_layers[i].linked_cels.duplicate()
new_layers[i] = Layer.new(new_layers[i].name, new_layers[i].visible, new_layers[i].locked, new_layers[i].frame_container, new_layers[i].new_cels_linked, new_linked_cels)
var new_cels : Array = f.cels.duplicate()
for i in new_cels.size():
new_cels[i] = Cel.new(new_cels[i].image, new_cels[i].opacity)
new_cels[i] = Cel.new(new_cels[i].image, new_cels[i].opacity, new_cels[i].image_texture)
if popup_menu.get_item_metadata(MenuOptions.LINK) == "Unlink Cel":
new_layers[layer].linked_cels.remove(cel_index)
var sprite := Image.new()
sprite.copy_from(Global.current_project.frames[frame].cels[layer].image)
sprite.copy_from(f.cels[layer].image)
sprite.lock()
var sprite_texture := ImageTexture.new()
sprite_texture.create_from_image(sprite, 0)
new_cels[layer].image = sprite
new_cels[layer].image_texture = sprite_texture
Global.current_project.undo_redo.create_action("Unlink Cel")
Global.current_project.undo_redo.add_do_property(Global.current_project, "layers", new_layers)
@ -130,7 +133,7 @@ func _on_PopupMenu_id_pressed(ID : int) -> void:
Global.current_project.undo_redo.commit_action()
elif popup_menu.get_item_metadata(MenuOptions.LINK) == "Link Cel":
new_layers[layer].linked_cels.append(Global.current_project.frames[frame])
new_layers[layer].linked_cels.append(f)
Global.current_project.undo_redo.create_action("Link Cel")
Global.current_project.undo_redo.add_do_property(Global.current_project, "layers", new_layers)
if new_layers[layer].linked_cels.size() > 1: