Moved C++ tools out

This commit is contained in:
2023-10-31 21:15:03 -05:00
parent f8a715ec78
commit 343f75433e
98 changed files with 5 additions and 16 deletions

View File

@ -0,0 +1,22 @@
# Copyright (c) 2023 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(vnscenetool
PRIVATE
VNMarkerParser.cpp
VNSceneEventsParser.cpp
VNPositionEventParser.cpp
VNTextEventParser.cpp
VNSetEventParser.cpp
VNWaitEventParser.cpp
VNParallelEventParser.cpp
VNGoToMarkerEventParser.cpp
VNChoiceEventParser.cpp
VNChoiceSetEventParser.cpp
VNIfEventParser.cpp
VNSceneChangeEventParser.cpp
VNSetDefaultFontEventParser.cpp
)

View File

@ -0,0 +1,110 @@
// 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;
}

View File

@ -0,0 +1,44 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "VNTextEventParser.hpp"
namespace Dawn {
struct VNChoice {
std::vector<struct VNText> texts;
std::string value;
};
struct VNChoiceEvent {
std::vector<struct VNText> titles;
std::vector<struct VNChoice> choices;
std::string key;
};
class VNChoiceParser : public XmlParser<struct VNChoice> {
protected:
std::vector<std::string> getRequiredAttributes() override;
std::map<std::string, std::string> getOptionalAttributes() override;
int32_t onParse(
Xml *node,
std::map<std::string, std::string> values,
struct VNChoice *out,
std::string *error
) override;
};
class VNChoicesEventParser : public XmlParser<struct VNChoiceEvent> {
protected:
std::vector<std::string> getRequiredAttributes() override;
std::map<std::string, std::string> getOptionalAttributes() override;
int32_t onParse(
Xml *node,
std::map<std::string, std::string> values,
struct VNChoiceEvent *out,
std::string *error
) override;
};
}

View File

@ -0,0 +1,27 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "VNChoiceSetEventParser.hpp"
using namespace Dawn;
std::vector<std::string> VNChoiceSetEventParser::getRequiredAttributes() {
return { "key", "value" };
}
std::map<std::string, std::string> VNChoiceSetEventParser::getOptionalAttributes() {
return {};
}
int32_t VNChoiceSetEventParser::onParse(
Xml *node,
std::map<std::string, std::string> values,
struct VNChoiceSetEvent *out,
std::string *error
) {
out->key = values["key"];
out->value = values["value"];
return 0;
}

View File

@ -0,0 +1,26 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "util/XmlParser.hpp"
namespace Dawn {
struct VNChoiceSetEvent {
std::string key;
std::string value;
};
class VNChoiceSetEventParser : public XmlParser<VNChoiceSetEvent> {
protected:
std::vector<std::string> getRequiredAttributes() override;
std::map<std::string, std::string> getOptionalAttributes() override;
int32_t onParse(
Xml *node,
std::map<std::string, std::string> values,
struct VNChoiceSetEvent *out,
std::string *error
) override;
};
}

View File

@ -0,0 +1,26 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "VNGoToMarkerEventParser.hpp"
using namespace Dawn;
std::vector<std::string> VNGoToMarkerEventParser::getRequiredAttributes() {
return { "name" };
}
std::map<std::string, std::string> VNGoToMarkerEventParser::getOptionalAttributes() {
return {};
}
int32_t VNGoToMarkerEventParser::onParse(
Xml *node,
std::map<std::string, std::string> values,
struct VNGoToMarkerEvent *out,
std::string *error
) {
out->name = values["name"];
return 0;
}

View File

@ -0,0 +1,25 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "util/XmlParser.hpp"
namespace Dawn {
struct VNGoToMarkerEvent {
std::string name;
};
class VNGoToMarkerEventParser : public XmlParser<struct VNGoToMarkerEvent> {
protected:
std::vector<std::string> getRequiredAttributes() override;
std::map<std::string, std::string> getOptionalAttributes() override;
int32_t onParse(
Xml *node,
std::map<std::string, std::string> values,
struct VNGoToMarkerEvent *out,
std::string *error
) override;
};
}

View File

@ -0,0 +1,30 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "VNIfEventParser.hpp"
#include "VNSceneEventsParser.hpp"
using namespace Dawn;
std::vector<std::string> VNIfEventParser::getRequiredAttributes() {
return { "key", "value" };
}
std::map<std::string, std::string> VNIfEventParser::getOptionalAttributes() {
return {};
}
int32_t VNIfEventParser::onParse(
Xml *node,
std::map<std::string, std::string> values,
struct VNIfEvent *out,
std::string *error
) {
//Get the key and value
out->key = values["key"];
out->value = values["value"];
return (VNSceneEventsParser()).parse(node, &out->events, error);
}

