78 lines
1.9 KiB
C++
78 lines
1.9 KiB
C++
// Copyright (c) 2023 Dominic Masters
|
|
//
|
|
// This software is released under the MIT License.
|
|
// https://opensource.org/licenses/MIT
|
|
|
|
#include "SceneParser.hpp"
|
|
|
|
using namespace Dawn;
|
|
|
|
std::vector<std::string> SceneParser::getRequiredAttributes() {
|
|
return { "name" };
|
|
}
|
|
|
|
std::map<std::string, std::string> SceneParser::getOptionalAttributes() {
|
|
return {
|
|
{ "extend", "" }
|
|
};
|
|
}
|
|
|
|
int32_t SceneParser::onParse(
|
|
Xml *node,
|
|
std::map<std::string, std::string> values,
|
|
struct Scene *out,
|
|
std::string *error
|
|
) {
|
|
int32_t ret;
|
|
|
|
//Create the scene item
|
|
out->name = values["name"];
|
|
out->extend = values["extend"];
|
|
|
|
struct SceneItemDependency dep;
|
|
|
|
//Parse the children
|
|
auto itChildren = node->childNodes.begin();
|
|
while(itChildren != node->childNodes.end()) {
|
|
if(itChildren->nodeType != XML_NODE_TYPE_ELEMENT) {
|
|
++itChildren;
|
|
continue;
|
|
}
|
|
|
|
Xml *child = itChildren->child;
|
|
|
|
if(child->node == "asset") {
|
|
struct SceneAsset asset;
|
|
auto ret = (SceneAssetParser()).parse(child, &asset, error);
|
|
if(ret != 0) return ret;
|
|
out->assets.push_back(asset);
|
|
|
|
} else if(child->node == "item") {
|
|
struct SceneItem item;
|
|
item.registry = out->registry;
|
|
ret = (SceneItemParser()).parse(child, &item, error);
|
|
if(ret != 0) return 1;
|
|
out->items.push_back(item);
|
|
|
|
//Add the dependency
|
|
dep.type = SCENE_ITEM_DEPENDENCY_TYPE_ITEM;
|
|
dep.position = out->items.size() - 1;
|
|
out->dependencies.push_back(dep);
|
|
|
|
} else if(child->node == "code") {
|
|
struct SceneCode code;
|
|
ret = (SceneCodeParser()).parse(child, &code, error);
|
|
if(ret != 0) return ret;
|
|
out->code.push_back(code);
|
|
|
|
//Add the dependency
|
|
dep.type = SCENE_ITEM_DEPENDENCY_TYPE_CODE;
|
|
dep.position = out->code.size() - 1;
|
|
out->dependencies.push_back(dep);
|
|
}
|
|
|
|
++itChildren;
|
|
}
|
|
|
|
return 0;
|
|
} |