62 lines
1.7 KiB
C++
62 lines
1.7 KiB
C++
/*
|
|
* ParseGameObject.cpp
|
|
*
|
|
* Created on: Dec 1, 2016
|
|
* Author: tibi
|
|
*/
|
|
#include <model/Background.h>
|
|
#include <storage/parsers/ParseGameObject.h>
|
|
|
|
namespace farmlands {
|
|
namespace storage {
|
|
|
|
template <>
|
|
base::GameObject* parse<base::GameObject> (boost::property_tree::ptree& root)
|
|
{
|
|
// Ensure we are on the scene node (property tree seems to add root of its own)
|
|
if (root.front().first == "GameObject")
|
|
root = root.front().second;
|
|
|
|
base::GameObject* gameObj = new base::GameObject();
|
|
gameObj->name = root.get<std::string>("<xmlattr>.name");
|
|
|
|
for (auto child : root)
|
|
{
|
|
// Base objects
|
|
if (child.first == "Transform")
|
|
gameObj->addComponent(parse<base::Transform>(child.second));
|
|
|
|
else if (child.first == "Camera")
|
|
gameObj->addComponent(parse<base::Camera>(child.second));
|
|
|
|
// Model
|
|
else if (child.first == "Background")
|
|
{
|
|
std::string path = child.second.get<std::string>("<xmlattr>.src");
|
|
resources::ResourceId id = resources::ResourceManager::instance().getId(path);
|
|
gameObj->addComponent(parse<model::Background>(id));
|
|
}
|
|
|
|
// Graphics
|
|
else if (child.first == "BackgroundRenderer")
|
|
gameObj->addComponent(parse<graphics::BackgroundRenderer>(child.second));
|
|
|
|
else if (child.first == "SpriteRenderer")
|
|
gameObj->addComponent(parse<graphics::SpriteRenderer>(child.second));
|
|
|
|
// Controllers
|
|
else if (child.first == "PlayerController")
|
|
gameObj->addComponent(parse<controller::player::PlayerController>(child.second));
|
|
|
|
else if (child.first == "DebugController")
|
|
gameObj->addComponent(parse<controller::DebugController>(child.second));
|
|
|
|
// !!! Add additional types here !!!
|
|
}
|
|
|
|
return gameObj;
|
|
}
|
|
|
|
}
|
|
}
|