View File

@ -0,0 +1,23 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "util/XmlParser.hpp"
namespace Dawn {
struct VNIfEvent;
class VNIfEventParser : public XmlParser<struct VNIfEvent> {
protected:
std::vector<std::string> getRequiredAttributes() override;
std::map<std::string, std::string> getOptionalAttributes() override;
int32_t onParse(
Xml *node,
std::map<std::string, std::string> values,
struct VNIfEvent *out,
std::string *error
) override;
};
}

View File

@ -0,0 +1,32 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "VNMarkerParser.hpp"
using namespace Dawn;
std::vector<std::string> VNMarkerParser::getRequiredAttributes() {
return { "name" };
}
std::map<std::string, std::string> VNMarkerParser::getOptionalAttributes() {
return {};
}
int32_t VNMarkerParser::onParse(
Xml *node,
std::map<std::string, std::string> values,
struct VNMarker *out,
std::string *error
) {
// Ensure name only contains letters, and numbers, no spaces or symbols
if(!std::regex_match(values["name"], std::regex("^[a-zA-Z0-9]+$"))) {
*error = "Marker name " + values["name"] + " must only contain letters and numbers.";
return -1;
}
out->name = values["name"];
return 0;
}

View File

@ -0,0 +1,26 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "util/XmlParser.hpp"
#include <regex>
namespace Dawn {
struct VNMarker {
std::string name;
};
class VNMarkerParser : public XmlParser<struct VNMarker> {
protected:
std::vector<std::string> getRequiredAttributes() override;
std::map<std::string, std::string> getOptionalAttributes() override;
int32_t onParse(
Xml *node,
std::map<std::string, std::string> values,
struct VNMarker *out,
std::string *error
) override;
};
}

View File

@ -0,0 +1,27 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "VNParallelEventParser.hpp"
#include "VNSceneEventsParser.hpp"
using namespace Dawn;
std::vector<std::string> VNParallelEventParser::getRequiredAttributes() {
return std::vector<std::string>();
}
std::map<std::string, std::string> VNParallelEventParser::getOptionalAttributes() {
return std::map<std::string, std::string>();
}
int32_t VNParallelEventParser::onParse(
Xml *node,
std::map<std::string, std::string> values,
struct VNParallelEvent *out,
std::string *error
) {
// Parse all children
return (VNSceneEventsParser()).parse(node, &out->events, error);
}

View File

@ -0,0 +1,23 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "util/XmlParser.hpp"
namespace Dawn {
struct VNParallelEvent;
class VNParallelEventParser : public XmlParser<struct VNParallelEvent> {
protected:
std::vector<std::string> getRequiredAttributes() override;
std::map<std::string, std::string> getOptionalAttributes() override;
int32_t onParse(
Xml *node,
std::map<std::string, std::string> values,
struct VNParallelEvent *out,
std::string *error
) override;
};
}

View File

@ -0,0 +1,33 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "VNPositionEventParser.hpp"
using namespace Dawn;
std::vector<std::string> VNPositionEventParser::getRequiredAttributes() {
return { "item" };
}
std::map<std::string, std::string> VNPositionEventParser::getOptionalAttributes() {
return {
{ "x", "" },
{ "y", "" },
{ "z", "" }
};
}
int32_t VNPositionEventParser::onParse(
Xml *node,
std::map<std::string, std::string> values,
struct VNPositionEvent *out,
std::string *error
) {
out->x = values["x"];
out->y = values["y"];
out->z = values["z"];
out->item = values["item"];
return 0;
}

View File

@ -0,0 +1,28 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "util/XmlParser.hpp"
namespace Dawn {
struct VNPositionEvent {
std::string x = "";
std::string y = "";
std::string z = "";
std::string item = "";
};
class VNPositionEventParser : public XmlParser<struct VNPositionEvent> {
protected:
std::vector<std::string> getRequiredAttributes() override;
std::map<std::string, std::string> getOptionalAttributes() override;
int32_t onParse(
Xml *node,
std::map<std::string, std::string> values,
struct VNPositionEvent *out,
std::string *error
) override;
};
}

View File

