JSON documents; remove the extended format
Documents can be saved as the editor's own JSON (Save as JSON, in Configure's
Serialization row, off by default) and any .anm2 starting with '{' opens as
one. The schema is new, not an XML mirror: content items in arrays (an item's
index is its id), animations keyed by unique name (a repeat saves as "Name 2"),
groups nested, paired values as arrays, a frame on a region storing only the
region, ISO 8601 dates, every default left out, and one line per frame and
content item, with anything else that fits in 100 columns on one line. Unknown
XML isn't kept. Each part is described once (frame_io, track_io, model_io...)
and run by a JsonWriter or a JsonReader; simdjson parses (new submodule). A
JSON file that opens but has unknown keys, wrong types, unknown values or bad
indices lists them by location in a warning toast; libraries toast their load
problems too. With Save as JSON on, saving always shows the Isaac warning.
The extended format is gone: no setting, File menu toggle, ExtendedVersion or
isExtendedFormat. XML saves are always the game's copy with SourceDocument;
old extended files still open. Document saves take Options instead of loose
bools, and model_load reads through model_load_string. docs/json_format.md
replaces docs/extended_format.md; goldens lose ExtendedVersion and the
.extended variants.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d77b2bae71
commit
b69b0eaa1b
121 files changed
+1248
-913
No files matched your search
+13
-13
@@ -49,7 +49,10 @@ namespace anm2ed::document
|
||||
void library_load(const std::filesystem::path& path, LibraryData& library)
|
||||
{
|
||||
library = {};
|
||||
model::model_load(library.model, path);
|
||||
std::string errorString{};
|
||||
model::model_load(library.model, path, &errorString);
|
||||
// Why it couldn't load, or what a JSON library couldn't read.
|
||||
if (!errorString.empty()) toast_log(Level::WARNING, TOAST_LIBRARY_ISSUES, path::to_utf8(path), errorString);
|
||||
std::error_code ec{};
|
||||
library.writeTime = std::filesystem::last_write_time(path, ec);
|
||||
util::WorkingDirectory workingDirectory(path.parent_path());
|
||||
@@ -181,11 +184,10 @@ namespace anm2ed::document
|
||||
|
||||
namespace anm2ed
|
||||
{
|
||||
Document::Document(const std::filesystem::path& path, bool isNew, std::string* errorString, bool isExtendedFormat)
|
||||
Document::Document(const std::filesystem::path& path, bool isNew, std::string* errorString)
|
||||
{
|
||||
tabId = document::document_tab_id_next();
|
||||
model = model::model_make();
|
||||
model.isExtendedFormat = isExtendedFormat;
|
||||
if (!isNew) model::model_load(model, path, errorString);
|
||||
if (isNew ? !save(path, errorString) : !model.isValid)
|
||||
{
|
||||
@@ -210,11 +212,11 @@ namespace anm2ed
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Document::save(const std::filesystem::path& path, std::string* errorString, bool isPurgeDefaultColors)
|
||||
bool Document::save(const std::filesystem::path& path, std::string* errorString, Options options)
|
||||
{
|
||||
auto absolutePath = !path.empty() ? path : this->path;
|
||||
auto absolutePathUtf8 = path::to_utf8(absolutePath);
|
||||
if (file_write(absolutePath, errorString, isPurgeDefaultColors))
|
||||
if (file_write(absolutePath, errorString, options))
|
||||
{
|
||||
this->path = absolutePath;
|
||||
toast_log(Level::INFO, TOAST_SAVE_DOCUMENT, absolutePathUtf8);
|
||||
@@ -226,10 +228,10 @@ namespace anm2ed
|
||||
}
|
||||
|
||||
// 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, bool isPurgeDefaultColors)
|
||||
bool Document::file_write(const std::filesystem::path& path, std::string* errorString, Options options)
|
||||
{
|
||||
std::optional<model::Model> game{};
|
||||
if (!model.isExtendedFormat && std::ranges::any_of(model.content.layers, &model::Layer::is_animation))
|
||||
if (!options.isJson && 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)
|
||||
@@ -241,10 +243,8 @@ namespace anm2ed
|
||||
std::filesystem::absolute(directory_get())));
|
||||
return spritesheetPath;
|
||||
});
|
||||
return model::model_save(model, path, errorString,
|
||||
{.isExtendedFormat = model.isExtendedFormat,
|
||||
.isPurgeDefaultColors = isPurgeDefaultColors,
|
||||
.gameModel = game ? &*game : nullptr});
|
||||
options.gameModel = game ? &*game : nullptr;
|
||||
return model::model_save(model, path, errorString, options);
|
||||
}
|
||||
|
||||
std::filesystem::path Document::autosave_path_get()
|
||||
@@ -262,11 +262,11 @@ namespace anm2ed
|
||||
return path.parent_path() / std::filesystem::path(std::u8string(fileName.begin(), fileName.end()));
|
||||
}
|
||||
|
||||
bool Document::autosave(std::string* errorString, bool isPurgeDefaultColors)
|
||||
bool Document::autosave(std::string* errorString, Options options)
|
||||
{
|
||||
auto autosavePath = autosave_path_get();
|
||||
auto autosavePathUtf8 = path::to_utf8(autosavePath);
|
||||
if (file_write(autosavePath, errorString, isPurgeDefaultColors))
|
||||
if (file_write(autosavePath, errorString, options))
|
||||
{
|
||||
for (auto id : spritesheets_autosave_dirty_get())
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user