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

+11
View File
@@ -101,3 +101,14 @@ TEST_CASE("JSON that can't be read is reported by where it is, and the rest stil
CHECK_FALSE(model::model_load_string(model, "{ \"fps\": 30 }", &issues));
CHECK_FALSE(model::model_load_string(model, "{ \"anm2ed\": 1, ", &issues));
}
TEST_CASE("JSON layers can name a library listed after them in the file")
{
auto text = R"({ "anm2ed": 1, "layers": [ { "name": "shadow", "library": 0, "animation": "Small" } ],
"libraries": [ "shared/shadows.anm2" ] })";
model::Model model{};
std::string issues{};
REQUIRE(model::model_load_string(model, text, &issues));
CHECK(issues.empty());
CHECK(model.content.layers[0].libraryId == 0);
}