@ -0,0 +1,33 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "VNSceneChangeEventParser.hpp"
using namespace Dawn;
std::vector<std::string> VNSceneChangeEventParser::getRequiredAttributes() {
return { "scene" };
}
std::map<std::string, std::string> VNSceneChangeEventParser::getOptionalAttributes() {
return {};
}
int32_t VNSceneChangeEventParser::onParse(
Xml *node,
std::map<std::string, std::string> values,
struct VNSceneChangeEvent *out,
std::string *error
) {
out->include = values["scene"] + ".hpp";
// Find last slash and take all string after that
size_t lastSlash = values["scene"].find_last_of('/');
if(lastSlash != std::string::npos) {
out->scene = values["scene"].substr(lastSlash+1);
}
return 0;
}

View File

@ -0,0 +1,26 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "util/XmlParser.hpp"
namespace Dawn {
struct VNSceneChangeEvent {
std::string scene;
std::string include;
};
class VNSceneChangeEventParser : public XmlParser<struct VNSceneChangeEvent> {
protected:
std::vector<std::string> getRequiredAttributes() override;
std::map<std::string, std::string> getOptionalAttributes() override;
int32_t onParse(
Xml *node,
std::map<std::string, std::string> values,
struct VNSceneChangeEvent *out,
std::string *error
) override;
};
}

View File

@ -0,0 +1,109 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "VNSceneEventsParser.hpp"
#include "VNParallelEventParser.hpp"
using namespace Dawn;
std::vector<std::string> VNSceneEventsParser::getRequiredAttributes() {
return { };
}
std::map<std::string, std::string> VNSceneEventsParser::getOptionalAttributes() {
return { };
}
int32_t VNSceneEventsParser::onParse(
Xml *node,
std::map<std::string, std::string> values,
struct VNSceneEventList *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;
struct VNSceneEvent event;
// Parse event(s)
if(child->node == "text") {
event.type = VN_SCENE_EVENT_TYPE_TEXT;
ret = (VNTextEventParser()).parse(child, &event.text, error);
if(ret != 0) return ret;
} else if(child->node == "position") {
event.type = VN_SCENE_EVENT_TYPE_POSITION;
ret = (VNPositionEventParser()).parse(child, &event.position, error);
if(ret != 0) return ret;
} else if(child->node == "set") {
event.type = VN_SCENE_EVENT_TYPE_SET;
ret = (VNSetEventParser()).parse(child, &event.set, error);
if(ret != 0) return ret;
} else if(child->node == "wait") {
event.type = VN_SCENE_EVENT_TYPE_WAIT;
ret = (VNWaitEventParser()).parse(child, &event.wait, error);
if(ret != 0) return ret;
} else if(child->node == "parallel") {
event.type = VN_SCENE_EVENT_TYPE_PARALLEL;
ret = (VNParallelEventParser()).parse(child, &event.parallel, error);
if(ret != 0) return ret;
} else if(child->node == "marker") {
event.type = VN_SCENE_EVENT_TYPE_MARKER;
ret = (VNMarkerParser()).parse(child, &event.marker, error);
if(ret != 0) return ret;
} else if(child->node == "goto-marker") {
event.type = VN_SCENE_EVENT_TYPE_GOTO_MARKER;
ret = (VNGoToMarkerEventParser()).parse(child, &event.gotoMarker, error);
if(ret != 0) return ret;
} else if(child->node == "choices") {
event.type = VN_SCENE_EVENT_TYPE_CHOICES;
ret = (VNChoicesEventParser()).parse(child, &event.choices, error);
if(ret != 0) return ret;
} else if(child->node == "choice-set") {
event.type = VN_SCENE_EVENT_TYPE_CHOICE_SET;
ret = (VNChoiceSetEventParser()).parse(child, &event.choiceSet, error);
if(ret != 0) return ret;
} else if(child->node == "if") {
event.type = VN_SCENE_EVENT_TYPE_IF;
ret = (VNIfEventParser()).parse(child, &event.ifEvent, error);
if(ret != 0) return ret;
} else if(child->node == "scene-change") {
event.type = VN_SCENE_EVENT_TYPE_SCENE_CHANGE;
ret = (VNSceneChangeEventParser()).parse(child, &event.sceneChange, error);
if(ret != 0) return ret;
} else if(child->node == "set-default-font" || child->node == "set-font") {
event.type = VN_SCENE_EVENT_SET_DEFAULT_FONT;
ret = (VNSetDefaultFontEventParser()).parse(child, &event.setDefaultFont, error);
if(ret != 0) return ret;
} else {
*error = "Unknown child node '" + child->node + "'";
return -1;
}
if(ret != 0) return ret;
out->events.push_back(event);
itChildren++;
}
return 0;
}

