Cleaned prefab parser a lot
This commit is contained in:
61
src/dawntools/prefabtool/PrefabChildParser.cpp
Normal file
61
src/dawntools/prefabtool/PrefabChildParser.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "PrefabChildParser.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::vector<std::string> PrefabChildParser::getRequiredAttributes() {
|
||||
return std::vector<std::string>();
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> PrefabChildParser::getOptionalAttributes() {
|
||||
return {
|
||||
{ "ref", "" },
|
||||
{ "position", "" },
|
||||
{ "scale", "" }
|
||||
};
|
||||
}
|
||||
|
||||
int32_t PrefabChildParser::onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
struct PrefabChild *out,
|
||||
std::string *error
|
||||
) {
|
||||
out->ref = values["ref"];
|
||||
|
||||
if(values["position"].size() > 0) {
|
||||
out->position = vec3Parser(values["position"], error);
|
||||
if(error->size() > 0) return 1;
|
||||
}
|
||||
|
||||
if(values["scale"].size() > 0) {
|
||||
out->scale = vec3Parser(values["scale"], error);
|
||||
if(error->size() > 0) return 1;
|
||||
}
|
||||
|
||||
auto itChildren = node->children.begin();
|
||||
while(itChildren != node->children.end()) {
|
||||
// Parse child nodes, they may be components or not
|
||||
auto c = *itChildren;
|
||||
if(c->node == "child") {
|
||||
struct PrefabChild child;
|
||||
child.registry = out->registry;
|
||||
auto ret = (PrefabChildParser()).parse(c, &child, error);
|
||||
if(ret != 0) return ret;
|
||||
out->children.push_back(child);
|
||||
} else {
|
||||
struct PrefabComponent component;
|
||||
component.registry = out->registry;
|
||||
auto ret = (PrefabComponentParser()).parse(c, &component, error);
|
||||
if(ret != 0) return ret;
|
||||
out->components.push_back(component);
|
||||
}
|
||||
++itChildren;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user