void SceneParser::parse(void) { parseConfig(); acceptToken(Scanner::Separator); advance(); parseObjects(); parseToken(Scanner::StreamDone); }
bool StateParser::parseState(const char *stateFile, std::string stateID, std::vector<GameObject *> *pObjects, std::vector<std::string> *pTextureIDs) { // instanciar xmldoc TiXmlDocument xmlDoc; // mira si esta cargada correctamente if (!xmlDoc.LoadFile(stateFile)) { return false; } // conseguir el root TiXmlElement* pRoot = xmlDoc.RootElement(); //declarar el nodo de <menu>... TiXmlElement* pStateRoot = 0; //busca el state segun el id que hemos pasado for (TiXmlElement* e = pRoot->FirstChildElement(); e != NULL; e = e->NextSiblingElement()) { if (e->Value() == stateID) { pStateRoot = e; } } // declarar el nodo de <texture> TiXmlElement* pTextureRoot = 0; for (TiXmlElement* e = pStateRoot->FirstChildElement(); e != NULL; e = e->NextSiblingElement()) { if (e->Value() == std::string("TEXTURES")) { pTextureRoot = e; } } //buscar la textura parseTextures(pTextureRoot, pTextureIDs); // declarar el nodo <objeto> TiXmlElement* pObjectRoot = 0; for (TiXmlElement* e = pStateRoot->FirstChildElement(); e != NULL; e = e->NextSiblingElement()) { if (e->Value() == std::string("OBJECTS")) { pObjectRoot = e; } } // buscar el objeto parseObjects(pObjectRoot, pObjects); return true; }
bool StateParser::parseState(const char* stateFile, string stateID, std::vector<GameObject*> * pObjects, std::vector<string> * pTextureIDs) { TiXmlDocument xmlDoc; // crea el documento xml if (!xmlDoc.LoadFile(stateFile)) { // carga el statefile return false; } TiXmlElement* pRoot = xmlDoc.RootElement(); TiXmlElement* pStateRoot = 0; for (TiXmlElement* e = pRoot->FirstChildElement(); e != nullptr; e = e->NextSiblingElement()) { if (e->Value() == stateID) { pStateRoot = e; break; } } TiXmlElement* pTextureRoot = 0; for (TiXmlElement* e = pStateRoot->FirstChildElement(); e != nullptr; e = e->NextSiblingElement()) { if (e->Value() == string("TEXTURES")) { pTextureRoot = e; break; } } parseTextures(pTextureRoot, pTextureIDs); TiXmlElement* pObjectRoot = 0; for (TiXmlElement* e = pStateRoot->FirstChildElement(); e != nullptr; e = e->NextSiblingElement()) { if (e->Value() == string("OBJECTS")) { pObjectRoot = e; break; } } parseObjects(pObjectRoot, pObjects); return true; }
bool StateParser::parseState(const char *stateFile, std::string stateID, std::vector<GameObject*> *pObjects, std::vector<std::string> *pTextureIDS) { cout<<"File ready"<<'\n'; TiXmlDocument xmlDoc; if (!xmlDoc.LoadFile(stateFile)) { cout << "not able to load file " << '\n' << stateFile; return false; } TiXmlElement *pRoot = xmlDoc.RootElement(); TiXmlElement *pStateRoot = 0; cout<<"File ready"; for (TiXmlElement *e = pRoot->FirstChildElement(); e != NULL; e=e->NextSiblingElement()) { if (e->Value() == stateID) { pStateRoot = e; } } TiXmlElement *pTextureRoot = 0; cout<<"pTextureRoot ready"<<'\n'; for (TiXmlElement *e = pStateRoot->FirstChildElement(); e != NULL; e=e->NextSiblingElement()) { if (e->Value() == string("TEXTURES")) { pTextureRoot = e; } } TiXmlElement *pObjectsRoot = 0; for (TiXmlElement *e = pStateRoot->FirstChildElement(); e != NULL; e=e->NextSiblingElement()) { if (e->Value() == string("OBJECTS")) { pObjectsRoot = e; } } parseTextures(pTextureRoot, pTextureIDS); cout<<"pTextureRoot loaded"<<pTextureRoot->Value()<<'\n'; cout<<"pObjectsRoot loaded"<<pObjectsRoot->Value()<<'\n'; parseObjects(pObjectsRoot, pObjects); return true; }
bool StateParser::parseState( const char *stateFile, std::string stateID, std::vector<GameObject*> *pObjects, std::vector<std::string> *pTextureIDs ) { std::cout << "< StateParser::parseState( " << stateFile << ", " << stateID << ", pObjects, pTextureIDs) >\n"; // create the XML document TiXmlDocument xmlDoc; // load the state file if( !xmlDoc.LoadFile( stateFile ) ) { std::cerr << xmlDoc.ErrorDesc() << "\n"; return false; } std::cout << " XML File Loaded\n"; // get the root element TiXmlElement* pRoot = xmlDoc.RootElement(); std::cout << " Got Document Root\n"; // pre declare the state's root node TiXmlElement* pStateRoot = 0; // get this state's root node and assign it to pStateRoot for( TiXmlElement* e = pRoot->FirstChildElement(); e != NULL; e = e->NextSiblingElement() ) { if( e->Value() == stateID ) { pStateRoot = e; } } std::cout << " Got State Root\n"; // pre-declare the texture root TiXmlElement* pTextureRoot = 0; // get the root of the texture elements for( TiXmlElement* e = pStateRoot->FirstChildElement(); e != NULL ; e = e->NextSiblingElement() ) { if( e->Value() == std::string("TEXTURES") ) { pTextureRoot = e; } } std::cout << " Got Texture Root\n"; // now parse the textures parseTextures( pTextureRoot, pTextureIDs ); std::cout << " Parsed textures\n"; // pre-declare the object root node TiXmlElement* pObjectRoot = 0; // get the root node and assign it to pObjectRoot for( TiXmlElement* e = pStateRoot->FirstChildElement(); e != NULL; e = e->NextSiblingElement() ) { if( e->Value() == std::string("OBJECTS") ) { pObjectRoot = e; } } std::cout << " Got Object Root\n"; // now parse the objects parseObjects( pObjectRoot, pObjects ); std::cout << " Parsed objects\n"; std::cout << "< END StateParser::parseState( " << stateFile << ", " << stateID << ", pObjects, pTextureIDs) >\n"; return true; }