diff --git a/src/Classes/Cel.gd b/src/Classes/Cel.gd index d08d28d66..46786dc39 100644 --- a/src/Classes/Cel.gd +++ b/src/Classes/Cel.gd @@ -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) diff --git a/src/UI/Timeline/CelButton.gd b/src/UI/Timeline/CelButton.gd index 81e3a5402..0ad551bf8 100644 --- a/src/UI/Timeline/CelButton.gd +++ b/src/UI/Timeline/CelButton.gd @@ -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: