#include "yamltexbindings.h" namespace genesis { /* TODO: Migrate to Godot * static const std::string gsKeyNamesPlural("names"), gsKeyName("name"), gsKeyTexture("texture"); YAMLTexBindingsReader::YAMLTexBindingsReader(std::istream & input) : _pParser(new YAML::Parser(input)) {} YAMLTexBindingsReader::~YAMLTexBindingsReader() { delete _pParser; } bool YAMLTexBindingsReader::load( ITextureBinder * pMatBind ) { while (*_pParser) { YAML::Node ndDoc; ITextureBinder::Category enmbcCategory; _pParser->GetNextDocument(ndDoc); if (ndDoc.GetTag() == "!minclass") enmbcCategory = ITextureBinder::MineralClasses; else if (ndDoc.GetTag() == "!mineral") enmbcCategory = ITextureBinder::Minerals; else throw YAML::RepresentationException(ndDoc.GetMark(), "Invalid tag type: " + ndDoc.GetTag()); if (ndDoc.GetType() != YAML::CT_MAP) throw YAML::RepresentationException(ndDoc.GetMark(), "Expected map"); for (YAML::Iterator i = ndDoc.begin(); i != ndDoc.end(); ++i) if (i.first() == "group") pMatBind->setGroup(enmbcCategory, i.second()); else if (i.first() == "default") pMatBind->setDefaultTexture(enmbcCategory, i.second()); else if (i.first() == "bindings") for (YAML::Iterator j = i.second().begin(); j != i.second().end(); ++j) readBinding(enmbcCategory, pMatBind, &*j); else throw YAML::RepresentationException(ndDoc.GetMark(), "Unrecognized key"); } return true; } void YAMLTexBindingsReader::readBinding( const ITextureBinder::Category enmbcCategory, ITextureBinder * pMatBind, const YAML::Node * pNode) { size_t c = 0; for (YAML::Iterator i = pNode->begin(); i != pNode->end(); ++i, ++c) { if (c > 2) throw YAML::RepresentationException(pNode->GetMark(), "Too many declarations"); if (i.first() == gsKeyNamesPlural) { std::string sMaterial = (*pNode)[gsKeyTexture]; for (YAML::Iterator j = i.second().begin(); j != i.second().end(); ++j) pMatBind->bind(enmbcCategory, *j, sMaterial); break; } else if (i.first() == gsKeyName) pMatBind->bind(enmbcCategory, i.second(), (*pNode)[gsKeyTexture]); else if (i.first() == gsKeyTexture) pMatBind->bind(enmbcCategory, (*pNode)[gsKeyName], i.second()); else throw YAML::RepresentationException(pNode->GetMark(), "Unrecognized binding declaration"); } } */ }