Remove items in use; drop Remove Unused
Every content window's Remove (the Delete key) takes the selection out with
what refers to it: a layer's or null's tracks in every animation, a
spritesheet's plain layers (and regions), an event or sound from its triggers
(dropping triggers left with neither), a shader or region from its frames
(which keep the region's rectangle), and a library's layers, flattened into
plain ones. When anything is in use it asks first, listing what goes ("This
will remove:" ... "Are you sure?"). Remove Unused is gone; Remove takes its
place in each footer.
One reference walk (model.cpp) counts uses and finds unused items, so
shaders on null and root frames count, and an animation layer's unused
spritesheet doesn't. Flattening can be limited to some layers, merging only
their children's triggers, which now record the layer they fired through.
edit::content_remove does the removal; Document::spritesheet_path_resolver_get
is shared with saving.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c9d68781d0
commit
065dd522f3
22 files changed
+475
-224
No files matched your search
@@ -1,41 +0,0 @@
|
||||
<AnimatedActor>
|
||||
<Info CreatedBy="fixture" CreatedOn="01/01/2026 12:00:00 PM" Fps="30" Version="2"/>
|
||||
<Content>
|
||||
<Spritesheets>
|
||||
<Spritesheet Id="0" Path="sheet.png">
|
||||
<Region Id="0" Name="custom" XCrop="0" YCrop="0" Width="16" Height="16" XPivot="3" YPivot="5"/>
|
||||
<Region Id="1" Name="topleft" XCrop="16" YCrop="0" Width="16" Height="32" Origin="TopLeft"/>
|
||||
<Region Id="2" Name="center" XCrop="32" YCrop="0" Width="10" Height="20" Origin="Center"/>
|
||||
<Region Id="3" Name="gap" XCrop="0" YCrop="32" Width="8" Height="8" XPivot="0" YPivot="0"/>
|
||||
</Spritesheet>
|
||||
<Spritesheet Id="1" Path="other.png"/>
|
||||
</Spritesheets>
|
||||
<Layers>
|
||||
<Layer Id="0" Name="a" SpritesheetId="0"/>
|
||||
<Layer Id="1" Name="b" SpritesheetId="1"/>
|
||||
</Layers>
|
||||
<Nulls/>
|
||||
<Events/>
|
||||
</Content>
|
||||
<Animations DefaultAnimation="A">
|
||||
<Animation Name="A" FrameNum="20" Loop="true">
|
||||
<RootAnimation>
|
||||
<Frame XPosition="0" YPosition="0" Delay="4" Visible="true" XScale="100" YScale="100" SkewX="0" SkewY="0" RedTint="255" GreenTint="255" BlueTint="255" AlphaTint="255" RedOffset="0" GreenOffset="0" BlueOffset="0" Rotation="0" Interpolated="false"/>
|
||||
</RootAnimation>
|
||||
<LayerAnimations>
|
||||
<LayerAnimation LayerId="0" Visible="true">
|
||||
<Frame RegionId="0" XPosition="0" YPosition="0" Delay="4" Visible="true" XScale="100" YScale="100" SkewX="0" SkewY="0" RedTint="255" GreenTint="255" BlueTint="255" AlphaTint="255" RedOffset="0" GreenOffset="0" BlueOffset="0" Rotation="0" Interpolated="false"/>
|
||||
<Frame RegionId="1" XPosition="0" YPosition="0" Delay="4" Visible="true" XScale="100" YScale="100" SkewX="0" SkewY="0" RedTint="255" GreenTint="255" BlueTint="255" AlphaTint="255" RedOffset="0" GreenOffset="0" BlueOffset="0" Rotation="0" Interpolated="false"/>
|
||||
<Frame RegionId="2" XPosition="0" YPosition="0" Delay="4" Visible="true" XScale="100" YScale="100" SkewX="0" SkewY="0" RedTint="255" GreenTint="255" BlueTint="255" AlphaTint="255" RedOffset="0" GreenOffset="0" BlueOffset="0" Rotation="0" Interpolated="false"/>
|
||||
<Frame XPivot="1" YPivot="1" XCrop="2" YCrop="2" Width="4" Height="4" XPosition="0" YPosition="0" Delay="4" Visible="true" XScale="100" YScale="100" SkewX="0" SkewY="0" RedTint="255" GreenTint="255" BlueTint="255" AlphaTint="255" RedOffset="0" GreenOffset="0" BlueOffset="0" Rotation="0" Interpolated="false"/>
|
||||
<Frame RegionId="3" XPosition="0" YPosition="0" Delay="4" Visible="true" XScale="100" YScale="100" SkewX="0" SkewY="0" RedTint="255" GreenTint="255" BlueTint="255" AlphaTint="255" RedOffset="0" GreenOffset="0" BlueOffset="0" Rotation="0" Interpolated="false"/>
|
||||
</LayerAnimation>
|
||||
<LayerAnimation LayerId="1" Visible="true">
|
||||
<Frame XPivot="8" YPivot="8" XCrop="0" YCrop="0" Width="16" Height="16" XPosition="0" YPosition="0" Delay="4" Visible="true" XScale="100" YScale="100" SkewX="0" SkewY="0" RedTint="255" GreenTint="255" BlueTint="255" AlphaTint="255" RedOffset="0" GreenOffset="0" BlueOffset="0" Rotation="0" Interpolated="false"/>
|
||||
</LayerAnimation>
|
||||
</LayerAnimations>
|
||||
<NullAnimations/>
|
||||
<Triggers/>
|
||||
</Animation>
|
||||
</Animations>
|
||||
</AnimatedActor>
|
||||
+82
-2
@@ -203,8 +203,6 @@ TEST_CASE("edit layer operations")
|
||||
return edit::animations_paste(anm2, text, 0, -1, groupIds, nullptr);
|
||||
},
|
||||
1},
|
||||
{"regions_remove_unused", "05_regions.anm2",
|
||||
[&](model::Model& anm2) { return edit::regions_remove_unused(anm2, 0); }, 0},
|
||||
{"regions_paste", "05_regions.anm2",
|
||||
[&](model::Model& anm2)
|
||||
{
|
||||
@@ -485,3 +483,85 @@ TEST_CASE("SVG spritesheets pack and merge into SVGs")
|
||||
REQUIRE(edit::spritesheets_merge(model, {0, 1}, image_get, true, false, false, Origin::TOP_LEFT));
|
||||
CHECK(model::item_get(model.content.spritesheets, 0)->path == "white.svg");
|
||||
}
|
||||
|
||||
TEST_CASE("content_remove takes what refers to an item with it")
|
||||
{
|
||||
auto path_keep = [](const model::Model&, const std::filesystem::path& path) { return path; };
|
||||
auto remove = [&](model::Model& model, ElementType type, std::set<int> ids, int spritesheetId = -1,
|
||||
const model::LibraryGet& library_get = {})
|
||||
{ edit::content_remove(model, type, ids, spritesheetId, library_get, path_keep); };
|
||||
auto tracks_count = [](const model::Model& model, int layerId)
|
||||
{
|
||||
int count{};
|
||||
for (auto [index, animation] : model.animations_get())
|
||||
model::tracks_each(animation->layers, [&](const model::Track& track, auto*) { count += track.id == layerId; });
|
||||
return count;
|
||||
};
|
||||
|
||||
SUBCASE("a layer's tracks, and a spritesheet's plain layers")
|
||||
{
|
||||
auto model = fixture_load("02_items.anm2");
|
||||
CHECK(model.uses_count(ElementType::LAYER_ELEMENT, {0}) == tracks_count(model, 0));
|
||||
remove(model, ElementType::LAYER_ELEMENT, {0});
|
||||
CHECK_FALSE(model::item_get(model.content.layers, 0));
|
||||
CHECK(tracks_count(model, 0) == 0);
|
||||
CHECK(tracks_count(model, 1) > 0);
|
||||
|
||||
CHECK(model.uses_count(ElementType::SPRITESHEET, {1}) == 1);
|
||||
remove(model, ElementType::SPRITESHEET, {1});
|
||||
CHECK(model.content.layers.empty());
|
||||
CHECK(tracks_count(model, 1) == 0);
|
||||
CHECK(model.content.spritesheets.size() == 1);
|
||||
}
|
||||
|
||||
SUBCASE("an event or sound from its triggers, and triggers left with neither")
|
||||
{
|
||||
auto model = fixture_load("02_items.anm2");
|
||||
auto& triggers = model.animation_get(0)->triggers.frames;
|
||||
REQUIRE(triggers.size() == 3);
|
||||
CHECK(model.uses_count(ElementType::SOUND_ELEMENT, {1}) == 2);
|
||||
remove(model, ElementType::SOUND_ELEMENT, {1});
|
||||
REQUIRE(triggers.size() == 2);
|
||||
CHECK(triggers[1].soundIds == std::vector{0});
|
||||
remove(model, ElementType::EVENT_ELEMENT, {0});
|
||||
REQUIRE(triggers.size() == 2);
|
||||
CHECK(triggers[0].eventIds.empty());
|
||||
CHECK(triggers[0].soundIds == std::vector{0});
|
||||
}
|
||||
|
||||
SUBCASE("a shader, and a region, from their frames")
|
||||
{
|
||||
auto shaders = fixture_load("06_shaders.anm2");
|
||||
remove(shaders, ElementType::SHADER, {0});
|
||||
CHECK(shaders.frame_get({0, LAYER, 0, 0})->shaderId == -1);
|
||||
CHECK(shaders.frame_get({0, LAYER, 0, 1})->shaderId == 4);
|
||||
|
||||
auto regions = fixture_load("05_regions.anm2");
|
||||
auto before = *regions.frame_get({0, LAYER, 0, 0});
|
||||
REQUIRE(before.regionId == 0);
|
||||
CHECK(regions.uses_count(ElementType::REGION, {0}, 0) == 1);
|
||||
remove(regions, ElementType::REGION, {0}, 0);
|
||||
auto after = *regions.frame_get({0, LAYER, 0, 0});
|
||||
CHECK(after.regionId == -1);
|
||||
CHECK(after.crop == before.crop);
|
||||
CHECK(after.size == before.size);
|
||||
CHECK(after.pivot == before.pivot);
|
||||
CHECK_FALSE(model::item_get(regions.content.spritesheets.front().regions, 0));
|
||||
}
|
||||
|
||||
SUBCASE("a library's layers, flattened")
|
||||
{
|
||||
auto model = model_load(file_load(TEST_DIR / "render" / "nested.anm2"));
|
||||
auto spin = model_load(file_load(TEST_DIR / "render" / "spin.anm2"));
|
||||
CHECK(model.uses_count(ElementType::LIBRARY, {0}) == 1);
|
||||
remove(model, ElementType::LIBRARY, {0}, -1,
|
||||
[&](const model::Model&, int id) { return id == 0 ? &spin : nullptr; });
|
||||
CHECK(model.content.libraries.empty());
|
||||
CHECK_FALSE(model::item_get(model.content.layers, 0));
|
||||
CHECK(
|
||||
std::ranges::any_of(model.content.layers, [](const model::Layer& layer) { return layer.name == "spin/red"; }));
|
||||
// Layers playing this file's animations stay as they are.
|
||||
CHECK(model::item_get(model.content.layers, 1)->is_animation());
|
||||
CHECK(model::item_get(model.content.layers, 3)->is_animation());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user