First real pass at VN Event Parsing

This commit is contained in:
2023-04-22 22:50:20 -07:00
parent 72a0bb9192
commit c269841236
27 changed files with 476 additions and 60 deletions

View File

@ -6,5 +6,6 @@
# Sources
target_sources(vnscenetool
PRIVATE
VNPositionParser.cpp
VNPositionEventParser.cpp
VNTextEventParser.cpp
)

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

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

View File

@ -1,6 +0,0 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once

View File

@ -0,0 +1,43 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "VNTextEventParser.hpp"
using namespace Dawn;
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
) {
auto itChildren = node->children.begin();
while(itChildren != node->children.end()) {
Xml *child = *itChildren;
// Parse strings
if(child->node == "string") {
VNText text;
text.language = child->attributes["lang"];
text.text = child->value;
out->texts.push_back(text);
} else {
*error = "Unknown child node '" + child->node + "'";
return -1;
}
itChildren++;
}
return 0;
}

View File

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