First real pass at VN Event Parsing
This commit is contained in:
@ -6,5 +6,6 @@
|
||||
# Sources
|
||||
target_sources(vnscenetool
|
||||
PRIVATE
|
||||
VNPositionParser.cpp
|
||||
VNPositionEventParser.cpp
|
||||
VNTextEventParser.cpp
|
||||
)
|
33
src/dawntools/vnscenetool/events/VNPositionEventParser.cpp
Normal file
33
src/dawntools/vnscenetool/events/VNPositionEventParser.cpp
Normal 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;
|
||||
}
|
28
src/dawntools/vnscenetool/events/VNPositionEventParser.hpp
Normal file
28
src/dawntools/vnscenetool/events/VNPositionEventParser.hpp
Normal 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;
|
||||
};
|
||||
}
|
@ -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;
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
43
src/dawntools/vnscenetool/events/VNTextEventParser.cpp
Normal file
43
src/dawntools/vnscenetool/events/VNTextEventParser.cpp
Normal 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;
|
||||
}
|
30
src/dawntools/vnscenetool/events/VNTextEventParser.hpp
Normal file
30
src/dawntools/vnscenetool/events/VNTextEventParser.hpp
Normal 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;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user