View File

@ -0,0 +1,80 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "VNTextEventParser.hpp"
#include "VNPositionEventParser.hpp"
#include "VNSetEventParser.hpp"
#include "VNWaitEventParser.hpp"
#include "VNParallelEventParser.hpp"
#include "VNMarkerParser.hpp"
#include "VNGoToMarkerEventParser.hpp"
#include "VNChoiceEventParser.hpp"
#include "VNChoiceSetEventParser.hpp"
#include "VNIfEventParser.hpp"
#include "VNSceneChangeEventParser.hpp"
#include "VNSetDefaultFontEventParser.hpp"
namespace Dawn {
struct VNSceneEvent;
struct VNSceneEventList {
std::vector<struct VNSceneEvent> events;
};
enum VNSceneEventType {
VN_SCENE_EVENT_TYPE_TEXT,
VN_SCENE_EVENT_TYPE_POSITION,
VN_SCENE_EVENT_TYPE_SET,
VN_SCENE_EVENT_TYPE_WAIT,
VN_SCENE_EVENT_TYPE_PARALLEL,
VN_SCENE_EVENT_TYPE_MARKER,
VN_SCENE_EVENT_TYPE_GOTO_MARKER,
VN_SCENE_EVENT_TYPE_CHOICES,
VN_SCENE_EVENT_TYPE_CHOICE_SET,
VN_SCENE_EVENT_TYPE_IF,
VN_SCENE_EVENT_TYPE_SCENE_CHANGE,
VN_SCENE_EVENT_SET_DEFAULT_FONT
};
struct VNParallelEvent {
struct VNSceneEventList events;
};
struct VNIfEvent {
std::string key;
std::string value;
struct VNSceneEventList events;
};
struct VNSceneEvent {
enum VNSceneEventType type;
struct VNTextEvent text;
struct VNPositionEvent position;
struct VNSetEvent set;
struct VNWaitEvent wait;
struct VNParallelEvent parallel;
struct VNMarker marker;
struct VNGoToMarkerEvent gotoMarker;
struct VNChoiceEvent choices;
struct VNChoiceSetEvent choiceSet;
struct VNIfEvent ifEvent;
struct VNSceneChangeEvent sceneChange;
struct VNSetFont setDefaultFont;
};
class VNSceneEventsParser : public XmlParser<struct VNSceneEventList> {
protected:
std::vector<std::string> getRequiredAttributes() override;
std::map<std::string, std::string> getOptionalAttributes() override;
int32_t onParse(
Xml *node,
std::map<std::string, std::string> values,
struct VNSceneEventList *out,
std::string *error
) override;
};
}

View File

@ -0,0 +1,46 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "VNSetDefaultFontEventParser.hpp"
using namespace Dawn;
std::map<std::string, std::string> VNSetDefaultFontEventParser::getOptionalAttributes() {
return {
{ "font", "font_main" },
{ "style", "" },
{ "size", "" },
{ "color", "" }
};
}
std::vector<std::string> VNSetDefaultFontEventParser::getRequiredAttributes() {
return {};
}
int32_t VNSetDefaultFontEventParser::onParse(
Xml *node,
std::map<std::string, std::string> values,
struct VNSetFont *out,
std::string *error
) {
//Get the font
out->font = values["font"];
if(out->font.empty()) {
*error = "Font is required.";
return 1;
}
//Get the style
out->style = values["style"];
//Get the size
out->fontSize = values["size"];
//Get the color
out->color = values["color"];
return 0;
}

View File

@ -0,0 +1,28 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "util/XmlParser.hpp"
namespace Dawn {
struct VNSetFont {
std::string font;
std::string style;
std::string fontSize;
std::string color;
};
class VNSetDefaultFontEventParser : public XmlParser<struct VNSetFont> {
protected:
std::vector<std::string> getRequiredAttributes() override;
std::map<std::string, std::string> getOptionalAttributes() override;
int32_t onParse(
Xml *node,
std::map<std::string, std::string> values,
struct VNSetFont *out,
std::string *error
) override;
};
}

View File

@ -0,0 +1,39 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "VNSetEventParser.hpp"
using namespace Dawn;
std::vector<std::string> VNSetEventParser::getRequiredAttributes() {
return { "property", "type" };
}
std::map<std::string, std::string> VNSetEventParser::getOptionalAttributes() {
return {
{ "to", "" },
{ "value", "" }
};
}
int32_t VNSetEventParser::onParse(
Xml *node,
std::map<std::string, std::string> values,
struct VNSetEvent *out,
std::string *error
) {
if(values["to"] != "") {
out->to = values["to"];
} else if(values["value"] != "") {
out->to = values["value"];
} else {
*error = "Either 'to' or 'value' must be specified";
return -1;
}
out->type = values["type"];
out->property = values["property"];
return 0;
}

