/* * ParseGameObject.cpp * * Created on: Dec 1, 2016 * Author: tibi */ #include #include namespace farmlands { namespace storage { template <> base::GameObject* parse (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(".name"); for (auto child : root) { // Base objects if (child.first == "Transform") gameObj->addComponent(parse(child.second)); else if (child.first == "Camera") gameObj->addComponent(parse(child.second)); // Model else if (child.first == "Background") { std::string path = child.second.get(".src"); resources::ResourceId id = resources::ResourceManager::instance().getId(path); gameObj->addComponent(parse(id)); } // Graphics else if (child.first == "BackgroundRenderer") gameObj->addComponent(parse(child.second)); else if (child.first == "SpriteRenderer") gameObj->addComponent(parse(child.second)); // Controllers else if (child.first == "PlayerController") gameObj->addComponent(parse(child.second)); else if (child.first == "DebugController") gameObj->addComponent(parse(child.second)); // !!! Add additional types here !!! } return gameObj; } } }