The import tool now writes every .anm2 as Anm2Ed's JSON document under its own name (anm2ed convert --format json),
as isaac-classic does; other XML keeps the generic {tag, attrs, children, text} mapping.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
52 lines
1.7 KiB
C++
52 lines
1.7 KiB
C++
#include "data.h"
|
|
#include <cctype>
|
|
|
|
std::string dataDirectory = "resources/";
|
|
|
|
// Where a game path lives once imported: under the data directory, lowercased with forward slashes, as the game
|
|
// normalizes every path before a lookup.
|
|
std::string resource_path(std::string_view path)
|
|
{
|
|
std::string normalized(path);
|
|
for (char& letter : normalized) letter = letter == '\\' ? '/' : (char)std::tolower((unsigned char)letter);
|
|
return dataDirectory + normalized;
|
|
}
|
|
|
|
// Where a converted XML document lives: its resource path with ".json" appended.
|
|
std::string data_path(std::string_view path)
|
|
{
|
|
return resource_path(path) + ".json";
|
|
}
|
|
|
|
// Loads a converted document, leaving isLoaded false when it is missing or unreadable.
|
|
void data_load(Data& data, std::string_view path)
|
|
{
|
|
data.isLoaded = data.parser.load(data_path(path)).get(data.root) == simdjson::SUCCESS;
|
|
}
|
|
|
|
std::string_view node_tag(DataNode node)
|
|
{
|
|
std::string_view tag;
|
|
return node["tag"].get(tag) == simdjson::SUCCESS ? tag : std::string_view();
|
|
}
|
|
|
|
// An attribute's raw string, or an empty one when the element lacks it.
|
|
std::string_view node_attr(DataNode node, std::string_view name)
|
|
{
|
|
std::string_view value;
|
|
return node["attrs"][name].get(value) == simdjson::SUCCESS ? value : std::string_view();
|
|
}
|
|
|
|
std::string_view node_text(DataNode node)
|
|
{
|
|
std::string_view text;
|
|
return node["text"].get(text) == simdjson::SUCCESS ? text : std::string_view();
|
|
}
|
|
|
|
// The element's children in document order, empty when it has none.
|
|
simdjson::dom::array node_children(DataNode node)
|
|
{
|
|
simdjson::dom::array children;
|
|
return node["children"].get(children) == simdjson::SUCCESS ? children : simdjson::dom::array();
|
|
}
|