Rebirth saves flatten animation layers; missing animations show red; pivot paths follow libraries

A Rebirth document's game copy turns each animation layer into plain layers,
one per layer its child draws, baked a frame at a time (runs of identical
frames merged; skew dropped), adding library spritesheets at paths relative to
the document; the editor's copy is unchanged and the Isaac warning says so.
Layers whose animation isn't in its file are drawn red in the Layers window
(nothing is said while a library hasn't loaded). Onionskin pivot paths are
redrawn when a library loads or reloads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-10-08 18:16:35 -04:00
1 parent 76c2186c81
commit 8807096170
16 files changed
+278 -21

No files matched your search

+32
View File
@@ -157,3 +157,35 @@ TEST_CASE("child animations fire their triggers as they reach them")
CHECK(sources_get(1) == std::vector<const model::Model*>{&spin});
CHECK(sources_get(2).empty());
}
TEST_CASE("flattening animation layers bakes their children into plain layers that draw the same")
{
auto anm2 = model_load(file_load(TEST_DIR / "render" / "nested.anm2"));
auto spin = model_load(file_load(TEST_DIR / "render" / "spin.anm2"));
auto library_get = [&](const model::Model&, int id) { return id == 0 ? &spin : nullptr; };
auto flat =
edit::animation_layers_flatten(anm2, library_get, [](const model::Model&, const std::filesystem::path& path)
{ return std::filesystem::path("library") / path; });
CHECK(std::ranges::none_of(flat.content.layers, &model::Layer::is_animation));
CHECK(flat.content.spritesheets.back().path == std::filesystem::path("library") / "sheet.png");
// Every frame, the plain layers draw where the animation layers' children did.
auto points_get = [&](const model::Model& model, const model::LibraryGet& get, float time)
{
std::vector<glm::vec2> points{};
for (const auto& draw :
model::animation_draws_get(model, *model.animation_get(0), {.time = time, .library_get = get}))
if (draw.type == model::DrawType::LAYER)
points.push_back(glm::round(glm::vec2(draw.parent * model::draw_quad_model_get(draw) * glm::vec4(1, 1, 0, 1))));
std::ranges::sort(points, [](glm::vec2 a, glm::vec2 b) { return std::tie(a.x, a.y) < std::tie(b.x, b.y); });
return points;
};
for (float time = 0.0f; time < 8.0f; time += 1.0f)
CHECK(points_get(flat, {}, time) == points_get(anm2, library_get, time));
auto text = model::model_to_string(anm2, {.gameModel = &flat});
auto game = game_document_get(text);
CHECK(game.find(" Animation=\"") == std::string::npos);
CHECK(game.find("spin/red") != std::string::npos);
CHECK(std::ranges::count_if(model_load(text).content.layers, &model::Layer::is_animation) == 3);
}
+31
View File
@@ -5,6 +5,7 @@
#include <cstdlib>
#include <format>
#include <fstream>
#include "canvas.hpp"
#include "document.hpp"
@@ -227,3 +228,33 @@ TEST_CASE("converting SVG spritesheets writes PNGs beside them")
CHECK(document.texture_get(0)->is_vector());
std::filesystem::remove_all(directory);
}
TEST_CASE("a Rebirth save flattens animation layers for the game")
{
auto directory = std::filesystem::temp_directory_path() / "anm2ed_flatten";
std::filesystem::remove_all(directory);
std::filesystem::create_directories(directory / "library");
std::filesystem::copy_file(RENDER_TEST_DIR / "nested.anm2", directory / "nested.anm2");
for (auto name : {"spin.anm2", "sheet.png"})
std::filesystem::copy_file(RENDER_TEST_DIR / name, directory / "library" / name);
auto text = std::string{};
{
std::ifstream file(directory / "nested.anm2");
text.assign(std::istreambuf_iterator<char>(file), {});
}
text.replace(text.find("Path=\"spin.anm2\""), std::string("Path=\"spin.anm2\"").size(), "Path=\"library/spin.anm2\"");
std::ofstream(directory / "nested.anm2") << text;
Document document(directory / "nested.anm2", false);
REQUIRE(document.is_valid());
document.model.isExtendedFormat = false;
REQUIRE(document.save(directory / "rebirth.anm2"));
std::ifstream file(directory / "rebirth.anm2");
std::string saved(std::istreambuf_iterator<char>(file), {});
auto game = saved.substr(0, saved.find("<SourceDocument"));
CHECK(game.find("Name=\"spin/red\"") != std::string::npos);
CHECK(game.find("Path=\"library/sheet.png\"") != std::string::npos);
CHECK(game.find(" Animation=\"") == std::string::npos);
CHECK(saved.find(" Animation=\"Spin\"") != std::string::npos);
std::filesystem::remove_all(directory);
}