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

+40 -4
View File
@@ -214,7 +214,7 @@ namespace anm2ed
{
auto absolutePath = !path.empty() ? path : this->path;
auto absolutePathUtf8 = path::to_utf8(absolutePath);
if (model::model_save(model, absolutePath, errorString, {.isExtendedFormat = model.isExtendedFormat}))
if (file_write(absolutePath, errorString))
{
this->path = absolutePath;
toast_log(Level::INFO, TOAST_SAVE_DOCUMENT, absolutePathUtf8);
@@ -225,6 +225,26 @@ namespace anm2ed
return false;
}
// Writes the document; a Rebirth document's game copy has its animation layers flattened into plain layers.
bool Document::file_write(const std::filesystem::path& path, std::string* errorString)
{
std::optional<model::Model> game{};
if (!model.isExtendedFormat && std::ranges::any_of(model.content.layers, &model::Layer::is_animation))
game = edit::animation_layers_flatten(
model, library_resolver_get(),
[&](const model::Model& source, const std::filesystem::path& spritesheetPath)
{
for (const auto& [libraryPath, library] : libraries)
if (&library.model == &source)
return path::backslash_replace(
path::make_relative(document::absolute_path_get(libraryPath.parent_path(), spritesheetPath),
std::filesystem::absolute(directory_get())));
return spritesheetPath;
});
return model::model_save(model, path, errorString,
{.isExtendedFormat = model.isExtendedFormat, .gameModel = game ? &*game : nullptr});
}
std::filesystem::path Document::autosave_path_get()
{
return directory_get() /
@@ -244,7 +264,7 @@ namespace anm2ed
{
auto autosavePath = autosave_path_get();
auto autosavePathUtf8 = path::to_utf8(autosavePath);
if (model::model_save(model, autosavePath, errorString, {.isExtendedFormat = model.isExtendedFormat}))
if (file_write(autosavePath, errorString))
{
for (auto id : spritesheets_autosave_dirty_get())
{
@@ -388,9 +408,11 @@ namespace anm2ed
: std::filesystem::path{};
}
// A library of this document (or of a copy of it) or of one of its libraries.
const LibraryData* Document::library_get(const model::Model& from, int id) const
{
auto link = libraryLinks.find({&from == &model ? nullptr : &from, id});
auto isLibrary = std::ranges::any_of(libraries, [&](const auto& pair) { return &pair.second.model == &from; });
auto link = libraryLinks.find({isLibrary ? &from : nullptr, id});
return link == libraryLinks.end() ? nullptr : link->second;
}
@@ -403,6 +425,15 @@ namespace anm2ed
};
}
// An animation layer whose animation isn't there; a library that didn't load leaves the question open (false).
bool Document::is_layer_animation_missing(const model::Layer& layer) const
{
if (!layer.is_animation()) return false;
auto library = layer.libraryId == -1 ? nullptr : library_get(model, layer.libraryId);
auto source = layer.libraryId == -1 ? &model : library && library->model.isValid ? &library->model : nullptr;
return source && !source->animation_named_get(layer.animation);
}
// The animation names of library `libraryId`, or of this document at -1.
std::vector<std::string> Document::animation_names_get(int libraryId) const
{
@@ -455,7 +486,11 @@ namespace anm2ed
{
auto path = document::absolute_path_get(directory, library.path);
auto [it, isNew] = libraries.try_emplace(path);
if (isNew) document::library_load(path, it->second);
if (isNew)
{
document::library_load(path, it->second);
++librariesRevision;
}
libraryLinks[{from == &model ? nullptr : from, library.id}] = &it->second;
if (reached.insert(path).second) pending.emplace_back(&it->second.model, path.parent_path());
}
@@ -473,6 +508,7 @@ namespace anm2ed
auto time = std::filesystem::last_write_time(path, ec);
if (ec || time == library.writeTime) continue;
document::library_load(path, library);
++librariesRevision;
isReloaded = true;
}
if (isReloaded) assets_sync();