Dawn/archive/dawntools/vnscenetool/events/VNChoiceEventParser.cpp
2023-10-31 21:15:03 -05:00

110 lines
2.6 KiB
C++

// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "VNChoiceEventParser.hpp"
using namespace Dawn;
std::vector<std::string> VNChoiceParser::getRequiredAttributes() {
return { "value" };
}
std::map<std::string, std::string> VNChoiceParser::getOptionalAttributes() {
return { };
}
int32_t VNChoiceParser::onParse(
Xml *node,
std::map<std::string, std::string> values,
struct VNChoice *out,
std::string *error
) {
int32_t ret;
auto itChildren = node->childNodes.begin();
while(itChildren != node->childNodes.end()) {
if(itChildren->nodeType != XML_NODE_TYPE_ELEMENT) {
++itChildren;
continue;
}
Xml *child = itChildren->child;
// Parse strings
if(child->node == "string") {
VNText text;
ret = (VNTextParser()).parse(child, &text, error);
if(ret != 0) return ret;
out->texts.push_back(text);
} else {
*error = "Unknown child node for choice event '" + child->node + "'";
return -1;
}
itChildren++;
}
out->value = values["value"];
return 0;
}
// // // // // // // // // // // // // // // // // // // // // // // // // // //
std::vector<std::string> VNChoicesEventParser::getRequiredAttributes() {
return { "key" };
}
std::map<std::string, std::string> VNChoicesEventParser::getOptionalAttributes() {
return { };
}
int32_t VNChoicesEventParser::onParse(
Xml *node,
std::map<std::string, std::string> values,
struct VNChoiceEvent *out,
std::string *error
) {
int32_t ret;
auto itChildren = node->childNodes.begin();
while(itChildren != node->childNodes.end()) {
if(itChildren->nodeType != XML_NODE_TYPE_ELEMENT) {
++itChildren;
continue;
}
Xml *child = itChildren->child;
// Parse strings
if(child->node == "title") {
auto itChildren2 = child->childNodes.begin();
while(itChildren2 != child->childNodes.end()) {
if(itChildren2->nodeType != XML_NODE_TYPE_ELEMENT) {
++itChildren2;
continue;
}
VNText text;
ret = (VNTextParser()).parse(itChildren2->child, &text, error);
if(ret != 0) return ret;
out->titles.push_back(text);
++itChildren2;
}
} else if(child->node == "choice") {
VNChoice choice;
ret = (VNChoiceParser()).parse(child, &choice, error);
if(ret != 0) return ret;
out->choices.push_back(choice);
} else {
*error = "Unknown child node for choices event '" + child->node + "'";
return -1;
}
itChildren++;
}
out->key = values["key"];
return 0;
}