Stage 7b: model/xml.cpp reads and writes tinyxml2 directly; Element tree removed

- Reading goes from tinyxml2 straight into the typed model, including legacy
  layouts (flat GroupId groups, *AnimationGroups with Index, FrameRestore
  backups, baked frames, SoundId, Overlay) and load-time id/region repair.
- Writing builds an XmlNode tree from the typed model for a set of flags:
  id renumbering, region sync, group-root and interpolation baking happen on
  typed data; groups are nested or extracted the way the old pipeline did.
- Unknown XML is kept verbatim (XmlNode) instead of being re-emitted through
  the Element writer.
- model_hash is an FNV hash of the editor-format node tree (what a save would
  write); the per-fixture hash goldens are gone.
- Deletes src/anm2 (Element, normalize, groups, hash, xml) and the unused
  util/xml attribute helpers and ElementType/ItemType table columns.
- All goldens, invariants and the local corpus are byte-identical.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-10-03 17:20:45 -04:00
1 parent 0b6f67d9bd
commit e50d76c784
33 files changed
+1386 -2935

No files matched your search

-102
View File
@@ -1,9 +1,5 @@
#include "xml.hpp"
#include "math.hpp"
#include "path.hpp"
using namespace anm2ed::util;
using namespace tinyxml2;
namespace anm2ed::util::xml
@@ -14,102 +10,4 @@ namespace anm2ed::util::xml
self.Print(&printer);
return std::string(printer.CStr());
}
bool query_string_attribute(const XMLElement* element, const char* attribute, std::string& out)
{
if (!element || !attribute) return false;
const char* value = nullptr;
if (element->QueryStringAttribute(attribute, &value) != XML_SUCCESS || !value) return false;
out = value;
return true;
}
bool query_path_attribute(const XMLElement* element, const char* attribute, std::filesystem::path& out)
{
std::string temp{};
if (!query_string_attribute(element, attribute, temp)) return false;
out = path::from_utf8(temp);
return true;
}
bool query_int_attribute(const XMLElement* element, const char* attribute, int& out)
{
return element && attribute && element->QueryIntAttribute(attribute, &out) == XML_SUCCESS;
}
bool query_float_attribute(const XMLElement* element, const char* attribute, float& out)
{
return element && attribute && element->QueryFloatAttribute(attribute, &out) == XML_SUCCESS;
}
bool query_bool_attribute(const XMLElement* element, const char* attribute, bool& out)
{
return element && attribute && element->QueryBoolAttribute(attribute, &out) == XML_SUCCESS;
}
bool query_color_attribute(const XMLElement* element, const char* attribute, float& out)
{
int value{};
if (!query_int_attribute(element, attribute, value)) return false;
out = math::uint8_to_float(value);
return true;
}
void set_string_attribute(XMLElement* element, const char* attribute, const std::string& value)
{
if (element && attribute && !value.empty()) element->SetAttribute(attribute, value.c_str());
}
void set_path_attribute(XMLElement* element, const char* attribute, const std::filesystem::path& value)
{
if (!element || !attribute || value.empty()) return;
auto utf8 = path::to_utf8(value);
element->SetAttribute(attribute, utf8.c_str());
}
void set_int_attribute(XMLElement* element, const char* attribute, int value)
{
if (element && attribute) element->SetAttribute(attribute, value);
}
void set_float_attribute(XMLElement* element, const char* attribute, float value)
{
if (element && attribute) element->SetAttribute(attribute, value);
}
void set_bool_attribute(XMLElement* element, const char* attribute, bool value)
{
if (element && attribute) element->SetAttribute(attribute, value);
}
void set_color_attribute(XMLElement* element, const char* attribute, float value)
{
if (element && attribute) element->SetAttribute(attribute, math::float_to_uint8(value));
}
XMLError query_string_attribute(XMLElement* element, const char* attribute, std::string* out)
{
if (!element || !attribute || !out) return XML_NO_ATTRIBUTE;
const char* value = nullptr;
auto result = element->QueryStringAttribute(attribute, &value);
if (result == XML_SUCCESS && value) *out = value;
return result;
}
XMLError query_path_attribute(XMLElement* element, const char* attribute, std::filesystem::path* out)
{
if (!out) return XML_NO_ATTRIBUTE;
std::string temp{};
auto result = query_string_attribute(element, attribute, &temp);
if (result == XML_SUCCESS) *out = path::from_utf8(temp);
return result;
}
void query_color_attribute(XMLElement* element, const char* attribute, float& out)
{
query_color_attribute(static_cast<const XMLElement*>(element), attribute, out);
}
}