Add a convert command; JSON libraries come before layers

`anm2ed convert <file> [--format json|xml] [--out PATH]` saves a document as
the editor does: XML (the default) is the game's copy with the editor's
embedded, animation layers flattened through their libraries; JSON is the
editor's own. Without --out the file is rewritten in place. JSON problems go
to stderr; a file that can't load or write exits 1, a bad --format 2. A
document loads without an OpenGL context now: its custom shaders just aren't
compiled. The file and --out are made absolute, so a bare file name has a
folder (render and frame crashed on one too).

JSON writes and reads "libraries" before "layers", so a layer's library index
is checked against the libraries rather than reported missing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-10-28 22:33:15 -04:00
1 parent 201a7c7cfc
commit c9d68781d0
5 files changed
+53 -8

No files matched your search

+3 -2
View File
@@ -675,7 +675,7 @@ namespace anm2ed::model
false);
}
// Content comes before animations, which read it.
// Content comes before animations, which read it (and anything named comes before what names it).
template <class Io, class M> void model_io(Io& io, M& model)
{
auto& content = model.content;
@@ -734,6 +734,8 @@ namespace anm2ed::model
true);
},
false, false);
// Libraries come before the layers that name them.
io.values("libraries", content.libraries, [](auto& library) -> auto& { return library.path; });
io.list(
"layers", content.layers,
[&](auto& layerIo, auto& layer)
@@ -754,7 +756,6 @@ namespace anm2ed::model
true, false);
io.values("events", content.events, [](auto& event) -> auto& { return event.name; });
io.values("sounds", content.sounds, [](auto& sound) -> auto& { return sound.path; });
io.values("libraries", content.libraries, [](auto& library) -> auto& { return library.path; });
io.field("defaultAnimation", model.animations.defaultAnimation, {});
if constexpr (Io::IS_READING)
animations_read(io, model);