View File

@ -0,0 +1,27 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "util/XmlParser.hpp"
namespace Dawn {
struct VNSetEvent {
std::string property = "";
std::string to = "";
std::string type = "";
};
class VNSetEventParser : public XmlParser<struct VNSetEvent> {
protected:
std::vector<std::string> getRequiredAttributes() override;
std::map<std::string, std::string> getOptionalAttributes() override;
int32_t onParse(
Xml *node,
std::map<std::string, std::string> values,
struct VNSetEvent *out,
std::string *error
) override;
};
}

View File

@ -0,0 +1,82 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "VNTextEventParser.hpp"
#include "util/parser/TypeParsers.hpp"
using namespace Dawn;
std::vector<std::string> VNTextParser::getRequiredAttributes() {
return { "lang" };
}
std::map<std::string, std::string> VNTextParser::getOptionalAttributes() {
return { };
}
int32_t VNTextParser::onParse(
Xml *node,
std::map<std::string, std::string> values,
struct VNText *out,
std::string *error
) {
std::string innerXml = node->innerXml;
// Split by newlines, then trim each line.
std::vector<std::string> lines = stringSplit(innerXml, "\n");
std::vector<std::string> finalLines;
for(auto it = lines.begin(); it != lines.end(); ++it) {
auto newLine = stringTrim(*it);
if(newLine.length() > 0) finalLines.push_back(newLine);
}
std::string finalXml = stringJoin(finalLines, "\n");
out->language = values["lang"];
out->text = stringParser(finalXml, error);
return error->length() == 0 ? 0 : -1;
}
// // // // // // // // // // // // // // // // // // // // // // // // // // //
std::vector<std::string> VNTextEventParser::getRequiredAttributes() {
return { };
}
std::map<std::string, std::string> VNTextEventParser::getOptionalAttributes() {
return { };
}
int32_t VNTextEventParser::onParse(
Xml *node,
std::map<std::string, std::string> values,
struct VNTextEvent *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 text event '" + child->node + "'";
return -1;
}
itChildren++;
}
return 0;
}

View File

@ -0,0 +1,42 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "util/XmlParser.hpp"
namespace Dawn {
struct VNText {
std::string language;
std::string text;
};
struct VNTextEvent {
std::vector<VNText> texts;
};
class VNTextParser : public XmlParser<struct VNText> {
protected:
std::vector<std::string> getRequiredAttributes() override;
std::map<std::string, std::string> getOptionalAttributes() override;
int32_t onParse(
Xml *node,
std::map<std::string, std::string> values,
struct VNText *out,
std::string *error
) override;
};
class VNTextEventParser : public XmlParser<struct VNTextEvent> {
protected:
std::vector<std::string> getRequiredAttributes() override;
std::map<std::string, std::string> getOptionalAttributes() override;
int32_t onParse(
Xml *node,
std::map<std::string, std::string> values,
struct VNTextEvent *out,
std::string *error
) override;
};
}

View File

@ -0,0 +1,35 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "VNWaitEventParser.hpp"
using namespace Dawn;
std::vector<std::string> VNWaitEventParser::getRequiredAttributes() {
return { };
}
std::map<std::string, std::string> VNWaitEventParser::getOptionalAttributes() {
return { { "duration", "" }, { "time", "" } };
}
int32_t VNWaitEventParser::onParse(
Xml *node,
std::map<std::string, std::string> values,
VNWaitEvent *out,
std::string *error
) {
//Get the duration
if(!values["duration"].empty()) {
out->duration = values["duration"];
} else if(!values["time"].empty()) {
out->duration = values["time"];
} else {
*error = "No duration specified.";
return -1;
}
return 0;
}

View File

@ -0,0 +1,25 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "util/XmlParser.hpp"
namespace Dawn {
struct VNWaitEvent {
std::string duration;
};
class VNWaitEventParser : public XmlParser<VNWaitEvent> {
protected:
std::vector<std::string> getRequiredAttributes() override;
std::map<std::string, std::string> getOptionalAttributes() override;
int32_t onParse(
Xml *node,
std::map<std::string, std::string> values,
VNWaitEvent *out,
std::string *error
) override;
};
}