Fix regression breaking linked cels on "Merge Down" (fix #4685)

This commit is contained in:
David Capello 2024-10-03 12:42:26 -03:00
parent a975873f7a
commit e5faac07b5
2 changed files with 39 additions and 2 deletions

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2019-2024 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -35,6 +35,8 @@
#include "doc/sprite.h"
#include "render/render.h"
#include <algorithm>
namespace app {
namespace cmd {
@ -128,11 +130,24 @@ void FlattenLayers::onExecute()
RestoreVisibleLayers restore;
restore.showSelectedLayers(sprite, layers);
const LayerList visibleLayers = sprite->allVisibleLayers();
// Map draw area to image coords
const gfx::ClipF area_to_image(0, 0, area);
// Copy all frames to the background.
for (frame_t frame(0); frame<sprite->totalFrames(); ++frame) {
// If the flatLayer is the only cel in this frame, we can skip
// this frame to keep existing links in the flatLayer.
const bool anotherCelExists =
std::any_of(visibleLayers.begin(),
visibleLayers.end(),
[flatLayer, frame](const Layer* other) {
return (flatLayer != other && other->cel(frame));
});
if (!anotherCelExists)
continue;
// Clear the image and render this frame.
clear_image(image.get(), bgcolor);
render.renderSprite(image.get(), sprite, frame, area_to_image);

View File

@ -1,4 +1,4 @@
-- Copyright (C) 2019 Igara Studio S.A.
-- Copyright (C) 2019-2024 Igara Studio S.A.
--
-- This file is released under the terms of the MIT license.
-- Read LICENSE.txt for more information.
@ -46,3 +46,25 @@ do
local after = s.cels[1].image
assert(before:isEqual(after))
end
-- Check that linked cels are not broken (regression in issue #4685)
-- We create two layers, the bottom one with 4 linked frames, and the
-- top one with one cel at 2nd frame, when we merge them, the
-- resulting layer should have frame 1, 3, and 4 linked.
do
local s = Sprite(32, 32)
app.useTool{ color=Color(255, 0, 0), points={ {0,0}, {32,32} } }
app.layer.isContinuous = true
app.command.NewFrame{ content=cellinked }
app.command.NewFrame{ content=cellinked }
app.command.NewFrame{ content=cellinked }
s:newLayer()
app.frame = 2
app.useTool{ color=Color(0, 0, 255), points={ {32,0}, {0,32} } }
app.command.MergeDownLayer()
local cels = app.layer.cels
-- Check that frame 1, 3, and 4 have the same image (linked cels)
assert(cels[1].image ~= cels[2].image)
assert(cels[1].image == cels[3].image)
assert(cels[1].image == cels[4].image)
end